AWS Bedrock integration for LangChain4j enabling Java applications to interact with various LLM providers through a unified interface
Cohere and Amazon Titan embedding models for AWS Bedrock.
Cohere embedding model supporting English and multilingual variants.
public class BedrockCohereEmbeddingModel extends DimensionAwareEmbeddingModel {
public BedrockCohereEmbeddingModel(Builder builder);
// Core methods
public Response<List<Embedding>> embedAll(List<TextSegment> textSegments);
// Builder
public static Builder builder();
}public static class Builder {
public Builder model(Model model);
public Builder model(String model);
public Builder inputType(InputType inputType);
public Builder inputType(String inputType);
public Builder truncate(Truncate truncate);
public Builder truncate(String truncate);
public Builder client(BedrockRuntimeClient client);
public Builder region(Region region);
public Builder credentialsProvider(AwsCredentialsProvider credentialsProvider);
public Builder maxRetries(Integer maxRetries);
public Builder maxSegmentsPerBatch(Integer maxSegmentsPerBatch);
public BedrockCohereEmbeddingModel build();
}public enum Model {
COHERE_EMBED_ENGLISH_V3("cohere.embed-english-v3"),
COHERE_EMBED_MULTILINGUAL_V3("cohere.embed-multilingual-v3");
public String getValue();
}
public enum InputType {
SEARCH_DOCUMENT("search_document"),
SEARCH_QUERY("search_query"),
CLASSIFICATION("classification"),
CLUSTERING("clustering");
public String getValue();
}
public enum Truncate {
NONE("NONE"),
START("START"),
END("END");
public String getValue();
}Amazon Titan embedding model supporting v1 and v2 variants.
public class BedrockTitanEmbeddingModel extends AbstractBedrockEmbeddingModel<BedrockTitanEmbeddingResponse> {
// Core methods
public Response<List<Embedding>> embedAll(List<TextSegment> textSegments);
public String getModel();
public Integer getDimensions();
public Boolean getNormalize();
public Region getRegion();
public AwsCredentialsProvider getCredentialsProvider();
public Integer getMaxRetries();
// Builder
public static BedrockTitanEmbeddingModelBuilder<?, ?> builder();
}public abstract static class BedrockTitanEmbeddingModelBuilder<B extends BedrockTitanEmbeddingModelBuilder<B, C>, C> {
public B model(String model);
public B dimensions(Integer dimensions);
public B normalize(Boolean normalize);
public B client(BedrockRuntimeClient client);
public B region(Region region);
public B credentialsProvider(AwsCredentialsProvider credentialsProvider);
public B maxRetries(Integer maxRetries);
public abstract C build();
}public enum Types {
TitanEmbedTextV1("amazon.titan-embed-text-v1"),
TitanEmbedTextV2("amazon.titan-embed-text-v2:0");
public String getValue();
}| Feature | Cohere English V3 | Cohere Multilingual V3 | Titan V1 | Titan V2 |
|---|---|---|---|---|
| Dimensions | 1024 (fixed) | 1024 (fixed) | 1536 (fixed) | 256/512/1024 (configurable) |
| Languages | English | 100+ | English | English |
| Input Types | 4 types | 4 types | N/A | N/A |
| Truncation | 3 modes | 3 modes | Automatic | Automatic |
| Normalization | No | No | No | Optional |
| Max Input Tokens | 512 | 512 | 8192 | 8192 |
| Max Batch Size | 96 | 96 | 1 | 1 |
Cohere:
model: COHERE_EMBED_ENGLISH_V3 or COHERE_EMBED_MULTILINGUAL_V3inputType: SEARCH_DOCUMENT, SEARCH_QUERY, CLASSIFICATION, or CLUSTERINGtruncate: NONE, START, or ENDmaxSegmentsPerBatch: Up to 96 segments per requestTitan:
model: TitanEmbedTextV1 or TitanEmbedTextV2dimensions: 256, 512, or 1024 (V2 only)normalize: true/false (V2 only)Related: