-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Feat(amazon bedrock): Add support for cohere embed models #6190
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Feat(amazon bedrock): Add support for cohere embed models #6190
Conversation
- Added support for Cohere embedding models with customizable settings including input type, truncation, and embedding types. - Implemented separate embedding methods for Cohere and Titan models within the BedrockEmbeddingModel class. - Updated response handling to accommodate both simple and complex embedding formats for Cohere. - Revised the BedrockEmbeddingSettings interface to include Cohere-specific settings.
- Introduced unit tests for the `doEmbed` method, covering both Cohere and Titan models. - Enhanced test cases to validate handling of single and multiple input values, image inputs, and various embedding types. - Updated server response mocks to reflect new embedding scenarios.
…lution - Added compiler options for module resolution and module type to support Node16 in the TypeScript configuration file, specific to bedrock sdk requirements.
- Added new export types for BedrockEmbeddingModelId, BedrockEmbeddingSettings, and CohereEmbeddingSettings in the index file
Please add a changeset. |
/** | ||
* Settings specific to Cohere embedding models. | ||
*/ | ||
cohere?: CohereEmbeddingSettings; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not a fan of this solution and the overall way of how the functionality is integrated. Need to think more about how to do this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you expand a bit more on what you would like to see? I can add more type safety for sure. But are you thinking more just rethinking the overall integration as a whole? I could split cohere and titan into their own class and then just set the general bedrockembeddingmodel to be a thin wrapper for the subclasses.
/** | ||
* Specifies the types of embeddings you want to have returned. | ||
*/ | ||
embedding_types?: Array<'float' | 'int8' | 'uint8' | 'binary' | 'ubinary'>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We only support float atm.
Ideally this would be on the |
Background
The current Amazon Bedrock provider implementation doesn't properly support Cohere embedding models, which use a different request format compared to Titan models. This causes issues when attempting to use Cohere models for embeddings through the Amazon Bedrock provider.
Summary
bedrock-embedding-model.ts
to handle Cohere-specific request and response formatsBedrockEmbeddingSettings
type in the package's index file to fix TypeScript errors when using the updated package in third-party applicationsVerification
I tested all changes using the automated test suite and verified functionality with each Bedrock embedding model (including Cohere models) in a Next.js 15 app router application using the updated dist outputs. All tests passed successfully, confirming that both Titan and Cohere embedding models now work as expected.
Tasks
pnpm prettier-fix
in the project root)Related Issues
Fixes #5055