ExamplescriptbeginnerRunnablememory-lab
Mem0 Oss Quickstart
Runnable example (beginner) for script using mem0, mem0ai.
Key Facts
- Level
- beginner
- Runtime
- Python • OpenAI API
- Pattern
- Memory-aware assistance with legible context
- Interaction
- Live sandbox • Script
- Updated
- 14 March 2026
Navigate this example
Library
Browse examplesReopen the wider library to compare adjacent patterns and linked learning paths.Interaction
Run sandbox nowTry the interaction directly in this example’s guided sandbox surface.Source
Open full sourceRead the real implementation, highlighted checkpoints, and runtime requirements.MCP
Call via MCPUse the same resource inside agents, deterministic exports, and MCP setup flows.
Linked principles
02-mem0-oss-quickstart.py
python
from mem0 import Memory
from dotenv import load_dotenv
load_dotenv(".env")
m = Memory() # Requires OpenAI API key
# --------------------------------------------------------------
# Message sequence
# --------------------------------------------------------------
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="default_user", metadata={"category": "movie_recommendations"}
)
# --------------------------------------------------------------
# Get all memories
# --------------------------------------------------------------
all_memories = m.get_all(user_id="default_user")
# --------------------------------------------------------------
# Search for related memories
# --------------------------------------------------------------
related_memories = m.search(query="What do you know about me?", user_id="default_user")
print(related_memories)
Related principles
- P2visibilityEnsure that background work remains perceptibleWhen the system is operating asynchronously or outside the user’s immediate focus, it should provide persistent and proportionate signals that work is continuing.Open principle →
- P3visibilityAlign feedback with the user’s level of attentionThe system should calibrate the depth and frequency of feedback according to whether the user is actively engaged, passively monitoring, or temporarily absent.Open principle →
- P7trustEstablish trust through inspectabilityUsers should be able to examine how a result was produced when confidence, accountability, or decision quality is important.Open principle →