Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: AmazonBedrockEmbeddingFunction support for Cohere Embed models #1675

Closed
wants to merge 5 commits into from
Closed
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
31 changes: 26 additions & 5 deletions chromadb/utils/embedding_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -751,18 +751,39 @@ def __init__(
def __call__(self, input: Documents) -> Embeddings:
accept = "application/json"
content_type = "application/json"
embeddings = []
for text in input:
input_body = {"inputText": text}
provider = self._model_name.split('.')[0]
if provider == "amazon":
embeddings = []
for text in input:
input_body = {
"inputText": text
}
body = json.dumps(input_body)
response = self._client.invoke_model(
body=body,
modelId=self._model_name,
accept=accept,
contentType=content_type,
)
embedding = json.load(response.get("body")).get("embedding")
embeddings.append(embedding)
elif provider == "cohere":
# See Amazon Bedrock User Guide > Cohere Embed models for more information
# https://docs.aws.amazon.com/bedrock/latest/userguide/model-parameters-embed.html
input_body = {
"texts": input,
JGalego marked this conversation as resolved.
Show resolved Hide resolved
"input_type": "search_document"
JGalego marked this conversation as resolved.
Show resolved Hide resolved
}
body = json.dumps(input_body)
response = self._client.invoke_model(
JGalego marked this conversation as resolved.
Show resolved Hide resolved
body=body,
modelId=self._model_name,
accept=accept,
contentType=content_type,
)
embedding = json.load(response.get("body")).get("embedding")
embeddings.append(embedding)
embeddings = json.load(response.get("body")).get("embeddings")
else:
JGalego marked this conversation as resolved.
Show resolved Hide resolved
raise NotImplemented
return embeddings


Expand Down
Loading