diff --git a/docs/embeddings.md b/docs/embeddings.md index 3ea7767..c270f78 100644 --- a/docs/embeddings.md +++ b/docs/embeddings.md @@ -21,6 +21,7 @@ Chroma provides lightweight wrappers around popular embedding providers, making | [Hugging Face Embedding Server](/embeddings/hugging-face-embedding-server) | ✅ | ✅ | | [Jina AI](/embeddings/jinaai) | ✅ | ✅ | | [Roboflow](/embeddings/roboflow-api) | ✅ | ➖ | +| [Amazon Bedrock](/embeddings/amazon-bedrock) | ✅ | ✅ | | [Ollama](/embeddings/ollama) | ✅ | ✅ | We welcome pull requests to add new Embedding Functions to the community. diff --git a/docs/embeddings/amazon-bedrock.md b/docs/embeddings/amazon-bedrock.md new file mode 100644 index 0000000..bcca6c1 --- /dev/null +++ b/docs/embeddings/amazon-bedrock.md @@ -0,0 +1,102 @@ +--- +--- + +# Amazon Bedrock + +import Tabs from '@theme/Tabs'; +import TabItem from '@theme/TabItem'; + +
Select a language
+ + + + + + + +Chroma provides a convinient wrapper for [Amazon Bedrock](https://aws.amazon.com/bedrock/) embedding API. This embedding function runs remotely on Amazon's servers, and requires an Amazon client information. + + + + +To use Amazon Bedrock embedding API, you must have `boto3` Python package installed. + +```sh +pip install boto3 +``` + +To pass AWS credential, create an instance of `boto3.Session` with your AWS credentials. + +Here is the example: + +```python +import boto3 +import chromadb.utils.embedding_functions as embedding_functions + +session = boto3.Session( + aws_access_key_id=aws_access_key_id, + aws_secret_access_key=aws_secret_access_key, + region_name=region_name, +) +bedrock = embedding_functions.AmazonBedrockEmbeddingFunction(session=session) +bedrock(["document1","document2"]) +``` + +By default, the embedding function uses the `amazon.titan-embed-text-v1` for the model, but you can specify a different model name with `model_name` parameter. For example: + +```python +bedrock = embedding_functions.AmazonBedrockEmbeddingFunction( + session=session, model_name="cohere.embed-multilingual-v3") +bedrock(["こんにちは", "你们好"]) +``` + + + + +To use Amazon Bedrock embedding API, you must have `@aws-sdk/client-bedrock-runtime` installed. + +You can pass AWS credentials to the constructor of `AmazonBedrockEmbeddingFunction` like this: + +```javascript +import { AmazonBedrockEmbeddingFunction } from 'chromadb'; + +const ef = new AmazonBedrockEmbeddingFunction({ + config: { + credentials: { + accessKeyId: process.env.AWS_ACCESS_KEY_ID, + secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY, + }, + region: "us-east-1" // Default region. You can change it to your region. + }, +}) + +// use directly +const embeddings = await ef.generate(["foo"]) + +// pass documents to query for .add and .query +const collection = await client.createCollection({name: "name", embeddingFunction: ef}) +const collection = await client.getCollection({name: "name", embeddingFunction: ef}) +``` + +If you want to use other credentials, e.g., SSO, Temporary Credential, etc., you need to install `@aws-sdk/credential-providers`. + +See [AWS SDK for JavaScript v3](https://docs.aws.amazon.com/sdk-for-javascript/v3/developer-guide/setting-credentials.html) for more information. + +Here is the example using SSO credentials: + +```javascript +import { AmazonBedrockEmbeddingFunction } from 'chromadb'; +import { fromSSO } = from '@aws-sdk/credential-providers'; + +const c = await fromSSO({profile: "my-profile"}) + +const ef = new AmazonBedrockEmbeddingFunction({ + config: { + credentials: c, + region: "us-east-1" + }, +}) +``` + + + diff --git a/sidebars.js b/sidebars.js index f94bc3f..7c23790 100644 --- a/sidebars.js +++ b/sidebars.js @@ -95,6 +95,7 @@ const sidebars = { 'embeddings/roboflow-api', 'embeddings/hugging-face-embedding-server', 'embeddings/jinaai', + 'embeddings/amazon-bedrock', 'embeddings/ollama', ], },