Configure Amazon Bedrock Embeddings
This guide shows how to configure Amazon Bedrock embeddings for semantic search in Neo4j Agent Memory.
Supported Models
Neo4j Agent Memory supports these Bedrock embedding models:
| Model | Dimensions | Notes |
|---|---|---|
|
1024 |
Recommended - Best quality/performance balance |
|
1536 |
Legacy model, higher dimensionality |
|
1024 |
Optimized for English text |
|
1024 |
Multilingual support (100+ languages) |
Prerequisites
-
AWS account with Bedrock access
-
Model access enabled in AWS Console (Bedrock → Model access)
-
boto3installed:pip install neo4j-agent-memory[bedrock]
Basic Configuration
Using BedrockEmbedder Directly
from neo4j_agent_memory.embeddings import BedrockEmbedder
embedder = BedrockEmbedder(
model="amazon.titan-embed-text-v2:0",
region_name="us-east-1",
)
# Generate a single embedding
embedding = await embedder.embed("Hello, world!")
print(f"Dimensions: {len(embedding)}") # 1024
# Check model dimensions
print(f"Model dimensions: {embedder.dimensions}")
Using with MemoryClient
from neo4j_agent_memory import MemoryClient, MemorySettings
from neo4j_agent_memory.config.settings import (
Neo4jConfig,
EmbeddingConfig,
EmbeddingProvider,
)
settings = MemorySettings(
neo4j=Neo4jConfig(
uri="neo4j+s://xxx.databases.neo4j.io",
password="your-password",
),
embedding=EmbeddingConfig(
provider=EmbeddingProvider.BEDROCK,
model="amazon.titan-embed-text-v2:0",
aws_region="us-east-1",
),
)
async with MemoryClient(settings) as client:
# Embeddings are generated automatically
await client.short_term.add_message(
session_id="session-1",
role="user",
content="Hello!",
generate_embedding=True,
)
Authentication
BedrockEmbedder uses the standard AWS credential chain:
-
Environment variables (
AWS_ACCESS_KEY_ID,AWS_SECRET_ACCESS_KEY) -
Shared credentials file (
~/.aws/credentials) -
IAM role (for EC2, Lambda, ECS)
Batch Processing
BedrockEmbedder supports efficient batch embedding with automatic chunking:
texts = [
"First document about machine learning",
"Second document about databases",
"Third document about cloud computing",
]
# Automatically batches in groups of 25
embeddings = await embedder.embed_batch(texts)
print(f"Generated {len(embeddings)} embeddings")
|
Bedrock limits batch size to 25 texts per request. The embedder automatically splits larger batches and processes them sequentially. |
Configuration Options
| Option | Default | Description |
|---|---|---|
|
|
Bedrock model ID |
|
From env/config |
AWS region for Bedrock API |
|
None |
AWS credentials profile name |
|
25 |
Max texts per batch request |
IAM Permissions
Required IAM policy for Bedrock embedding access:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"bedrock:InvokeModel"
],
"Resource": [
"arn:aws:bedrock:*::foundation-model/amazon.titan-embed-*",
"arn:aws:bedrock:*::foundation-model/cohere.embed-*"
]
}
]
}
For Lambda functions, attach this policy to the execution role.
Choosing a Model
Troubleshooting
AccessDeniedException
Ensure model access is enabled:
-
Go to AWS Console → Bedrock → Model access
-
Click "Manage model access"
-
Enable the embedding models you need
-
Wait for access to be granted (may take a few minutes)
ValidationException
Check your model ID format:
-
✅ Correct:
amazon.titan-embed-text-v2:0 -
❌ Incorrect:
titan-embed-text-v2(missing prefix)