Skip to content

Add dimension as parameter in BedrockEmbeddings #796

@johnkitaoka

Description

@johnkitaoka

Package

langchain-aws

Checked other resources

  • I added a descriptive title to this issue
  • I searched the LangChain documentation with the integrated search
  • I used the GitHub search to find a similar issue and didn't find it
  • I am sure this is a feature request and not a bug report or question

Feature Description

Add a dimensions parameter to BedrockEmbeddings to control output embedding vector size, following the pattern established by OpenAIEmbeddings:
dimensions: int | None = None
This would allow users to specify different embedding dimensions supported by each model.

Use Case

Bedrock embeddings models (Titan, Cohere, Nova, etc.) support multiple dimensions values for embeddings granularity. This would allow for more functionality and flexibility with BedrockEmbeddings objects.

Proposed Implementation (optional)

Add a unified `dimensions` parameter that maps to each provider's schema with a default value corresponding to each model. Also validate that `dimensions` is supported for the given model and raise a clear error if not. 

For Titan:
  {"inputText": text, "dimensions": self.dimensions}

For Cohere  :
  {"texts": [text], "input_type": input_type, "output_dimension": self.dimensions}

For Nova:
  {
      "taskType": "SINGLE_EMBEDDING",
      "singleEmbeddingParams": {
          "embeddingDimension": self.dimensions,
          "embeddingPurpose": "GENERIC_INDEX",
          "text": {"truncationMode": "END", "value": text}
      }
  }

Additional Context

https://docs.aws.amazon.com/nova/latest/userguide/embeddings-schema.html
https://docs.aws.amazon.com/bedrock/latest/userguide/model-parameters-embed-v4.html
https://docs.aws.amazon.com/bedrock/latest/userguide/model-parameters-titan-embed-text.html

#773, #744 , #791

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions