Skip to content

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

Draft
wants to merge 174 commits into
base: main
Choose a base branch
from

Conversation

QuinnGT
Copy link

@QuinnGT QuinnGT commented May 7, 2025

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

  • Modified bedrock-embedding-model.ts to handle Cohere-specific request and response formats
  • Added support for Cohere embedding model's additional capabilities including clustering and image embeddings
  • Ensured proper typing for Cohere embedding model settings
  • Exported BedrockEmbeddingSettings type in the package's index file to fix TypeScript errors when using the updated package in third-party applications

Verification

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

  • Tests have been added / updated for bug fixes / features
  • Documentation has been added / updated for bug fixes / features
  • Formatting issues have been fixed (run pnpm prettier-fix in the project root)

Related Issues

Fixes #5055

dylanmoz and others added 30 commits April 3, 2025 08:10
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
samdenty and others added 20 commits April 30, 2025 15:53
## Background

This resolves an issue a user ran into:
vercel#6041

## Summary

Aligned openai provider with openai-compatible
## Background

This pull request adds the ability for clients to resume an ongoing chat
generation stream after a network disconnect.

## Summary

This pull request adds support for the `useChat` hook to resume an
ongoing chat generation stream by exposing `experimental_resume()` that
can be called by any client, typically during the initial mount of the
hook.

The `experimental_resume` function makes a `GET` request to the api
endpoint you've initialized the hook with (or `/api/chat` by default)
and streams the contents of the stream if it is active or fails silently
if it has ended.

In order for `experimental_resume` to work as intended, it requires the
usage of the
[`resumable-stream`](https://www.npmjs.com/package/resumable-stream)
package for stream creation and a redis instance for the package to
manage the pub/sub mechanism.

## Verification

An example has been added at `examples/next-openai/app/use-chat-resume`
to test the feature. Follow the following steps to test it end-to-end:
1. Run the development server
2. Navigate to `http://localhost:3000/use-chat-resume`
3. Send a message that will have a longer generation duration, example
"Write an essay about Michael Jordan"
4. Once the generation starts, click the chat id above to open the
conversation in a new tab
5. Verify the stream gets resumed

## Tasks

- [x] Tests have been added / updated (for bug fixes / features)
- [x] Documentation has been added / updated (for bug fixes / features)
- [x] A _patch_ changeset for relevant packages has been added
- [x] Formatting issues have been fixed (run `pnpm prettier-fix` in the
project root)

---------

Co-authored-by: Lars Grammel <[email protected]>
# Releases
## [email protected]

### Patch Changes

-   Updated dependencies [6c59ae7]
    -   @ai-sdk/[email protected]
    -   @ai-sdk/[email protected]

## @ai-sdk/[email protected]

### Patch Changes

-   6c59ae7: feat (ui/react): support resuming an ongoing stream
-   Updated dependencies [6c59ae7]
    -   @ai-sdk/[email protected]

## @ai-sdk/[email protected]

### Patch Changes

-   Updated dependencies [6c59ae7]
    -   @ai-sdk/[email protected]

## @ai-sdk/[email protected]

### Patch Changes

-   Updated dependencies [6c59ae7]
    -   @ai-sdk/[email protected]

## @ai-sdk/[email protected]

### Patch Changes

-   6c59ae7: feat (ui/react): support resuming an ongoing stream

## @ai-sdk/[email protected]

### Patch Changes

-   [email protected]

## @ai-sdk/[email protected]

### Patch Changes

-   Updated dependencies [6c59ae7]
    -   @ai-sdk/[email protected]

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
## Background
This pull request fixes a docs formatting issue due to a missing comma
in useChat reference docs.

## Summary

Fixed formatting in useChat reference docs by adding a comma.

## Tasks
- [x] Documentation has been added / updated (for bug fixes / features)
- [x] Formatting issues have been fixed (run `pnpm prettier-fix` in the
project root)

## Related Issues
vercel#6052
## Background

The Dify provider allows developers to easily integrate Dify's
application workflow with their applications using the Vercel AI SDK.

## Summary

This PR adds the Dify provider documentation to the AI SDK, enabling
users to understand how to implement and use the Dify integration.

## Tasks

- [x] Documentation has been added for the Dify provider
- [x] Installation instructions are included
- [x] Usage examples for both cloud and self-hosted instances are
provided

## Related Issues

[Support Dify Provider](vercel#4084)

---------

Co-authored-by: Lars Grammel <[email protected]>
<!--
Welcome to contributing to AI SDK! We're excited to see your changes.

We suggest you read the following contributing guide we've created
before submitting:

https://github.com/vercel/ai/blob/main/CONTRIBUTING.md
-->

## Background

<!-- Why was this change necessary? -->

## Summary

<!-- What did you change? -->

## Verification

<!--
For features & bugfixes.
Please explain how you *manually* verified that the change works
end-to-end as expected (independent of automated tests).
Remove the section if it's not needed (e.g. for docs).
-->

## Tasks

<!--
This task list is intended to help you keep track of what you need to
do.
Feel free to add tasks and remove unnecessary tasks as needed.

Please check if the PR fulfills the following requirements:
-->

- [ ] Tests have been added / updated (for bug fixes / features)
- [ ] Documentation has been added / updated (for bug fixes / features)
- [ ] A _patch_ changeset for relevant packages has been added (for bug
fixes / features - run `pnpm changeset` in the project root)
- [ ] Formatting issues have been fixed (run `pnpm prettier-fix` in the
project root)

## Future Work

<!--
Feel free to mention things not covered by this PR that can be done in
future PRs.
Remove the section if it's not needed.
 -->

## Related Issues

<!--
List related issues here, e.g. "Fixes vercel#1234".
Remove the section if it's not needed.
-->
## Background

The safetyRating was an empty object for some reason

## Summary

Fixes vercel#6109
…el#6133)

## Background

Before in issues like vercel#5499 &
vercel#5833, if users ran into an
issue where the messages array failed to parse correctly they'd run into
a difficult to debug error `Invalid prompt: messages must be an array of
CoreMessage or UIMessage`

## Summary

This PR extends these error messages to include more details on what
exactly went wrong, which is useful information for debugging when stuff
breaks.

On security: I think this is an okay change since the data sent is not
private
This adds gemini-2.5-pro-preview-05-06 to AI SDK
- 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
@lgrammel
Copy link
Collaborator

lgrammel commented May 7, 2025

Please add a changeset.

/**
* Settings specific to Cohere embedding models.
*/
cohere?: CohereEmbeddingSettings;
Copy link
Collaborator

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.

Copy link
Author

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'>;
Copy link
Collaborator

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.

@lgrammel
Copy link
Collaborator

lgrammel commented May 7, 2025

Ideally this would be on the v5 branch.

@QuinnGT QuinnGT marked this pull request as draft May 7, 2025 17:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cohere embeddings models do not work in @ai-sdk/amazon-bedrock