This repository has been archived by the owner on May 10, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 110
feat: Amazon Bedrock Embedding doc #204
Open
chezou
wants to merge
5
commits into
chroma-core:main
Choose a base branch
from
chezou:bedrock-emb
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
9d4d457
feat: Amazon Bedrock Embedding doc
chezou 7390e29
Apply review feedback
chezou db5ee3c
Add more examples for credentials
chezou ef25f33
Merge branch 'main' into bedrock-emb
chezou b4e64a1
Merge branch 'main' into bedrock-emb
chezou File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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`. | ||
|
||
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, added db5ee3c