|
| 1 | +--- |
| 2 | +title: AWS Bedrock |
| 3 | +--- |
| 4 | + |
| 5 | +<Snippet file="security-compliance.mdx" /> |
| 6 | + |
| 7 | +This integration demonstrates how to use **Mem0** with **AWS Bedrock** and **Amazon OpenSearch Service (AOSS)** to enable persistent, semantic memory in intelligent agents. |
| 8 | + |
| 9 | +## Overview |
| 10 | + |
| 11 | +In this guide, you'll: |
| 12 | + |
| 13 | +1. Configure AWS credentials to enable Bedrock and OpenSearch access |
| 14 | +2. Set up the Mem0 SDK to use Bedrock for embeddings and LLM |
| 15 | +3. Store and retrieve memories using OpenSearch as a vector store |
| 16 | +4. Build memory-aware applications with scalable cloud infrastructure |
| 17 | + |
| 18 | +## Prerequisites |
| 19 | + |
| 20 | +- AWS account with access to: |
| 21 | + - Bedrock foundation models (e.g., Titan, Claude) |
| 22 | + - OpenSearch Service with a configured domain |
| 23 | +- Python 3.8+ |
| 24 | +- Valid AWS credentials (via environment or IAM role) |
| 25 | + |
| 26 | +## Setup and Installation |
| 27 | + |
| 28 | +Install required packages: |
| 29 | + |
| 30 | +```bash |
| 31 | +pip install mem0ai boto3 opensearch-py |
| 32 | +``` |
| 33 | + |
| 34 | +Set environment variables: |
| 35 | + |
| 36 | +Be sure to configure your AWS credentials using environment variables, IAM roles, or the AWS CLI. |
| 37 | + |
| 38 | +```python |
| 39 | +import os |
| 40 | + |
| 41 | +os.environ['AWS_REGION'] = 'us-west-2' |
| 42 | +os.environ['AWS_ACCESS_KEY_ID'] = 'AKIA...' |
| 43 | +os.environ['AWS_SECRET_ACCESS_KEY'] = 'AS...' |
| 44 | +``` |
| 45 | + |
| 46 | +## Initialize Mem0 Integration |
| 47 | + |
| 48 | +Import necessary modules and configure Mem0: |
| 49 | + |
| 50 | +```python |
| 51 | +import boto3 |
| 52 | +from opensearchpy import OpenSearch, RequestsHttpConnection, AWSV4SignerAuth |
| 53 | +from mem0.memory.main import Memory |
| 54 | + |
| 55 | +region = 'us-west-2' |
| 56 | +service = 'aoss' |
| 57 | +credentials = boto3.Session().get_credentials() |
| 58 | +auth = AWSV4SignerAuth(credentials, region, service) |
| 59 | + |
| 60 | +config = { |
| 61 | + "embedder": { |
| 62 | + "provider": "aws_bedrock", |
| 63 | + "config": { |
| 64 | + "model": "amazon.titan-embed-text-v2:0" |
| 65 | + } |
| 66 | + }, |
| 67 | + "llm": { |
| 68 | + "provider": "aws_bedrock", |
| 69 | + "config": { |
| 70 | + "model": "anthropic.claude-3-5-haiku-20241022-v1:0", |
| 71 | + "temperature": 0.1, |
| 72 | + "max_tokens": 2000 |
| 73 | + } |
| 74 | + }, |
| 75 | + "vector_store": { |
| 76 | + "provider": "opensearch", |
| 77 | + "config": { |
| 78 | + "collection_name": "mem0", |
| 79 | + "host": "your-opensearch-domain.us-west-2.es.amazonaws.com", |
| 80 | + "port": 443, |
| 81 | + "http_auth": auth, |
| 82 | + "embedding_model_dims": 1024, |
| 83 | + "connection_class": RequestsHttpConnection, |
| 84 | + "pool_maxsize": 20, |
| 85 | + "use_ssl": True, |
| 86 | + "verify_certs": True |
| 87 | + } |
| 88 | + } |
| 89 | +} |
| 90 | + |
| 91 | +# Initialize memory system |
| 92 | +m = Memory.from_config(config) |
| 93 | +``` |
| 94 | + |
| 95 | +## Memory Operations |
| 96 | + |
| 97 | +Use Mem0 with your Bedrock-powered LLM and OpenSearch storage backend: |
| 98 | + |
| 99 | +```python |
| 100 | +# Store conversational context |
| 101 | +messages = [ |
| 102 | + {"role": "user", "content": "I'm planning to watch a movie tonight. Any recommendations?"}, |
| 103 | + {"role": "assistant", "content": "How about a thriller?"}, |
| 104 | + {"role": "user", "content": "I prefer sci-fi."}, |
| 105 | + {"role": "assistant", "content": "Noted! I'll suggest sci-fi movies next time."} |
| 106 | +] |
| 107 | + |
| 108 | +m.add(messages, user_id="alice", metadata={"category": "movie_recommendations"}) |
| 109 | + |
| 110 | +# Search for memory |
| 111 | +relevant = m.search("What kind of movies does Alice like?", user_id="alice") |
| 112 | + |
| 113 | +# Retrieve all user memories |
| 114 | +all_memories = m.get_all(user_id="alice") |
| 115 | +``` |
| 116 | + |
| 117 | +## Key Features |
| 118 | + |
| 119 | +1. **Serverless Memory Embeddings**: Use Titan or other Bedrock models for fast, cloud-native embeddings |
| 120 | +2. **Scalable Vector Search**: Store and retrieve vectorized memories via OpenSearch |
| 121 | +3. **Seamless AWS Auth**: Uses AWS IAM or environment variables to securely authenticate |
| 122 | +4. **User-specific Memory Spaces**: Memories are isolated per user ID |
| 123 | +5. **Persistent Memory Context**: Maintain and recall history across sessions |
| 124 | + |
| 125 | +## Help |
| 126 | + |
| 127 | +- [AWS Bedrock Documentation](https://docs.aws.amazon.com/bedrock/) |
| 128 | +- [Amazon OpenSearch Service Docs](https://docs.aws.amazon.com/opensearch-service/) |
| 129 | +- [Mem0 Platform](https://app.mem0.ai) |
| 130 | + |
| 131 | +<Snippet file="get-help.mdx" /> |
| 132 | + |
0 commit comments