|
| 1 | +--- |
| 2 | +--- |
| 3 | + |
| 4 | +# Amazon Bedrock |
| 5 | + |
| 6 | +import Tabs from '@theme/Tabs'; |
| 7 | +import TabItem from '@theme/TabItem'; |
| 8 | + |
| 9 | +<div class="select-language">Select a language</div> |
| 10 | + |
| 11 | +<Tabs queryString groupId="lang"> |
| 12 | +<TabItem value="py" label="Python"></TabItem> |
| 13 | +<TabItem value="js" label="JavaScript"></TabItem> |
| 14 | +</Tabs> |
| 15 | + |
| 16 | + |
| 17 | +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. |
| 18 | + |
| 19 | +<Tabs queryString groupId="lang" className="hideTabSwitcher"> |
| 20 | +<TabItem value="py" label="Python"> |
| 21 | + |
| 22 | +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: |
| 23 | + |
| 24 | +```python |
| 25 | +import boto3 |
| 26 | +import chromadb.utils.embedding_functions as embedding_functions |
| 27 | + |
| 28 | +session = boto3.Session( |
| 29 | + aws_access_key_id=aws_access_key_id, |
| 30 | + aws_secret_access_key=aws_secret_access_key, |
| 31 | + region_name=region_name, |
| 32 | +) |
| 33 | +bedrock = embedding_functions.AmazonBedrockEmbeddingFunction(session=session) |
| 34 | +bedrock(["document1","document2"]) |
| 35 | +``` |
| 36 | + |
| 37 | +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: |
| 38 | + |
| 39 | +```python |
| 40 | +bedrock = embedding_functions.AmazonBedrockEmbeddingFunction( |
| 41 | + session=session, model_name="cohere.embed-multilingual-v3") |
| 42 | +bedrock(["こんにちは", "你们好"]) |
| 43 | +``` |
| 44 | + |
| 45 | +</TabItem> |
| 46 | +<TabItem value="js" label="JavaScript"> |
| 47 | + |
| 48 | +To use Amazon Bedrock embedding API, you must have `@aws-sdk/client-bedrock-runtime` installed. To use: |
| 49 | + |
| 50 | +```javascript |
| 51 | +import { AmazonBedrockEmbeddingFunction } from 'chromadb'; |
| 52 | +import { fromSSO } = from '@aws-sdk/credential-providers'; |
| 53 | + |
| 54 | +const c = await fromSSO({profile: "my-profile"}) |
| 55 | +const ef = new AmazonBedrockEmbeddingFunction({config: {credentials: c, region: "us-east-1"}}) |
| 56 | + |
| 57 | +// use directly |
| 58 | +const embeddings = await ef.generate(["foo"]) |
| 59 | + |
| 60 | +// pass documents to query for .add and .query |
| 61 | +const collection = await client.createCollection({name: "name", embeddingFunction: ef}) |
| 62 | +const collection = await client.getCollection({name: "name", embeddingFunction: ef}) |
| 63 | +``` |
| 64 | + |
| 65 | +</TabItem> |
| 66 | +</Tabs> |
0 commit comments