What is Contextual Memory Creation?
Contextual memory creation automatically manages message history for you, so you can focus on building great AI experiences instead of tracking interactions manually. Simply send new messages, and Mem0 handles the context automatically.Why Use Contextual Memory Creation?
- Simple: Send only new messages, no manual history tracking
- Efficient: Smaller payloads and faster processing
- Automatic: Context management handled by Mem0
- Reliable: No risk of missing interaction history
- Scalable: Works seamlessly as your application grows
How It Works
Basic Usage
Organization Strategies
Choose the right approach based on your application’s needs:User-Level Memories (user_id
only)
Best for: Personal preferences, profile information, long-term user data
Session-Specific Memories (user_id
+ run_id
)
Best for: Task-specific context, separate interaction threads, project-based sessions
Real-World Use Cases
Python
Best Practices
✅ Do
- Organize by context scope: Use
user_id
only for persistent data, addrun_id
for session-specific context - Keep messages focused on the current interaction
- Test with real interaction flows to ensure context works as expected
❌ Don’t
- Send duplicate messages or interaction history
- Forget to include
version="v2"
parameter - Mix contextual and non-contextual approaches in the same application
Troubleshooting
Issue | Solution |
---|---|
Context not working | Ensure you’re using version="v2" and consistent user_id |
Wrong context retrieved | Check if you need separate run_id values for different interaction topics |
Missing interaction history | Verify all messages in the interaction thread use the same user_id and run_id |
Too much irrelevant context | Use more specific run_id values to separate different interaction types |