Skip to content

feat(amazon-bedrock): binary embeddings #5642

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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

anatolzak
Copy link
Contributor

@anatolzak anatolzak commented Apr 9, 2025

Background

The AI SDK currently does not support generating binary embeddings using Amazon Titan Text Embeddings V2.
Binary embeddings offer significant advantages, maintaining about 95% accuracy while having a footprint that is more than 95% smaller compared to float embeddings.

image

https://youtu.be/8B1RW6uw8GQ?t=1109

Summary

This PR introduces an option to allow generating binary embeddings using Amazon Titan Text Embeddings V2.

const { embedding } = await embed({
  model: bedrock.embedding('amazon.titan-embed-text-v2:0', {
    embeddingType: 'binary',
  }),
  value: 'sunny day at the beach',
});

console.log(embedding);

[
  0, 1, 0, 0, 1, 1, 0, 0, 0, 1, 1, 1,
  1, 0, 0, 0, 1, 0, 1, 1, 0, 1, 1, 0,
  1, 1, 1, 0, 1, 1, 1, 1, 0, 0, 1, 1,
  1, 1, 0, 1, 1, 0, 0, 1, 1, 1, 1, 1,
  1, 1, 1, 1, 0, 1, 1, 1, 0, 0, 1, 0,
  0, 1, 1, 0, 1, 0, 0, 1, 1, 1, 1, 0,
  1, 1, 0, 0, 1, 0, 1, 1, 1, 1, 1, 1,
  1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 1, 1,
  0, 0, 0, 1,
  ... 924 more items
]

See the Amazon Titan Text Embeddings v2 response schema for reference:
https://docs.aws.amazon.com/bedrock/latest/userguide/model-parameters-titan-embed-text.html#model-parameters-titan-embed-text-request-response

Tasks

  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)
  • You've followed the PR contributing guidelines for adding a patch changeset to version packages and fixing prettier issues

Future Work

@anatolzak anatolzak force-pushed the feat-amazon-bedrock-binary-embeddings branch 3 times, most recently from 9f7fe83 to b60637c Compare April 11, 2025 11:34
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.

1 participant