Skip to content
Open
Show file tree
Hide file tree
Changes from 5 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
53 changes: 21 additions & 32 deletions fern/pages/deployment-options/cohere-on-aws/amazon-bedrock.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -21,57 +21,46 @@ Here, you’ll learn how to use Amazon Bedrock to deploy both the Cohere Command
- Embed - English
- Embed - Multilingual

Note that the code snippets below are in Python, but you can find the equivalent code for other languages (if they’re supported)[here](https://docs.cohere.com/docs/cohere-works-everywhere)
Note that the code snippets below are in Python, but you can find the equivalent code for other languages (if they’re supported) [here](https://docs.cohere.com/docs/cohere-works-everywhere).

## Prerequisites

Here are the steps you'll need to get set up in advance of running Cohere models on Amazon Bedrock.

- Subscribe to Cohere's models on Amazon Bedrock. For more details, [see here](https://docs.aws.amazon.com/bedrock/latest/userguide/model-access.html).
- You'll also need to install the AWS Python SDK and some related tooling. Run:
- `pip install cohere-aws` (or `pip install --upgrade cohere-aws` if you need to upgrade). You can also install from source with `python setup.py install`.
- For more details, see this [GitHub repo](https://github.com/cohere-ai/cohere-aws/) and [related notebooks](https://github.com/cohere-ai/cohere-aws/tree/main/notebooks/bedrock).
- Finally, you'll have to configure your authentication credentials for AWS. This [document](https://boto3.amazonaws.com/v1/documentation/api/latest/guide/quickstart.html#configuration) has more information.
- Subscribe to Cohere's models on Amazon Bedrock. [Check here](https://docs.aws.amazon.com/bedrock/latest/userguide/model-access.html) for more details.
- You may need to pip install `cohere`, `boto3`, and `botocore`.
- You'll also have to configure your authentication credentials for AWS. This [document](https://boto3.amazonaws.com/v1/documentation/api/latest/guide/quickstart.html#configuration) has more information.

## Embeddings

You can use this code to invoke Cohere’s Embed English v3 model (`cohere.embed-english-v3`) or Embed Multilingual v3 model (`cohere.embed-multilingual-v3`) on Amazon Bedrock:
You can use this code to invoke Cohere’s Embed English v3 model (`embed-english-v3`) on Amazon Bedrock:

```python PYTHON
import cohere

co = cohere.BedrockClient(
aws_region="us-east-1",
co = cohere.BedrockClientV2(
aws_region="...",
aws_access_key="...",
aws_secret_key="...",
aws_session_token="...",
)

# Input parameters for embed. In this example we are embedding hacker news post titles.
texts = [
"Interesting (Non software) books?",
"Non-tech books that have helped you grow professionally?",
"I sold my company last month for $5m. What do I do with the money?",
"How are you getting through (and back from) burning out?",
"I made $24k over the last month. Now what?",
"What kind of personal financial investment do you do?",
"Should I quit the field of software development?",
]
input_type = "clustering"
truncate = "NONE" # optional
model_id = (
"cohere.embed-english-v3" # or "cohere.embed-multilingual-v3"
)

# Invoke the model and print the response
result = co.embed(
model=model_id,
input_type=input_type,
texts=texts,
truncate=truncate,
) # aws_client.invoke_model(**params)
model="cohere.embed-english-v3",
input_type="clustering",
embedding_types=["float"],
texts=[
"Interesting (Non software) books?",
"Non-tech books that have helped you grow professionally?",
"I sold my company last month for $5m. What do I do with the money?",
"How are you getting through (and back from) burning out?",
"I made $24k over the last month. Now what?",
"What kind of personal financial investment do you do?",
"Should I quit the field of software development?",
],
)

print(result)
print(result.embeddings.float)
```

Note that we've released multimodal embeddings models that are able to handle images in addition to text. Find [more information here](https://docs.cohere.com/docs/multimodal-embeddings).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,6 @@ In order to successfully subscribe to Cohere’s offerings on Amazon SageMaker,

These permissions allow a user to manage your organization’s Amazon SageMaker subscriptions. Learn more about [managing Amazon’s IAM Permissions here](https://aws.amazon.com/iam/?trk=cf28fddb-12ed-4ffd-981b-b89c14793bf1&sc_channel=ps&ef_id=CjwKCAjwsvujBhAXEiwA_UXnAJ4JEQ3KgW0eFBzr5nuwt9L5S7w3A0f3wqensQJgUQ7Mf_ZEdArZRxoCjKQQAvD_BwE:G:s&s_kwcid=AL!4422!3!652240143562!e!!g!!amazon%20iam!19878797467!148973348604). Contact your AWS administrator if you have questions about account permissions.

You'll also need to install the AWS Python SDK and some related tooling. Run:

- `pip install cohere-aws` (or `pip install --upgrade cohere-aws` if you want to upgrade to the most recent version of the SDK).

## Cohere with Amazon SageMaker Setup

First, navigate to [Cohere’s SageMaker Marketplace](https://aws.amazon.com/marketplace/seller-profile?id=87af0c85-6cf9-4ed8-bee0-b40ce65167e0) to view the available product offerings. Select the product offering to which you are interested in subscribing.
Expand Down Expand Up @@ -81,6 +77,7 @@ result = co.embed(

print(result)
```

<Warning>Cohere's embed models don't support batch transform operations.</Warning>

Note that we've released multimodal embeddings models that are able to handle images in addition to text. Find [more information here](https://docs.cohere.com/docs/multimodal-embeddings).
Expand Down
57 changes: 21 additions & 36 deletions fern/pages/v2/deployment-options/cohere-on-aws/amazon-bedrock.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ updatedAt: 'Thu May 30 2024 16:00:53 GMT+0000 (Coordinated Universal Time)'
<Note title="Note">
The code examples in this section use the Cohere v1 API. The v2 API is not yet supported for cloud deployments and will be coming soon.
</Note>

In an effort to make our language-model capabilities more widely available, we've partnered with a few major platforms to create hosted versions of our offerings.

Here, you'll learn how to use Amazon Bedrock to deploy both the Cohere Command and the Cohere Embed models on the AWS cloud computing platform. The following models are available on Bedrock:
Expand All @@ -29,13 +30,9 @@ Note that the code snippets below are in Python, but you can find the equivalent

Here are the steps you'll need to get set up in advance of running Cohere models on Amazon Bedrock.

- Subscribe to Cohere's models on Amazon Bedrock. For more details, [see here](https://docs.aws.amazon.com/bedrock/latest/userguide/model-access.html).
- You'll also need to install the AWS Python SDK and some related tooling. Run:
- `pip install cohere-aws` (or `pip install --upgrade cohere-aws` if you need to upgrade). You can also install from source with `python setup.py install`.
- For more details, see this [GitHub repo](https://github.com/cohere-ai/cohere-aws/) and [related notebooks](https://github.com/cohere-ai/cohere-aws/tree/main/notebooks/bedrock).
- Finally, you'll have to configure your authentication credentials for AWS. This [document](https://boto3.amazonaws.com/v1/documentation/api/latest/guide/quickstart.html#configuration) has more information.

## Embeddings
- Subscribe to Cohere's models on Amazon Bedrock. [Check here](https://docs.aws.amazon.com/bedrock/latest/userguide/model-access.html) for more details.
- You may need to pip install `cohere`, `boto3`, and `botocore`.
- You'll also have to configure your authentication credentials for AWS. This [document](https://boto3.amazonaws.com/v1/documentation/api/latest/guide/quickstart.html#configuration) has more information.

## Embeddings

Expand All @@ -44,39 +41,29 @@ You can use this code to invoke Cohere’s Embed English v3 model (`cohere.embed
```python PYTHON
import cohere

co = cohere.BedrockClient(
aws_region="us-east-1",
co = cohere.BedrockClientV2(
aws_region="...",
aws_access_key="...",
aws_secret_key="...",
aws_session_token="...",
)

# Input parameters for embed. In this example we are embedding hacker news post titles.
texts = [
"Interesting (Non software) books?",
"Non-tech books that have helped you grow professionally?",
"I sold my company last month for $5m. What do I do with the money?",
"How are you getting through (and back from) burning out?",
"I made $24k over the last month. Now what?",
"What kind of personal financial investment do you do?",
"Should I quit the field of software development?",
]
input_type = "clustering"
truncate = "NONE" # optional
model_id = (
"cohere.embed-english-v3" # or "cohere.embed-multilingual-v3"
)


# Invoke the model and print the response
result = co.embed(
model=model_id,
input_type=input_type,
texts=texts,
truncate=truncate,
) # aws_client.invoke_model(**params)
model="cohere.embed-english-v3",
input_type="clustering",
embedding_types=["float"],
texts=[
"Interesting (Non software) books?",
"Non-tech books that have helped you grow professionally?",
"I sold my company last month for $5m. What do I do with the money?",
"How are you getting through (and back from) burning out?",
"I made $24k over the last month. Now what?",
"What kind of personal financial investment do you do?",
"Should I quit the field of software development?",
],
)

print(result)
print(result.embeddings.float)
```

Note that we've released multimodal embeddings models that are able to handle images in addition to text. Find [more information here](https://docs.cohere.com/docs/multimodal-embeddings).
Expand Down Expand Up @@ -111,7 +98,7 @@ You can use this code to invoke our latest Rerank models on Bedrock
import cohere

co = cohere.BedrockClientV2(
aws_region="us-west-2", # pick a region where the model is available
aws_region="...",
aws_access_key="...",
aws_secret_key="...",
aws_session_token="...",
Expand All @@ -124,13 +111,11 @@ docs = [
"Washington, D.C. (also known as simply Washington or D.C., and officially as the District of Columbia) is the capital of the United States. It is a federal district.",
"Capital punishment has existed in the United States since beforethe United States was a country. As of 2017, capital punishment is legal in 30 of the 50 states.",
]

response = co.rerank(
model="cohere.rerank-v3-5:0",
query="What is the capital of the United States?",
documents=docs,
top_n=3,
)

print(response)
```
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,6 @@ In order to successfully subscribe to Cohere’s offerings on Amazon SageMaker,

These permissions allow a user to manage your organization’s Amazon SageMaker subscriptions. Learn more about [managing Amazon’s IAM Permissions here](https://aws.amazon.com/iam/?trk=cf28fddb-12ed-4ffd-981b-b89c14793bf1&sc_channel=ps&ef_id=CjwKCAjwsvujBhAXEiwA_UXnAJ4JEQ3KgW0eFBzr5nuwt9L5S7w3A0f3wqensQJgUQ7Mf_ZEdArZRxoCjKQQAvD_BwE:G:s&s_kwcid=AL!4422!3!652240143562!e!!g!!amazon%20iam!19878797467!148973348604). Contact your AWS administrator if you have questions about account permissions.

You'll also need to install the AWS Python SDK and some related tooling. Run:

- `pip install cohere-aws` (or `pip install --upgrade cohere-aws` if you want to upgrade to the most recent version of the SDK).

## Cohere with Amazon SageMaker Setup

First, navigate to [Cohere’s SageMaker Marketplace](https://aws.amazon.com/marketplace/seller-profile?id=87af0c85-6cf9-4ed8-bee0-b40ce65167e0) to view the available product offerings. Select the product offering to which you are interested in subscribing.
Expand Down