docs/platform/features/memory-export.mdx
The Memory Export feature allows you to create structured exports of memories using customizable Pydantic schemas. This process enables you to transform your stored memories into specific data formats that match your needs. You can apply various filters to narrow down which memories to export and define exactly how the data should be structured.
To create a memory export, you'll need to:
Here's an example schema for extracting professional profile information:
{
"$defs": {
"EducationLevel": {
"enum": ["high_school", "bachelors", "masters"],
"title": "EducationLevel",
"type": "string"
},
"EmploymentStatus": {
"enum": ["full_time", "part_time", "student"],
"title": "EmploymentStatus",
"type": "string"
}
},
"properties": {
"full_name": {
"anyOf": [
{
"maxLength": 100,
"minLength": 2,
"type": "string"
},
{
"type": "null"
}
],
"default": null,
"description": "The professional's full name",
"title": "Full Name"
},
"current_role": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"default": null,
"description": "Current job title or role",
"title": "Current Role"
}
},
"title": "ProfessionalProfile",
"type": "object"
}
You can optionally provide additional instructions to guide how memories are processed and structured during export using the export_instructions parameter.
# Basic export request
filters = {"user_id": "alice"}
response = client.create_memory_export(
schema=json_schema,
filters=filters
)
# Export with custom instructions and additional filters
export_instructions = """
1. Create a comprehensive profile with detailed information in each category
2. Only mark fields as "None" when absolutely no relevant information exists
3. Base all information directly on the user's memories
4. When contradictions exist, prioritize the most recent information
5. Clearly distinguish between factual statements and inferences
"""
filters = {
"AND": [
{"user_id": "alex"},
{"created_at": {"gte": "2024-01-01"}}
]
}
response = client.create_memory_export(
schema=json_schema,
filters=filters,
export_instructions=export_instructions # Optional
)
print(response)
// Basic Export request
const filters = {"user_id": "alice"};
const response = await client.createMemoryExport({
schema: json_schema,
filters: filters
});
// Export with custom instructions and additional filters
const export_instructions = `
1. Create a comprehensive profile with detailed information in each category
2. Only mark fields as "None" when absolutely no relevant information exists
3. Base all information directly on the user's memories
4. When contradictions exist, prioritize the most recent information
5. Clearly distinguish between factual statements and inferences
`;
// For create operation, using only user_id filter as requested
const filters = {
"AND": [
{"user_id": "alex"},
{"created_at": {"gte": "2024-01-01"}}
]
}
const responseWithInstructions = await client.createMemoryExport({
schema: json_schema,
filters: filters,
exportInstructions: export_instructions
});
console.log(responseWithInstructions);
curl -X POST "https://api.mem0.ai/v1/memories/export/" \
-H "Authorization: Token your-api-key" \
-H "Content-Type: application/json" \
-d '{
"schema": {json_schema},
"filters": {"user_id": "alice"},
"export_instructions": "1. Create a comprehensive profile with detailed information\n2. Only mark fields as \"None\" when absolutely no relevant information exists"
}'
{
"message": "Memory export request received. The export will be ready in a few seconds.",
"id": "550e8400-e29b-41d4-a716-446655440000"
}
Once the export job is complete, you can retrieve the structured data in two ways:
# Retrieve using export ID
response = client.get_memory_export(memory_export_id="550e8400-e29b-41d4-a716-446655440000")
print(response)
// Retrieve using export ID
const memoryExportId = "550e8400-e29b-41d4-a716-446655440000";
const response = await client.getMemoryExport({
memoryExportId: memoryExportId
});
console.log(response);
{
"full_name": "John Doe",
"current_role": "Senior Software Engineer",
"years_experience": 8,
"employment_status": "full_time",
"education_level": "masters",
"skills": ["Python", "AWS", "Machine Learning"]
}
# Retrieve using filters
filters = {
"AND": [
{"created_at": {"gte": "2024-07-10", "lte": "2024-07-20"}},
{"user_id": "alex"}
]
}
response = client.get_memory_export(filters=filters)
print(response)
// Retrieve using filters
const filters = {
"AND": [
{"created_at": {"gte": "2024-07-10", "lte": "2024-07-20"}},
{"user_id": "alex"}
]
}
const response = await client.getMemoryExport({
filters: filters
});
console.log(response);
{
"full_name": "John Doe",
"current_role": "Senior Software Engineer",
"years_experience": 8,
"employment_status": "full_time",
"education_level": "masters",
"skills": ["Python", "AWS", "Machine Learning"]
}
You can apply various filters to customize which memories are included in the export:
user_id: Filter memories by specific useragent_id: Filter memories by specific agentrun_id: Filter memories by specific runsession_id: Filter memories by specific sessioncreated_at: Filter memories by dateIf you have any questions, please feel free to reach out to us using one of the following methods:
<Snippet file="get-help.mdx" />