docs/components/vectordbs/dbs/s3_vectors.mdx
Amazon S3 Vectors is a purpose-built, cost-optimized vector storage and query service for semantic search and AI applications. It provides S3-level elasticity and durability with sub-second query performance.
S3 Vectors support requires additional dependencies. Install them with:
<CodeGroup> ```bash Python pip install boto3 ```npm install @aws-sdk/client-s3vectors
To use Amazon S3 Vectors with Mem0, you need to have an AWS account and the necessary IAM permissions (s3vectors:*). Ensure your environment is configured with AWS credentials (e.g., via ~/.aws/credentials or environment variables).
config = { "vector_store": { "provider": "s3_vectors", "config": { "vector_bucket_name": "my-mem0-vector-bucket", "collection_name": "my-memories-index", "embedding_model_dims": 1536, "distance_metric": "cosine", "region_name": "us-east-1" } } }
m = Memory.from_config(config) messages = [ {"role": "user", "content": "I'm planning to watch a movie tonight. Any recommendations?"}, {"role": "assistant", "content": "How about a thriller movie? They can be quite engaging."}, {"role": "user", "content": "I'm not a big fan of thriller movies but I love sci-fi movies."}, {"role": "assistant", "content": "Got it! I'll avoid thriller recommendations and suggest sci-fi movies in the future."} ] m.add(messages, user_id="alice", metadata={"category": "movies"})
```typescript TypeScript
import { Memory } from 'mem0ai/oss';
// Ensure your AWS credentials are configured in your environment
// e.g., by setting AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, and AWS_DEFAULT_REGION
const config = {
vectorStore: {
provider: 's3_vectors',
config: {
vectorBucketName: 'my-mem0-vector-bucket',
collectionName: 'my-memories-index',
embeddingModelDims: 1536,
distanceMetric: 'cosine',
region: 'us-east-1',
},
},
};
const memory = new Memory(config);
const messages = [
{"role": "user", "content": "I'm planning to watch a movie tonight. Any recommendations?"},
{"role": "assistant", "content": "How about a thriller movie? They can be quite engaging."},
{"role": "user", "content": "I'm not a big fan of thriller movies but I love sci-fi movies."},
{"role": "assistant", "content": "Got it! I'll avoid thriller recommendations and suggest sci-fi movies in the future."}
]
await memory.add(messages, { userId: "alice", metadata: { category: "movies" } });
Here are the parameters available for configuring Amazon S3 Vectors:
| Parameter | Description | Default Value |
|---|---|---|
vector_bucket_name | The name of the S3 Vector bucket to use. It will be created if it doesn't exist. | Required |
collection_name | The name of the vector index within the bucket. | mem0 |
embedding_model_dims | Dimensions of the embedding model. Must match your embedder. | 1536 |
distance_metric | Distance metric for similarity search. Options: cosine, euclidean. | cosine |
region_name | The AWS region where the bucket and index reside. | None (uses default from AWS config) |
Your AWS identity (user or role) needs permissions to perform actions on S3 Vectors. A minimal policy would look like this:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": "s3vectors:*",
"Resource": "*"
}
]
}
For production, it is recommended to scope down the resource ARN to your specific buckets and indexes.