Entity IDs vs. graph entities. This page covers the
user_id / agent_id / app_id / run_id identifiers used to scope memories. These are different from the graph entities (the people, places, and concepts surfaced in Graph Memory).You’ll use this when…
- You run assistants for multiple customers who each need private memory spaces
- Different agents (like a planner and a critic) need separate context for the same user
- Sessions should expire on their own schedule, making debugging and data removal more precise
Configure access
client.project.get() to verify your connection. It should return your project details including org_id and project_id. If you get a 401 error, generate a new API key in the Mem0 dashboard.
Feature anatomy
- Writes (
client.add) accept any combination of these fields.app_idandrun_idare stored on every memory the call produces.user_idandagent_idbehave differently on the default extraction path: each extracted fact is attributed to whoever stated it, so a record carriesuser_idoragent_id, not both. Absent fields default tonull. - Reads (
client.search,client.get_all, exports) accept the same identifiers inside thefiltersJSON object. Deletes (client.delete_all) scope via query parameters instead; the SDK builds these for you when you passuser_id=...,run_id=..., and so on. - Unmentioned entities are not constrained: Passing only
{"user_id": "alice"}matches onuser_idalone. It does not requireagent_id,app_id, orrun_idto benull, so records that also have those fields set are still returned.
Choose the right identifier
For more detailed examples, see the Partition Memories by Entity cookbook.
Configure it
The example below adds memories with entity tags:POST /v3/memories/add/ with the same identifiers in the JSON body. See the Add Memories API reference for REST details.
See it in action
1. Store scoped memoriesWildcards (
"*") include only non-null values. Use them when you want “any agent” or “any user” without limiting results to null-only records.A successful delete returns
{"message": "Memories deleted successfully!"}. Run the previous get_all call again to confirm the session memories were removed.Verify the feature is working
- Run
client.searchwith your filters and confirm only expected memories appear. Mismatched identifiers usually mean a typo in your scoping. - Check the Mem0 dashboard filter pills. User, agent, app, and run should all show populated values for your memory entry.
- Call
client.delete_allwith a uniquerun_idand confirm other sessions remain intact (the count inget_allshould only drop for that run).
Best practices
- Use consistent identifier formats (like
team-alphaorapp-ios-retail) so you can query or delete entire groups later - When debugging, print your filters before each call to verify wildcards (
"*"), lists, and run IDs are spelled correctly - Combine entity filters with metadata filters (categories, created_at) for precise exports or audits
- Use
run_idfor temporary sessions like support tickets or experiments, then schedule cleanup jobs to delete them