LlamaIndex Bedrock Embeddings Integration
The `llama-index-embeddings-bedrock` library provides robust integration for Amazon Bedrock embedding models within the LlamaIndex framework. It allows developers to leverage various AWS Bedrock models like Amazon Titan and Cohere for generating text embeddings. The library is actively maintained, with version 0.8.0 released on March 12, 2026, and receives frequent updates to align with LlamaIndex core and Bedrock API changes.
Common errors
-
botocore.exceptions.NoRegionError: You must specify a region.
cause The AWS region was not specified in the `BedrockEmbedding` constructor or via environment variables (`AWS_REGION_NAME`).fixEnsure `region_name` is provided to `BedrockEmbedding` (e.g., `region_name="us-east-1"`) or set the `AWS_REGION_NAME` environment variable. Also check other AWS credential configurations. -
An error occurred (ValidationException) when calling the InvokeModel operation: Input is too long for requested model.
cause The input text provided to the Bedrock embedding model (especially Cohere models) exceeded its maximum token or character limit.fixReduce the size of the text chunks being embedded. For LlamaIndex, adjust `chunk_size` and `chunk_overlap` settings in your `Settings` (or `ServiceContext` for older versions) object to ensure chunks adhere to the model's limits. -
Vector dimension 1536 does not match the dimension of the index 1024
cause The embedding model used to generate vectors (e.g., OpenAI's ADA with 1536 dimensions by default in LlamaIndex) does not match the dimensionality of the vector store index (e.g., 1024 for AWS Titan).fixEnsure consistency in embedding model dimensions. If you intend to use AWS Bedrock embeddings, configure LlamaIndex to use `BedrockEmbedding` for all indexing and querying operations, and re-index your data if the dimensions are mismatched. Explicitly set the embedding model in LlamaIndex's global settings or `ServiceContext`. -
Unable to install llama-index-embeddings-bedrock (due to `llama-index-core` version conflict)
cause Specific versions of `llama-index-embeddings-bedrock` might have strict dependencies on `llama-index-core`, leading to conflicts if `llama-index-core` is already installed at an incompatible version.fixUpgrade `llama-index-embeddings-bedrock` to the latest version, which typically has broader `llama-index-core` compatibility. If issues persist, try upgrading `llama-index-core` to its latest version or, as a last resort, downgrade `llama-index-core` to a version compatible with your `llama-index-embeddings-bedrock` (e.g., `pip install llama-index-core==0.10.0`).
Warnings
- gotcha Cohere embedding models on Bedrock have strict input token limits (e.g., 512 tokens or ~2048 characters for `cohere.embed-english-v3`). Exceeding this limit will result in a `ValidationException` or 'Input too long' error, even with small LlamaIndex chunk sizes if the underlying text is too long.
- gotcha When using an `application_inference_profile_arn` with `BedrockEmbedding`, the `model_name` argument *must* still match the underlying model referenced by the profile. The integration does not validate this, and mismatched values lead to undefined behavior or errors.
- gotcha Failing to configure AWS credentials (e.g., `AWS_ACCESS_KEY_ID`, `AWS_SECRET_ACCESS_KEY`, `AWS_REGION_NAME`) or specify `region_name` during `BedrockEmbedding` initialization will lead to `botocore.exceptions.NoRegionError` or authentication failures.
- gotcha Mixing embedding models with different output vector dimensions (e.g., default OpenAI `text-embedding-ada-002` (1536 dims) with AWS Titan (1024 dims)) when using a vector store can lead to `Vector dimension does not match the dimension of the index` errors.
Install
-
pip install llama-index-embeddings-bedrock
Imports
- BedrockEmbedding
from llama_index.embeddings.bedrock import BedrockEmbedding
Quickstart
import os
from llama_index.embeddings.bedrock import BedrockEmbedding
# Configure AWS credentials and region via environment variables or explicitly
# os.environ['AWS_ACCESS_KEY_ID'] = 'YOUR_ACCESS_KEY'
# os.environ['AWS_SECRET_ACCESS_KEY'] = 'YOUR_SECRET_KEY'
# os.environ['AWS_REGION_NAME'] = 'us-east-1'
# Initialize the embedding model
embed_model = BedrockEmbedding(
model_name="cohere.embed-english-v3", # Example model, choose from supported models
region_name=os.environ.get('AWS_REGION_NAME', 'us-east-1'),
# Optionally, specify credentials directly or via profile_name
aws_access_key_id=os.environ.get('AWS_ACCESS_KEY_ID'),
aws_secret_access_key=os.environ.get('AWS_SECRET_ACCESS_KEY'),
# profile_name='my-aws-profile'
)
# Get a single embedding
text = "Hello, world! This is a test document."
embedding = embed_model.get_text_embedding(text)
print(f"Embedding length: {len(embedding)}")
print(f"First 5 embedding values: {embedding[:5]}")
# List supported models
# supported_models = BedrockEmbedding.list_supported_models()
# print("Supported models:", supported_models)