From 9d4d457bd50c971553225d62746c230e7927f670 Mon Sep 17 00:00:00 2001 From: Aki Ariga Date: Fri, 19 Jan 2024 17:57:12 -0800 Subject: [PATCH 1/3] feat: Amazon Bedrock Embedding doc --- docs/embeddings.md | 1 + docs/embeddings/amazon-bedrock.md | 66 +++++++++++++++++++++++++++++++ sidebars.js | 1 + 3 files changed, 68 insertions(+) create mode 100644 docs/embeddings/amazon-bedrock.md diff --git a/docs/embeddings.md b/docs/embeddings.md index b1adb3eb..dfc4adce 100644 --- a/docs/embeddings.md +++ b/docs/embeddings.md @@ -20,6 +20,7 @@ Chroma provides lightweight wrappers around popular embedding providers, making | [Instructor](/embeddings/instructor) | ✅ | ➖ | | [Hugging Face Embedding Server](/embeddings/hugging-face-embedding-server) | ✅ | ✅ | | [Jina AI](/embeddings/jinaai) | ✅ | ✅ | +| [Amazon Bedrock](/embeddings/amazon-bedrock) | ✅ | ✅ | 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 00000000..1cac7909 --- /dev/null +++ b/docs/embeddings/amazon-bedrock.md @@ -0,0 +1,66 @@ +--- +--- + +# 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 and create an instance of `boto3.Session` with your AWS credentials. To use: + +```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. To use: + +```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"}}) + +// 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}) +``` + + + diff --git a/sidebars.js b/sidebars.js index 62c6fd88..cd14a330 100644 --- a/sidebars.js +++ b/sidebars.js @@ -93,6 +93,7 @@ const sidebars = { 'embeddings/instructor', 'embeddings/hugging-face-embedding-server', 'embeddings/jinaai', + 'embeddings/amazon-bedrock', ], }, ], From 7390e294143b62aeeb2e8f62c535f17a1c62726b Mon Sep 17 00:00:00 2001 From: Aki Ariga Date: Sun, 21 Jan 2024 09:51:18 -0800 Subject: [PATCH 2/3] Apply review feedback - Add boto3 installation - Add more JS authentication details --- docs/embeddings/amazon-bedrock.md | 46 +++++++++++++++++++++++++++---- 1 file changed, 41 insertions(+), 5 deletions(-) diff --git a/docs/embeddings/amazon-bedrock.md b/docs/embeddings/amazon-bedrock.md index 1cac7909..227a5bae 100644 --- a/docs/embeddings/amazon-bedrock.md +++ b/docs/embeddings/amazon-bedrock.md @@ -19,7 +19,15 @@ Chroma provides a convinient wrapper for [Amazon Bedrock](https://aws.amazon.com -To use Amazon Bedrock embedding API, you must have `boto3` Python package installed and create an instance of `boto3.Session` with your AWS credentials. To use: +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 @@ -45,14 +53,22 @@ bedrock(["こんにちは", "你们好"]) -To use Amazon Bedrock embedding API, you must have `@aws-sdk/client-bedrock-runtime` installed. To use: +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'; -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"}}) +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"]) @@ -62,5 +78,25 @@ const collection = await client.createCollection({name: "name", embeddingFunctio const collection = await client.getCollection({name: "name", embeddingFunction: ef}) ``` +If you want to use other credentials, 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" + }, +}) +``` + From db5ee3c7772abdbbb42299f656e199be6543a5a3 Mon Sep 17 00:00:00 2001 From: Aki Ariga Date: Tue, 27 Feb 2024 07:12:23 -0800 Subject: [PATCH 3/3] Add more examples for credentials --- docs/embeddings/amazon-bedrock.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/embeddings/amazon-bedrock.md b/docs/embeddings/amazon-bedrock.md index 227a5bae..bcca6c19 100644 --- a/docs/embeddings/amazon-bedrock.md +++ b/docs/embeddings/amazon-bedrock.md @@ -78,7 +78,7 @@ const collection = await client.createCollection({name: "name", embeddingFunctio const collection = await client.getCollection({name: "name", embeddingFunction: ef}) ``` -If you want to use other credentials, you need to install `@aws-sdk/credential-providers`. +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.