Skip to main content

Mem0

Memory management for AI agents with semantic search.

Provider: Mem0
Authentication: API Key required
Category: AI & Memory
Credit Cost: 1 credit per operation

Overview

Mem0 tools provide persistent memory storage for AI agents. Store user preferences, conversation context, and learned information that persists across sessions. Features semantic search for intelligent memory retrieval.

Key Features

  • Persistent Memory: Store information across sessions
  • Semantic Search: Find memories by meaning, not just keywords
  • User Scoping: Memories tied to specific users
  • Agent/Run Scoping: Organize memories by agent or session
  • Metadata Support: Attach custom data to memories

Setup

Get Mem0 API Key

  1. Go to Mem0 Dashboard
  2. Navigate to SettingsAPI Keys
  3. Click Create API Key
  4. Copy the generated key

Add to Reeva

  1. Dashboard → AccountsAdd Account
  2. Select Mem0
  3. Paste your API key
  4. Click Save

Available Tools

Add Memories

Store new memories from messages or text.

Tool ID: mem0_add_memories
Credit Cost: 1 credit

Parameters:

  • messages (array or string, required): Either:
    • Array of message objects with role and content
    • Raw text string to store as memory
  • mem0_user_id (string, required): User identifier for scoping memories
  • agent_id (string, optional): Associate with specific agent
  • run_id (string, optional): Associate with specific run/session
  • metadata (object, optional): Additional metadata to attach

Response:

{
"result": {
"results": [
{
"id": "mem_abc123",
"memory": "User prefers dark mode and compact layouts",
"event": "ADD"
}
]
},
"message": "Memories added successfully",
"user_id": "user_123"
}

Example Usage:

# Python - Add from conversation
response = client.call_tool(
name="mem0_add_memories",
arguments={
"messages": [
{"role": "user", "content": "I prefer dark mode and compact layouts"},
{"role": "assistant", "content": "I'll remember your preference for dark mode and compact layouts"}
],
"mem0_user_id": "user_123"
}
)

for memory in response["result"]["results"]:
print(f"Added: {memory['memory']} (ID: {memory['id']})")
// TypeScript - Add with metadata
const response = await client.callTool({
name: "mem0_add_memories",
arguments: {
messages: "User's favorite programming language is Python",
mem0_user_id: "user_456",
agent_id: "coding_assistant",
metadata: {
source: "onboarding",
confidence: 0.95
}
}
});
# cURL - Add memory
curl -X POST https://api.joinreeva.com/mcp/server_YOUR_ID \
-H "Authorization: Bearer mcpk_your_key" \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"name": "mem0_add_memories",
"arguments": {
"messages": "User is a software engineer at TechCorp",
"mem0_user_id": "user_789"
}
},
"id": 1
}'

Use Cases:

  • Store user preferences
  • Remember conversation context
  • Save learned facts about users
  • Track user history

Get Memory

Retrieve a specific memory by ID.

Tool ID: mem0_get_memory
Credit Cost: 1 credit

Parameters:

  • memory_id (string, optional): Specific memory ID to retrieve
  • mem0_user_id (string, required): User identifier
  • agent_id (string, optional): Filter by agent ID
  • run_id (string, optional): Filter by run ID
  • filters (object, optional): Advanced filter with AND/OR/NOT operators

Response:

{
"memories": [
{
"id": "mem_abc123",
"memory": "User prefers dark mode",
"created_at": "2025-11-22T10:30:00Z",
"metadata": {}
}
],
"count": 1,
"action": "get_all"
}

Example Usage:

# Python - Get specific memory
response = client.call_tool(
name="mem0_get_memory",
arguments={
"memory_id": "mem_abc123",
"mem0_user_id": "user_123"
}
)

print(f"Memory: {response['memories'][0]['memory']}")
// TypeScript - Get with filters
const response = await client.callTool({
name: "mem0_get_memory",
arguments: {
mem0_user_id: "user_123",
agent_id: "assistant",
filters: {
created_at: {gte: "2025-01-01"}
}
}
});

Use Cases:

  • Retrieve specific memory by ID
  • Get memories for a user
  • Filter by agent or session

Get Memories

List all memories for a user with optional filtering.

Tool ID: mem0_get_memories
Credit Cost: 1 credit

Parameters:

  • mem0_user_id (string, required): User identifier
  • agent_id (string, optional): Filter by agent ID
  • run_id (string, optional): Filter by run ID
  • filters (object, optional): Advanced filter object

Response:

{
"memories": [
{
"id": "mem_abc123",
"memory": "User prefers dark mode",
"created_at": "2025-11-22T10:30:00Z"
},
{
"id": "mem_def456",
"memory": "User is a Python developer",
"created_at": "2025-11-22T11:00:00Z"
}
],
"count": 2,
"user_id": "user_123"
}

Example Usage:

# Python - Get all user memories
response = client.call_tool(
name="mem0_get_memories",
arguments={
"mem0_user_id": "user_123"
}
)

print(f"Found {response['count']} memories:")
for memory in response["memories"]:
print(f" - {memory['memory']}")
// TypeScript - Get memories with date filter
const response = await client.callTool({
name: "mem0_get_memories",
arguments: {
mem0_user_id: "user_123",
filters: {
AND: [
{created_at: {gte: "2025-01-01"}},
{created_at: {lte: "2025-12-31"}}
]
}
}
});

Filter Operators:

OperatorDescriptionExample
gteGreater than or equal{"created_at": {"gte": "2025-01-01"}}
lteLess than or equal{"created_at": {"lte": "2025-12-31"}}
inIn array{"status": {"in": ["active", "pending"]}}
icontainsCase-insensitive contains{"memory": {"icontains": "python"}}
ANDLogical AND{"AND": [{...}, {...}]}
ORLogical OR{"OR": [{...}, {...}]}
NOTLogical NOT{"NOT": {...}}

Use Cases:

  • List all memories for context
  • Filter memories by date range
  • Get memories for specific agent

Search Memories

Semantically search memories using natural language.

Tool ID: mem0_search_memories
Credit Cost: 1 credit

Parameters:

  • query (string, required): Natural language search query
  • mem0_user_id (string, required): User identifier
  • agent_id (string, optional): Filter by agent ID
  • run_id (string, optional): Filter by run ID
  • limit (integer, optional): Maximum results to return
    • Default: 10
    • Range: 1-100

Response:

{
"results": [
{
"id": "mem_abc123",
"memory": "User prefers dark mode and minimalist design",
"score": 0.92,
"created_at": "2025-11-22T10:30:00Z"
},
{
"id": "mem_def456",
"memory": "User likes clean interfaces",
"score": 0.78,
"created_at": "2025-11-22T11:00:00Z"
}
],
"count": 2,
"query": "What are the user's UI preferences?",
"limit": 10
}

Example Usage:

# Python - Semantic search
response = client.call_tool(
name="mem0_search_memories",
arguments={
"query": "What programming languages does the user know?",
"mem0_user_id": "user_123",
"limit": 5
}
)

print("Relevant memories:")
for result in response["results"]:
print(f" [{result['score']:.2f}] {result['memory']}")
// TypeScript - Search with agent filter
const response = await client.callTool({
name: "mem0_search_memories",
arguments: {
query: "user's preferences for notifications",
mem0_user_id: "user_123",
agent_id: "settings_agent",
limit: 10
}
});
# cURL - Search memories
curl -X POST https://api.joinreeva.com/mcp/server_YOUR_ID \
-H "Authorization: Bearer mcpk_your_key" \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"name": "mem0_search_memories",
"arguments": {
"query": "What does the user do for work?",
"mem0_user_id": "user_123"
}
},
"id": 1
}'

Use Cases:

  • Find relevant context for responses
  • Retrieve specific information by meaning
  • Power personalized recommendations
  • Context-aware AI responses

Update Memory

Modify the content of an existing memory.

Tool ID: mem0_update_memory
Credit Cost: 1 credit

Parameters:

  • memory_id (string, required): Memory ID to update
  • text (string, required): New text content for the memory

Response:

{
"memory_id": "mem_abc123",
"message": "Memory updated successfully",
"result": {
"id": "mem_abc123",
"memory": "User prefers dark mode and compact layout",
"updated_at": "2025-11-22T15:45:00Z"
}
}

Example Usage:

# Python - Update memory
response = client.call_tool(
name="mem0_update_memory",
arguments={
"memory_id": "mem_abc123",
"text": "User prefers dark mode, compact layout, and high contrast"
}
)

print(f"Updated: {response['result']['memory']}")
// TypeScript - Update memory text
const response = await client.callTool({
name: "mem0_update_memory",
arguments: {
memory_id: "mem_abc123",
text: "User's favorite language changed from Python to Rust"
}
});

Use Cases:

  • Correct inaccurate memories
  • Update changed preferences
  • Refine memory content
  • Consolidate related memories

Delete Memory

Permanently remove a memory.

Tool ID: mem0_delete_memory
Credit Cost: 1 credit

Parameters:

  • memory_id (string, required): Memory ID to delete

Response:

{
"memory_id": "mem_abc123",
"message": "Memory deleted successfully"
}

Example Usage:

# Python - Delete memory
response = client.call_tool(
name="mem0_delete_memory",
arguments={
"memory_id": "mem_abc123"
}
)

print(response["message"])
// TypeScript - Delete memory
const response = await client.callTool({
name: "mem0_delete_memory",
arguments: {
memory_id: "mem_obsolete"
}
});

Use Cases:

  • Remove outdated information
  • Honor user data deletion requests
  • Clean up incorrect memories
  • Privacy compliance

Warning: Deletion is permanent and cannot be undone.

Common Patterns

Context-Aware Responses

# Retrieve relevant memories before responding
def get_contextual_response(user_id, user_message):
# Search for relevant memories
memories = client.call_tool(
name="mem0_search_memories",
arguments={
"query": user_message,
"mem0_user_id": user_id,
"limit": 5
}
)

# Build context from memories
context = "User context:\n"
for mem in memories["results"]:
context += f"- {mem['memory']}\n"

# Use context in AI response
response = generate_response(user_message, context)

# Store new information learned
client.call_tool(
name="mem0_add_memories",
arguments={
"messages": [
{"role": "user", "content": user_message},
{"role": "assistant", "content": response}
],
"mem0_user_id": user_id
}
)

return response

User Preference Management

# Manage user preferences
class PreferenceManager:
def __init__(self, user_id, agent_id="preferences"):
self.user_id = user_id
self.agent_id = agent_id

def get_preferences(self):
return client.call_tool(
name="mem0_get_memories",
arguments={
"mem0_user_id": self.user_id,
"agent_id": self.agent_id
}
)

def set_preference(self, preference_text):
return client.call_tool(
name="mem0_add_memories",
arguments={
"messages": preference_text,
"mem0_user_id": self.user_id,
"agent_id": self.agent_id,
"metadata": {"type": "preference"}
}
)

def find_preference(self, query):
return client.call_tool(
name="mem0_search_memories",
arguments={
"query": query,
"mem0_user_id": self.user_id,
"agent_id": self.agent_id,
"limit": 3
}
)

Conversation Memory

# Store conversation history for context
def process_conversation(user_id, conversation):
# Store the conversation
client.call_tool(
name="mem0_add_memories",
arguments={
"messages": conversation,
"mem0_user_id": user_id,
"run_id": generate_session_id(),
"metadata": {
"type": "conversation",
"timestamp": datetime.now().isoformat()
}
}
)

# Later: recall relevant context
def recall_context(user_id, topic):
return client.call_tool(
name="mem0_search_memories",
arguments={
"query": f"Previous conversations about {topic}",
"mem0_user_id": user_id,
"limit": 10
}
)

Memory Cleanup

# Clean up old or irrelevant memories
def cleanup_memories(user_id, before_date):
# Get old memories
old_memories = client.call_tool(
name="mem0_get_memories",
arguments={
"mem0_user_id": user_id,
"filters": {
"created_at": {"lte": before_date}
}
}
)

# Delete each old memory
deleted = []
for memory in old_memories["memories"]:
client.call_tool(
name="mem0_delete_memory",
arguments={"memory_id": memory["id"]}
)
deleted.append(memory["id"])

return deleted

Best Practices

User Scoping

  • Always provide mem0_user_id to scope memories
  • Use consistent user IDs across sessions
  • Consider agent-level scoping for different contexts

Memory Quality

  • Store concise, factual information
  • Avoid storing sensitive data
  • Use metadata for categorization
  • Update or delete outdated memories

Search Optimization

  • Use natural language queries
  • Set appropriate limits
  • Combine with filters for precision
  • Handle low-score results carefully

Performance

  • Search is faster than listing all memories
  • Use filters to reduce result sets
  • Cache frequently accessed memories
  • Batch memory additions when possible

Troubleshooting

"Memory not found" Error

Cause: Invalid memory ID

Solutions:

  • Verify memory ID is correct
  • Check memory wasn't already deleted
  • Ensure you have access to the memory

Empty Search Results

Cause: No matching memories or query mismatch

Solutions:

  • Try broader search queries
  • Check that memories exist for the user
  • Verify user ID is correct
  • Adjust search limit

Low Relevance Scores

Cause: Query doesn't match memory content well

Solutions:

  • Rephrase the search query
  • Use more specific language
  • Check if the memory content is accurate
  • Consider updating memory text

See Also