Retrieve, review, and migrate user memories with structured exports.
Mem0 is a dynamic memory store that gives you full control over your data. Along with storing memories, it gives you the ability to retrieve, export, and migrate your data whenever you need.This cookbook shows you how to retrieve and export your data for inspection, migration, or compliance.
from mem0 import MemoryClientclient = MemoryClient(api_key="your-api-key")
Your API key needs export permissions to download memory data. Check your project settings on the dashboard if export operations fail with authentication errors.
Let’s add some sample memories to work with:
Copy
Ask AI
# Dev's work historyclient.add( "Dev works at TechCorp as a senior engineer", user_id="dev", metadata={"type": "professional"})# Arjun's preferencesclient.add( "Arjun prefers morning meetings and async communication", user_id="arjun", metadata={"type": "preference"})# Carl's project notesclient.add( "Carl is leading the API redesign project, targeting Q2 launch", user_id="carl", metadata={"type": "project"})
Total memories: 1First memory: Dev works at TechCorp as a senior engineer
Expected output:get_all() retrieved Dev’s complete memory record. This method returns everything matching your filters—no semantic search, no ranking, just raw retrieval. Perfect for exports and audits.
When you need semantic search instead of retrieving everything, use search():
Copy
Ask AI
results = client.search( query="What does Dev do for work?", filters={"user_id": "dev"}, top_k=5)for result in results['results']: print(f"{result['memory']} (score: {result['score']:.2f})")
Output:
Copy
Ask AI
Dev works at TechCorp as a senior engineer (score: 0.89)
Search works across all memory fields and ranks by relevance. Use it when you have a specific question, use get_all() when you need everything.
Export initiated: Status is “processing”. Large exports may take a few seconds. Poll with get_memory_export() until status changes to “completed” before downloading data.
Guide how Mem0 resolves conflicts or formats the export:
Copy
Ask AI
export_with_instructions = client.create_memory_export( schema=professional_profile_schema, filters={"user_id": "arjun"}, export_instructions="""1. Use the most recent information if there are conflicts2. Only include confirmed facts, not speculation3. Return null for missing fields rather than guessing""")
Always check export status before downloading. Call get_memory_export() in a loop with a short delay until status == "completed". Attempting to download while still processing returns incomplete data.
You can also export memories directly from the Mem0 platform UI:
Navigate to Memory Exports in your project dashboard
Click Create Export
Select your filters and schema
Download the completed export as JSON
This is useful for one-off exports or manual data reviews.
Exported data expires after 7 days. Download and store exports locally if you need long-term archives. After expiration, you’ll need to recreate the export job.
Use get_all() for bulk retrieval, search() for specific questions, and create_memory_export() for structured data exports with custom schemas. Remember exports expire after 7 days—download them locally for long-term archives.
Expire Short-Term Data
Keep exports lean by clearing session context before you archive it.
Control Memory Ingestion
Ensure only verified insights make it into your export pipeline.