Memory, Compression & Failure Modes
Published
Your bar: draw a clean line between memory and a knowledge base, explain how a long-running agent survives a fixed budget with summarization and sliding windows, and (this is the question interviewers keep returning to) diagnose why a context system gave a bad answer by classifying it as missing, wrong, outdated, conflicting, or excessive. 1
Three ideas, one sentence each. Each chip is one thing this lesson makes permanent:
Memory is what the system learned from us
a knowledge base is what’s true in general
long runs survive by compressing the old, keeping the recent
and most AI bugs are context bugs with five named shapes
Memory vs Knowledge Base vs Retrieval
Four words people blur into one. Memory and knowledge base are stores; retrieval is the mechanism that pulls from them; context is the assembled window. The model holds none of them — it is stateless (Lesson 1).
Who writes it, and what it holds
| Term | Who writes it | Mutability | What it holds |
|---|---|---|---|
| Memory | The system / agent, over time | Append & update | Interaction-derived facts, preferences, decisions, state of an ongoing task. |
| Knowledge base | External authors | Read-only (to the agent) | Source documents and reference truth — what’s true in general. |
| Retrieval | — (it’s a mechanism) | — | Nothing; it fetches from memory or the KB into the window (Lesson 2). |
| Context | The assembly step, per call | Rebuilt each call | The window for ONE inference (Lesson 1). |
Memory, pinned down
Is Memory is persisted state the system writes and recalls about an ongoing task or relationship — what happened, derived preferences, decisions made. Usually structured and keyed, grown by the agent across sessions.
Why it exists The model is stateless and forgets everything between calls. To act like it “remembers us,” the runtime must store facts externally and reload the relevant ones into the next window.
Like (world) Your personal recollection of a friend: their name, that they’re vegetarian, the argument you settled last month. You wrote it; you update it; you recall it when needed.
Like (code) A per-user session/profile store the service writes to and reads back — not the product catalog. Memory is the user’s row; the KB is the catalog.
Knowledge base, pinned down
Is The corpus of source documents and facts — the reference material. Authored externally, treated as read-only by the agent, the same for every user.
Why it exists The model’s training is frozen and generic. The KB supplies your domain truth — docs, policies, code — so answers are grounded in your facts, not the model’s guesses.
Like (world) The library or encyclopedia down the street. You don’t write it; you look things up in it. It’s true in general, not “true about us.”
Like (code) A read-only reference dataset or vector index of your documentation. Shared, versioned by its authors, queried — never mutated by the answering request.
The confusion that trips people up
✓ The model is stateless (Lesson 1). Memory is external storage the runtime reloads — the model only “remembers” what got retrieved into this window.
✓ KB = what’s true in general (external, read-only). Memory = what I learned from us (system-written, updatable). Different owners, different lifecycle.
📥 Memory rule: Knowledge base = what’s true in general. Memory = what I learned from us. Both reach the model only by being retrieved into context.
Memory check
- Who writes memory vs the knowledge base? → the system/agent writes memory over time; the KB is authored externally and read-only to the agent
- How does either store actually reach the model? → only via retrieval into the context window — the model has no direct access to either
- Why is "the model remembers us" wrong? → the model is stateless; the runtime reloads stored facts each call, the model itself keeps nothing
A teammate stores a user’s preferences in the knowledge base index alongside the docs. Why
is that a design smell?
Hit these points: the KB is shared, read-only reference truth; per-user preferences are mutable, user-scoped memory → mixing them pollutes everyone’s retrieval (one user’s facts can surface for another) and breaks isolation/privacy → lifecycles differ: KB is versioned by authors, memory is written constantly by the agent → keep them separate stores, retrieve from both into context, and tag provenance so you know which is which.
Context Compression for Long Runs
A long-running agent’s history outgrows any window (Lesson 1’s fixed budget). The fix isn’t a bigger window — it’s storing the full transcript externally and packing only a compressed, relevant slice each call.
The four moves, pinned down
| Technique | What it does | Loss | When |
|---|---|---|---|
| Summarization | Condense old history into a shorter summary. | Lossy | History too long to carry verbatim. |
| Distillation | Extract the salient facts/decisions/state; drop the narrative. | Lossy | You need the conclusions, not the chatter. |
| Compression | Remove redundancy/boilerplate, dedupe, prune low-value tokens. | Near-lossless | Content is repetitive or padded. |
| Sliding window | Keep the last N turns verbatim + a rolling summary of all older. | Mixed | The default for long chats/agents. |
Is Compression is the family of moves that trade fidelity for room in a fixed budget: summarize, distill, dedupe, or window so the most useful tokens survive and the rest is stored, not carried.
Why it exists The budget is fixed (Lesson 1) but a long run’s history is unbounded. Something has to give — and dropping the right tokens is cheaper and smarter than truncating blindly from the top.
Like (world) Meeting minutes: you don’t transcribe every word, you record the decisions and action items, and keep the raw recording filed in case someone needs it later.
Like (code) Log rollup / compaction: keep recent events at full detail, aggregate old ones into summaries, archive the raw stream for replay on demand.
The trade-offs to name out loud
✓ Summarizing costs extra LLM calls, and it’s lossy: a detail dropped now (an ID, a constraint) can be the one that matters three turns later.
✓ Compress the OLD; keep the RECENT and the DECISIONS/IDs verbatim. Compress as you approach the budget, not pre-emptively.
📥 Memory rule: Compression trades fidelity for room. Summarize the old, keep the recent and the decisions verbatim, store the rest and retrieve on demand.
Memory check
- Which two techniques are lossy, and what's the risk? → summarization and distillation; they can drop a detail (ID, constraint) that later turns out to matter
- What does a sliding window keep verbatim vs summarize? → last N turns verbatim + a rolling summary of everything older
- When should you compress? → as you approach the budget — not pre-emptively; keep recent + decisions/IDs verbatim
Your agent loses track of a database ID it was told 20 turns ago, after the history was
summarized. What went wrong and how do you fix it?
Hit these points: root cause is lossy summarization — the ID lived in an old turn that got condensed into prose and dropped → fix the policy, not just this case: distill structured state (IDs, decisions, constraints) into a durable key-value scratchpad that’s always kept verbatim, separate from the narrative summary → keep recent turns verbatim so freshly-mentioned facts survive → and store the full transcript so you can retrieve the original turn on demand rather than relying on the summary to be complete.
The Five Failure Modes
When an AI system gives a bad answer, the model is rarely the culprit. The context is. Most failures fit one of five named shapes; once you name the shape, the fix follows.
Symptom → cause → fix (the centerpiece)
| Failure mode | Symptom | Root cause | Fix |
|---|---|---|---|
| Missing | ”I don’t know” or hallucinated filler. | Recall gap; not in KB; chunking fragmented it. | Improve recall (hybrid), better chunking, add the source. |
| Wrong | Confident but off-topic / incorrect. | Embedding “topically-similar-but-wrong”; no rerank. | Rerank, metadata filters, hybrid + exact match. |
| Outdated | Answers from old data (old price, old API). | Index not refreshed; cached doc. | Freshness/invalidation, re-index, live fetch for volatile data. |
| Conflicting | Contradictory / arbitrary answer. | Duplicates/versions; no source-of-truth precedence. | Dedupe, rank by authority/recency, pass provenance. |
| Excessive | Slower, costlier; key fact ignored. | Dump-everything; no selection (“lost in the middle”). | Select less but right; cite position bias.4 |
Is A failure mode is a named pattern of context defect that produces a bad answer despite a capable model. The five — missing, wrong, outdated, conflicting, excessive — cover the overwhelming majority.
Why it exists The model can’t tell you it got bad input — it answers fluently from whatever’s in the window (Lesson 2’s silent failure). So failures surface as confident wrongness, and you must classify by hand.
Like (world) A doctor with a wrong, incomplete, stale, or contradictory chart — same skill, bad answer. Or a desk so buried in paper the one key memo gets overlooked (excessive).
Like (code) Garbage-in / garbage-out, but silent: no exception, no 500. Like a query returning wrong rows that the app renders confidently — you only catch it by auditing the inputs.
✓ Excessive context is its own failure mode — it’s slower, costlier, and the key fact gets “lost in the middle” of a long window.4
✓ Classify it first. Most wrong answers are a context defect — fixing retrieval is cheaper and fixes the root cause; a bigger model just reasons better over bad input.
📥 Memory rule: Most AI bugs are context bugs. Classify it — missing / wrong / outdated / conflicting / excessive — then the fix is obvious.
Memory check
- Which mode causes a confident but off-topic answer, and what fixes it? → wrong context (topically-similar-but-wrong); fix with rerank, filters, hybrid + exact match
- Two sources disagree in-window — name it and the fix. → conflicting context; dedupe, rank by authority/recency, pass provenance / source-of-truth precedence
- Why is "dump everything" a failure mode, not a safe default? → excessive context: slower, costlier, and the key fact gets lost in the middle (position bias)
Your assistant quotes last quarter’s pricing. Walk through diagnosing it with the
failure-mode framework.
Hit these points: classify the symptom — it answered from old data, so this is outdated context, not a model defect → verify by inspecting what was retrieved: a stale index entry or cached doc with last quarter’s price → root cause is freshness — the index wasn’t re-indexed after the price changed → fixes: invalidate/re-index on source change, add a freshness/TTL signal, and for volatile fields like price prefer a live structured fetch over an embedded snapshot → prevention: monitor index staleness and treat volatile data differently from static docs.
Two retrieved docs give different answers to the same question. Why does this happen and
how do you make the system deterministic?
Hit these points: this is conflicting context — duplicates or multiple versions both got retrieved, with no precedence → the model picks arbitrarily, so the same query can flip answers → fixes: dedupe near-identical chunks, establish a source-of-truth ranking (authority + recency), and drop or down-rank the loser → pass provenance into the window so the model (and your logs) can see which source won → prevention: version your KB and avoid indexing the same fact from multiple uncontrolled sources.
Retrieval practice — test the three modules
Q1. The clearest line between memory and a knowledge base is…
Q2. Both memory and the knowledge base reach the model by…
Q3. A sliding window for a long-running agent keeps…
Q4. The model answers confidently but completely off-topic. The most likely failure mode is…
Q5. Packing far more context than needed mainly hurts because…
Interview — pick your bar
Answer out loud in ~60s, then reveal. Core = recall · Senior = trade-offs & failure modes · Staff = synthesis under ambiguity · System Design = open design round (a different axis, not a harder level).
Distinguish memory, knowledge base, retrieval, and context. Use a human analogy.
Who writes memory vs the knowledge base, and how does each one actually reach the model?
Name the four compression moves and which ones are lossy.
List the five failure modes with one symptom each.
A teammate stores a user's preferences in the knowledge base index alongside the docs. Why is that a design smell?
"Summarize aggressively to save money." Where does that reasoning break down?
Your agent loses track of a database ID it was told 20 turns ago, after the history was summarized. Diagnose and fix.
An assistant quotes last quarter's pricing. Walk the failure-mode framework to the fix.
Design the memory + context strategy for an agent that runs for hundreds of turns on a fixed budget.
Two retrieved docs answer the same question differently and the answer flips between runs. Classify it and make the system deterministic.
Production incident: the model is fluent and confident but the answer is just wrong. Walk through classifying it before touching the model.
- Clarify the run shape — multi-session over days vs one long run for hours, number of users, latency/cost budget, what "remembering" must mean.
- Separate the stores — user-scoped memory (writable) vs shared read-only KB; decide what's worth persisting vs derivable.
- Define the window recipe — system prompt + rolling summary + last N verbatim + retrieved facts, and the fixed token budget it must fit.
- Compression policy — what's summarized vs kept verbatim (decisions/IDs/constraints), and when compression triggers (near budget, not pre-emptively).
- Retrieval & freshness — how memory and KB get queried per call, plus invalidation/TTL for volatile facts.
- Failure-mode guardrails — provenance, dedupe/precedence, recall monitoring, and treating retrieved text as data.
- Cost, eval & observability — the extra LLM calls compression adds, how you'd test recall, and what you log to diagnose the five modes.
Design the memory and compression strategy for a multi-session customer-support agent that talks to the same users for months.
Design the context strategy for an autonomous agent that runs for hours on a single task (e.g. a long research or migration job).
These notes reflect my current understanding and are updated as I learn, build, and discover better explanations.