This example demonstrates how to configure and use the mem0ai SDK with AWS Bedrock and OpenSearch Service (AOSS) for persistent memory capabilities in Python.
import os# Set these in your environment or notebookos.environ['AWS_REGION'] = 'us-west-2'os.environ['AWS_ACCESS_KEY_ID'] = 'AK00000000000000000'os.environ['AWS_SECRET_ACCESS_KEY'] = 'AS00000000000000000'# Confirm they are setprint(os.environ['AWS_REGION'])print(os.environ['AWS_ACCESS_KEY_ID'])print(os.environ['AWS_SECRET_ACCESS_KEY'])
messages = [ {"role": "user", "content": "I'm planning to watch a movie tonight. Any recommendations?"}, {"role": "assistant", "content": "How about a thriller movies? 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."}]# Store inferred memories (default behavior)result = m.add(messages, user_id="alice", metadata={"category": "movie_recommendations"})
With Mem0 and AWS services like Bedrock and OpenSearch, you can build intelligent AI companions that remember, adapt, and personalize their responses over time. This makes them ideal for long-term assistants, tutors, or support bots with persistent memory and natural conversation abilities.