Skip to content
This repository was 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 1 commit
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
66 changes: 66 additions & 0 deletions docs/embeddings/amazon-bedrock.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
---
---

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

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

To use Amazon Bedrock embedding API, you must have `@aws-sdk/client-bedrock-runtime` installed. To use:
Copy link
Contributor

Choose a reason for hiding this comment

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

@chezou, do you think users can benefit from explaining how to supply the credentials e.g. export them as env vars or use aws cli to login?

Copy link
Author

@chezou chezou Jan 21, 2024

Choose a reason for hiding this comment

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

I think it's too much to explain AWS credential preparation stuff in detail, so I added an example with Access Key ID and Secret Access Key instead.
Also, added the link to more information on AWS credential handling.
7390e29


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

</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