Skip to content
This repository has been archived by the owner on May 10, 2024. It is now read-only.

feat: Amazon Bedrock Embedding doc #204

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/embeddings.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
102 changes: 102 additions & 0 deletions docs/embeddings/amazon-bedrock.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
---
---

# Amazon Bedrock

import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';

<div class="select-language">Select a language</div>

<Tabs queryString groupId="lang">
<TabItem value="py" label="Python"></TabItem>
<TabItem value="js" label="JavaScript"></TabItem>
</Tabs>


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.

<Tabs queryString groupId="lang" className="hideTabSwitcher">
<TabItem value="py" label="Python">

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(["こんにちは", "你们好"])
```

</TabItem>
<TabItem value="js" label="JavaScript">

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, you need to install `@aws-sdk/credential-providers`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you provide an example or two of "other credentials"? thanks!

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, added db5ee3c


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"
},
})
```

</TabItem>
</Tabs>
1 change: 1 addition & 0 deletions sidebars.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ const sidebars = {
'embeddings/instructor',
'embeddings/hugging-face-embedding-server',
'embeddings/jinaai',
'embeddings/amazon-bedrock',
],
},
],
Expand Down