Cohere Embeddings

Provides Bedrock Cohere Embedding client. Integrate generative AI capabilities into essential apps and workflows that improve business outcomes.

The AWS Bedrock Cohere Model Page and Amazon Bedrock User Guide contains detailed information on how to use the AWS hosted model.


Refer to the Spring AI documentation on Amazon Bedrock for setting up API access.

Add Repositories and BOM

Spring AI artifacts are published in Spring Milestone and Snapshot repositories. Refer to the Repositories section to add these repositories to your build system.

To help with dependency management, Spring AI provides a BOM (bill of materials) to ensure that a consistent version of Spring AI is used throughout the entire project. Refer to the Dependency Management section to add the Spring AI BOM to your build system.


Add the spring-ai-bedrock-ai-spring-boot-starter dependency to your project’s Maven pom.xml file:


or to your Gradle build.gradle build file.

dependencies {
    implementation ''
Refer to the Dependency Management section to add the Spring AI BOM to your build file.

Enable Cohere Embedding Support

By default the Cohere model is disabled. To enable it set the property to true. Exporting environment variable is one way to set this configuration property:


Embedding Properties

The prefix is the property prefix to configure the connection to AWS Bedrock.

Property Description Default

AWS region to use.


AWS access key.


AWS secret key.


The prefix (defined in BedrockCohereEmbeddingProperties) is the property prefix that configures the embedding client implementation for Cohere.




Enable or disable support for Cohere


The model id to use. See the CohereEmbeddingModel for the supported models.


Prepends special tokens to differentiate each type from one another. You should not mix different types together, except when mixing types for for search and retrieval. In this case, embed your corpus with the search_document type and embedded queries with type search_query type.


Specifies how the API handles inputs longer than the maximum token length. If you specify LEFT or RIGHT, the model discards the input until the remaining input is exactly the maximum input token length for the model.


Look at the CohereEmbeddingModel for other model IDs. Supported values are: cohere.embed-multilingual-v3 and cohere.embed-english-v3. Model ID values can also be found in the AWS Bedrock documentation for base model IDs.

All properties prefixed with can be overridden at runtime by adding a request specific Embedding Options to the EmbeddingRequest call.

Embedding Options

The provides model configurations, such as input-type or truncate.

On start-up, the default options can be configured with the BedrockCohereEmbeddingClient(api, options) constructor or the* properties.

At run-time you can override the default options by adding new, request specific, options to the EmbeddingRequest call. For example to override the default temperature for a specific request:

EmbeddingResponse embeddingResponse =
    new EmbeddingRequest(List.of("Hello World", "World is big and salvation is near"),

Sample Controller (Auto-configuration)

Create a new Spring Boot project and add the spring-ai-bedrock-ai-spring-boot-starter to your pom (or gradle) dependencies.

Add a file, under the src/main/resources directory, to enable and configure the Cohere Embedding client:${AWS_ACCESS_KEY_ID}${AWS_SECRET_ACCESS_KEY}
replace the regions, access-key and secret-key with your AWS credentials.

This will create a BedrockCohereEmbeddingClient implementation that you can inject into your class. Here is an example of a simple @Controller class that uses the chat client for text generations.

public class EmbeddingController {

    private final EmbeddingClient embeddingClient;

    public EmbeddingController(EmbeddingClient embeddingClient) {
        this.embeddingClient = embeddingClient;

    public Map embed(@RequestParam(value = "message", defaultValue = "Tell me a joke") String message) {
        EmbeddingResponse embeddingResponse = this.embeddingClient.embedForResponse(List.of(message));
        return Map.of("embedding", embeddingResponse);

Manual Configuration

The BedrockCohereEmbeddingClient implements the EmbeddingClient and uses the Low-level CohereEmbeddingBedrockApi Client to connect to the Bedrock Cohere service.

Add the spring-ai-bedrock dependency to your project’s Maven pom.xml file:


or to your Gradle build.gradle build file.

dependencies {
    implementation ''
Refer to the Dependency Management section to add the Spring AI BOM to your build file.

Next, create an BedrockCohereEmbeddingClient and use it for text embeddings:

var cohereEmbeddingApi =new CohereEmbeddingBedrockApi(,
		EnvironmentVariableCredentialsProvider.create(),, new ObjectMapper());

var embeddingClient = new BedrockCohereEmbeddingClient(cohereEmbeddingApi);

EmbeddingResponse embeddingResponse = embeddingClient
	.embedForResponse(List.of("Hello World", "World is big and salvation is near"));

Low-level CohereEmbeddingBedrockApi Client

The CohereEmbeddingBedrockApi provides is lightweight Java client on top of AWS Bedrock Cohere Command models.

Following class diagram illustrates the CohereEmbeddingBedrockApi interface and building blocks:

bedrock cohere embedding low level api

The CohereEmbeddingBedrockApi supports the cohere.embed-english-v3 and cohere.embed-multilingual-v3 models for single and batch embedding computation.

Here is a simple snippet how to use the api programmatically:

CohereEmbeddingBedrockApi api = new CohereEmbeddingBedrockApi(,
		EnvironmentVariableCredentialsProvider.create(),, new ObjectMapper());

CohereEmbeddingRequest request = new CohereEmbeddingRequest(
		List.of("I like to eat apples", "I like to eat oranges"),

CohereEmbeddingResponse response = api.embedding(request);