Agent MemoryMemory ArchitectureMulti-TenantContext

Context-Dependent Retrieval: Why Memory Leaks Across Tenants

Ryan Musser
Ryan Musser
Founder

Memory remembers more than you think

A memory is never just a fact. It is a fact in a context. The room you were in, the mood you were in, the smell of coffee, the people around you. All of it gets bound to the trace, and all of it shapes whether you can recall the trace later. The principle has the boring name encoding specificity, and it has surprisingly direct implications for how you scope an agent's memory.

The biology

Tulving's encoding specificity principle (1973) states that retrieval succeeds when cues at retrieval match cues at encoding. The most charming demonstration is Godden and Baddeley's 1975 study with scuba divers. Divers learned word lists either underwater or on dry land, then were tested in either matching or mismatched conditions. People recalled the words about 40% better when they were tested in the same environment they had learned in. Words learned underwater were recalled best underwater. Words learned on land were recalled best on land.

The effect generalizes:

  • State-dependent memory: memories formed in one internal state (mood, arousal, even drug state) are recalled better when that state is reinstated. Things you remember while sad come back more easily when you are sad.
  • Mood-congruent memory: people in a positive mood retrieve positive memories preferentially. People in a negative mood retrieve negative ones. This is part of why depression is self-reinforcing at the memory level.
  • Place cells in the hippocampus tag every memory with a spatial coordinate, contributing to the strength of context dependence.

The deeper truth is that retrieval is not a query against a context-free store. It is a query that uses every available cue, including ones the recaller is not consciously aware of.

The technology

Mem0 implements multi-level memory scoping: every operation is tagged with user_id, agent_id, session_id, and run_id. Memories created in one scope are retrieved only within that scope. This directly mirrors encoding specificity: if a memory was encoded with "user 42, session 17" as part of its context, it should only be retrieved in queries that share that context.

In multi-agent or multi-tenant setups, where multiple agents share the same userId, memories can leak between unrelated contexts. The colorful name for this is context pollution, and it is the computational equivalent of context-independent retrieval failures.

Vector database namespaces (Pinecone, Milvus) and metadata filters provide infrastructure-level scoping. Google's ADK treats "context engineering" as a first-class architectural concern with explicit scoping for multi-agent systems. Graphiti's bi-temporal model enables temporal context retrieval: you can ask "what was true at 2pm yesterday" and get the version of memory that was active at that time, not what is active now.

Where the gap is

User and session isolation is production-ready. Sophisticated state-dependent retrieval is nascent. Mood-congruent retrieval and dynamic context-aware biasing based on conversation state remain unimplemented. The brain quietly biases retrieval based on the user's emotional state. AI systems do not, and probably should.

Context engineering as a discipline is still maturing. Most systems scope by identity tags (user, session, agent), not by cognitive or semantic state. There is plenty of room to scope by topic, by recent conversation focus, by inferred user goal, and so on. Each additional scoping signal acts like an additional encoding specificity cue, and each one tightens retrieval precision.

Practical implication: every memory write should carry as many context tags as you can cheaply generate (user, session, agent, topic, time). Every retrieval should filter on the matching subset. The defaults of "search all memories" or "search this user's memories" leave a lot of precision on the table. The lesson from Godden and Baddeley's divers is that the right context dramatically improves recall, and the wrong context lets stuff leak in. Plan accordingly.

Series footer

← Previous: Metamemory · Series anchor · Next: Memory Schemas →

Context-Dependent Retrieval: Why Memory Leaks Across Tenants | TypeGraph