skip to content
Sandesh Bhandari

understanding ai memory

/ 20 min read

Table of Contents

Hi. Let me explain how AI memory actually works, because most people use language models every day without thinking about what is happening underneath, and once we understand it, the limits of these tools start to make sense as direct consequences of how the systems are designed.

A language model can write a legal brief, debug a distributed system, explain a black hole, or write a sonnet in the style of Keats. Ask it what we discussed three days ago, and it has no record of the conversation. Not because the information was sensitive, not because someone deleted it, but because the system is architecturally incapable of recalling it.

This is not a bug that will be fixed in a future model release. It is how these systems are built. The context window, the token buffer that holds everything happening in our current conversation, is cleared completely at the end of every session, with no continuity and no accumulation carrying over to the next time we open the application.

The gap between how we remember and how a language model “remembers” is not a matter of degree. It is not that humans can hold more information for longer, but that human memory is a completely different kind of system: one with multiple specialized stores, sleep-based consolidation, associative retrieval, graceful forgetting, and the ability to update continuously without erasing everything previously known.

how human memory actually works

Human memory is not one thing, but at least four distinct systems, each with its own capacity, duration, and decay function.

Working memory is the mental scratchpad that holds roughly seven items at a time and decays within 15 to 30 seconds without active rehearsal. This is the system that lets us replay the last few sentences of a conversation in our head five minutes after it happened, and the trace fades quickly the moment we stop paying attention to it.

Episodic memory is the autobiographical record of specific events with their context, emotion, time, and place, and it is the system that lets us replay a vacation or an argument. When people say they “remember” something, this is usually what they mean. It is a reconstructive re-experiencing of a past event rather than a file pulled from disk.

Semantic memory is general knowledge with no timestamp attached, like the capital of France or the boiling point of water. These memories are extremely durable and resist forgetting for decades, which is why we can still recall the quadratic formula from high school even though we could not say what we ate for lunch last Tuesday.

Procedural memory is skill knowledge, like how to ride a bike, type on a keyboard, or play a piano chord. These memories are almost impossible to verbalize and almost impossible to lose, which is why a person who has not ridden a bike in thirty years can still ride one.

AI systems have none of these as designed systems. No working memory structure, no episodic store, no semantic consolidation, no procedural layer. A flat token buffer and a set of frozen weights. Everything that looks like memory in an AI conversation is a simulation of memory built on top of those two primitive tools.

So when a model seems to remember something, it is not really remembering, it is reading. The “memory” is just text in front of it, and the moment we close the window, the text is gone and so is the memory.

how ai “memory” actually works

Every language model in production today runs on a context window, a fixed-length sequence of tokens that holds the entire state of the conversation. The model reads this sequence, runs attention over it, and produces the next token. That context window is the only memory the model has during inference.

The size of the window varies across models. GPT-4 holds 32,000 tokens, Claude 3 Opus holds 200,000 tokens, and Gemini 1.5 Pro demonstrated 1 million tokens in a research setting. These numbers sound large, but they change the economics of the problem without changing its shape.

The clearest way to picture the context window is as a whiteboard. The model can only see what is currently written on it. It does not remember anything that has been erased, and it does not remember yesterday’s whiteboard. If we need it to know something, we have to write that something on the whiteboard now, and once the whiteboard fills up, some of the existing content has to be removed before new content can be added.

This works well enough for short conversations, but it becomes a real problem the moment we want anything that resembles a long-term relationship with the model.

the context cliff

Human forgetting is a curve that is gradual and graceful, with meaningful partial retention throughout. We do not forget a conversation all at once, but lose the exact words first, then the order of topics, then the smaller details, while the gist often survives for years and a faint emotional impression might survive forever.

AI forgetting, on the other hand, is a cliff. A token is either inside the context window and fully accessible, or outside it and completely gone, with no gradient in between. There is no “faint but retrievable” and no “I remember the vibe of what we discussed but not the specifics.” It is either in-context or it is nothing.

Humans forget exponentially but retain partial traces for weeks, months, and even decades, and those traces remain functional. Someone who learned French in high school and has not spoken it in twenty years can still recognize vocabulary and grammatical patterns far more easily than someone who never studied the language at all, because the faded traces are still usable. A context window has no equivalent partial retention: the token exists or it doesn’t.

When a conversation runs longer than the context window allows, something has to be evicted. The three common eviction strategies, truncation, summarization, and sliding window, each preserve different failure modes without solving the underlying problem. Information that mattered earlier in the conversation gets treated as expendable, because the model has no concept of importance at the level of stored memory and treats all tokens as equal until proven otherwise.

The obvious next question is: why not just make the window bigger?

why bigger windows don’t fix it

The obvious engineering response to the context cliff is to extend the window, making it a million tokens or ten million, but the reason this does not solve the problem is something called quadratic attention complexity, and the implications of this constraint shape almost every limitation that follows.

In a standard transformer, every token attends to every other token, which means the cost is quadratic in the sequence length. Doubling the context length quadruples the compute, so a sequence of 128,000 tokens costs 256 times more attention computation than a sequence of 8,000 tokens.

The 1-million-token context windows that exist in research today are technically real, but in practice processing them takes minutes per request and costs significantly more than a normal context. Long context exists as a capability, but not as a practical replacement for working memory in everyday use.

Alternative architectures have been proposed that cut the cost from quadratic to linear, and they show genuine promise on certain benchmarks. They also consistently lose recall quality on tasks that require precise, long-range memory, which is exactly the capability needed to solve the memory problem. The field is trading quality for scale rather than solving the underlying issue, and the marketing around “1M token context windows” makes it sound like the problem is solved when really it has just been deferred and made more expensive.

There is a second, separate issue even inside the window. Models systematically underweight information positioned in the middle of long contexts, while information near the beginning (the primacy effect) and near the end (the recency effect) gets recalled reliably. Information in the middle gets ignored even when it is directly relevant to the query.

The practical implication is that a 200,000-token context window does not give us 200,000 tokens of equally usable working space. It gives us reliable recall for roughly the first 20,000 tokens and the last 20,000 tokens, with degraded and unreliable recall for the 160,000 tokens in between. Human working memory does not have this problem at all, because within capacity all seven items are roughly equally accessible. AI ends up with the opposite tradeoff from humans: a large buffer with unequal access, versus a small buffer with uniform access. Neither is obviously better, but the two systems fail in different ways.

the missing process: consolidation

Nobody talks about this part enough, and it is probably the hardest piece to fix.

In humans, memory consolidation is the process by which short-term episodic memories get converted into long-term semantic knowledge, and it happens primarily during sleep. The hippocampus replays recent experiences in compressed bursts (sharp-wave ripples, lasting roughly 100 milliseconds each), while the neocortex strengthens the corresponding patterns and gradually integrates them into existing knowledge.

A person who has a hundred conversations about a topic gradually develops an intuition for that topic, building a generalized semantic understanding from all those episodes even though they could not reproduce any single conversation. The specific conversations fade, but the extracted knowledge remains, and that extraction is what consolidation actually does.

AI training, in contrast, is a one-time consolidation event. The model is trained on a fixed corpus, the weights are frozen, and then the model is deployed, with no ongoing consolidation after that. A model that has millions of conversations with users extracts nothing from those conversations in the way a human would, because each conversation evaporates completely once the session ends. The weights that encode the model’s knowledge are identical at the end of the deployment as they were at the beginning.

This is the deepest architectural gap between human and AI memory. Human memory is a dynamic, self-updating system that continuously compresses experience into knowledge, while AI inference is a static process running on frozen weights. Without a mechanism analogous to sleep consolidation, an offline process that replays experience and updates the model incrementally, this gap cannot be closed by making the context window larger. It is a different problem entirely.

We could give a model a context window the size of the Library of Congress and it would still not learn from its conversations the way a human does. Learning is not just reading more text in one sitting. Learning is what happens between sittings.

what transformers call memory: the kv cache

Inside a single forward pass, transformers maintain something called the KV (key-value) cache. For each token in the context, every attention layer stores a key vector representing what that token is, and a value vector representing what information it carries, and the attention mechanism uses these cached vectors to compute which earlier tokens to attend to when generating each new token.

The KV cache is sometimes described as the model’s “working memory,” but that framing is misleading, and the reason it is misleading is worth explaining carefully.

The cache is read-only during inference, meaning the model cannot write new information to it except by having that information appear as fresh tokens in the context. It is flushed completely between conversations, and it scales linearly with context length, so a 200K-token context in a 96-layer model with 128-dimensional key/value vectors needs roughly 5GB of memory per request just to hold the cache.

The deeper limitation, though, is that the KV cache represents no abstraction above the token level. Human working memory operates on structured chunks like goals, sub-tasks, relationships, and concepts, while the KV cache operates on subword token fragments. There is no mechanism for the cache to organize information into meaningful units, and no mechanism for it to weight more important tokens above less important ones.

So when people say transformers have working memory, what they really mean is that transformers have a buffer, and a buffer is not the same thing as working memory. A pile of laundry is not an outfit: the components are present, but the structure is not.

the workaround we use now: rag

Retrieval-Augmented Generation, or RAG, is the production answer to the memory problem right now. The idea is simple enough: store documents, conversation summaries, or structured facts in a vector database, and at query time, convert the user’s message to an embedding vector, retrieve the most similar stored chunks, stuff those chunks into the context window, and generate a response that incorporates the retrieved information.

RAG works well for factual question answering over a fixed corpus, and it works well for document retrieval, but it is not a memory system, and the distinction between the two matters.

Retrieval requires an explicit query, while human memory does not. A smell, a visual cue, or a related thought can surface a memory associatively without anyone formulating a search request. We walk past a bakery and we remember our grandmother’s kitchen, and nobody typed that into a search bar. RAG waits for us to ask.

More fundamentally, RAG never actually escapes the context window. The retrieved chunks fill tokens, and the generation step still runs inside the same fixed-length context that was the original problem. RAG defers the cliff edge by moving some information outside the window and retrieving it on demand, but it does not eliminate the cliff, and a sufficiently long conversation that retrieves many chunks will eventually run into the same context limit that motivated using RAG to begin with.

The problem is deferred, not solved. What RAG actually does is make the broken memory feel less broken for a wider range of cases, which is useful, but it is not the same thing as fixing it.

why we can’t just retrain: catastrophic forgetting

If context windows are not the answer, the natural alternative is weight updates: just train the model on new information so that it becomes part of the weights, making the new knowledge part of the model itself rather than part of the prompt.

The problem with this approach is catastrophic forgetting. When a neural network is trained on new data, gradient descent updates the weights to minimize loss on that new data, often at the expense of overwriting the weights that encoded older knowledge. This is not an engineering bug that better tooling can fix, but a fundamental property of how gradient-based learning works on shared weight matrices.

The problem has been recognized since the 1980s, and decades of research have produced partial mitigations (sparse updates, modular adapters, regularization tricks) without ever producing a clean fix. Each mitigation introduces its own costs, whether reduced plasticity, more architectural complexity, or limited transfer to new tasks, and the trade-off itself does not go away. We have just gotten better at choosing which side of it to pay.

Humans are remarkably resistant to catastrophic forgetting, and the contrast is striking. Learning a new language does not erase the old one. Learning to drive a new car does not erase decades of driving experience. This resistance comes from the distributed, overlapping representation of knowledge across the neocortex, combined with the hippocampal consolidation process that interleaves new learning with replay of old memories to prevent overwriting. No transformer architecture currently implements anything analogous to this.

So the choice that AI systems face is whether to learn new things or preserve old things, with no real way to do both at once and no way to do either without paying a price somewhere.

the architecture is the problem

Human memory is organized as a hierarchy, with the sensory buffer feeding into working memory, working memory feeding into episodic storage, and episodic storage feeding into semantic consolidation, with procedural encoding running in parallel. Each layer has its own purpose, its own capacity, its own update rate, and its own decay function, and information moves between layers through well-understood processes like attention, rehearsal, sleep consolidation, and repeated retrieval.

AI memory approaches do not form a hierarchy in this sense at all. The context window, the KV cache, RAG databases, fine-tuning, and external memory modules are disconnected engineering patches layered on top of a transformer architecture that was never designed to have persistent memory at all. There is no protocol for moving information from the context window into parametric weights, and no consolidation step that extracts general patterns from episodic interactions. The pieces are not a system, but a collection of workarounds invented separately for separate reasons that do not coordinate with each other.

The depth of this architectural mismatch is most evident at the working memory level. Human working memory is small by design, because the capacity limit forces prioritization and keeps only the most relevant information active, while the prefrontal cortex actively suppresses distractors to produce a highly structured, relevant workspace.

AI context windows are large by design, but size without structure produces a different failure mode, where the signal-to-noise ratio degrades as the context fills with increasingly marginal information. A model can get lost in its own context window, and a lot of the time, that is exactly what happens.

the deeper technical barriers

Understanding why a complete solution has not emerged means understanding the depth of the barriers, because each one is a foundational unsolved problem in machine learning rather than an engineering gap that more development effort can close.

The stability-plasticity dilemma is the central tension, where a system that learns quickly enough to update on new information will overwrite old knowledge, while a system stable enough to preserve old knowledge will not update quickly enough to be useful. This trade-off has been known since the 1980s and no known architecture eliminates it. Existing approaches only manage it with different trade-off profiles.

The quadratic attention problem constrains every approach that uses full self-attention, and the linear alternatives that exist consistently sacrifice recall quality on exactly the tasks that long-term memory would need to support.

The what-to-remember problem has no current solution at all. Human brains use emotional tagging, novelty detection, and spaced repetition to determine what gets encoded durably, while AI systems have no equivalent inference-time signal for salience. During training, the loss function determines what matters, but during inference, there is no mechanism for the model to decide that something in a conversation is important enough to warrant durable encoding. The model does not know what to keep, because the architecture provides no “keeping” mechanism at all.

The indexing problem is deeper than it looks. Associative recall, the kind that lets a smell trigger a memory without a search query, requires that memories be indexed by their semantic content and relational structure rather than by a vector embedding of their surface form. Current vector databases store embeddings of chunks, which supports similarity search but does not support the kind of spreading activation that characterizes human associative memory.

Four foundational problems, each one open, and none of them is going away in the next product release.

what real ai memory would need

A complete solution is well-defined even if none of its components currently exist, because human memory provides the specification. The hard part is implementing that specification in a system that is trainable, scalable, and computationally tractable, which is something nobody currently knows how to do.

Tiered storage would mean separate systems for short-term working state (fast, small, high-fidelity), recent episodic events (medium-term, moderate capacity), and consolidated semantic knowledge (permanent and unlimited), with each tier having its own update rules and retrieval mechanisms and a protocol for moving information between them.

Continual learning without catastrophic forgetting would mean the ability to add new information to weights without gradient descent overwriting old representations. This probably requires architectural innovations like sparse updates and modular memory rather than training tricks applied to monolithic dense transformers.

Learnable consolidation would mean an offline process running throughout deployment, not just at initial training, that periodically replays recent interactions and extracts durable patterns into semantic memory. The right analogy here is sleep, not fine-tuning: a structured, automatic, incremental update process rather than a large discrete retraining run.

Associative retrieval would mean the ability to surface memories in response to contextual cues, partial matches, semantic relatives, and temporally proximate events, all without requiring an explicit query. This almost certainly requires a different memory indexing scheme than current vector databases provide.

Selective forgetting would mean actively pruning low-relevance information rather than treating all memories as equally worth preserving. Forgetting is often perceived as failure, but it isn’t. Human forgetting reduces interference and keeps memory efficient, and an AI memory system that never forgets would face catastrophic interference over long deployment periods, eventually becoming unable to retrieve anything useful from the volume of accumulated, mostly irrelevant data.

Cross-session persistence would mean a stable representation of accumulated knowledge that survives session boundaries, user changes, and deployment updates. This is technically the easiest requirement to describe but practically the most contentious, because it raises immediate questions about privacy, consent, and model identity. What does it mean for a model to “know” us? What does it mean for that knowledge to belong to anyone? These are not just engineering questions.

Current systems meet none of these requirements fully. Each existing approach, longer context, RAG, fine-tuning, external memory, summarization, agent memory architectures, solves one constraint in isolation while accepting the others as fixed. A real solution would have to address all of them simultaneously, which is what human memory does by design.

the size of the gap

The gaps are uneven. The widest are on consolidation, where no AI system has anything resembling sleep-based memory replay, and on cross-session persistence, where systems that maintain any memory across sessions are still rare and limited. On most other dimensions, AI memory is real but shallow, enough to handle a single conversation well but not enough to accumulate anything across time.

The one dimension where AI has a genuine advantage is write speed. Appending a token to the context window is instantaneous, while human episodic encoding takes seconds to minutes and can fail under stress, distraction, or sleep deprivation. A user-provided fact is in the AI context the moment it is typed, while a human might forget the same fact by morning. For tasks that involve ingesting information fast and using it within the next ten seconds, AI is a real upgrade.

What makes the practical impact harder to see than it should be is that the dimensions compound. A system missing consolidation will not improve its recall quality over time. A system missing cross-session persistence cannot build on prior knowledge. Each weakness amplifies the others, and the compounding becomes visible over weeks and months of use rather than in any single conversation. AI memory demos that look impressive in a five-minute window are showing us the system performing well in the narrow region where its weaknesses haven’t had time to stack up yet.

what to take from this

The memory problem is architectural rather than just engineering. Adding more tokens to a context window is like adding more RAM to a computer that has no disk: it delays the bottleneck but does not change the fundamental storage model. The missing piece is not capacity but structure, tiered systems, consolidation processes, associative indexing, and selective forgetting. The whole thing has to be redesigned, not just scaled up.

Human forgetting is a feature, not a bug. The forgetting curve, the 7±2 working memory capacity limit, and the episodic-to-semantic compression that happens during sleep are not biological limitations to overcome, but mechanisms that prevent interference, reduce noise, and ensure that the information that matters most survives. Any AI memory system worth building will have to implement its own version of structured forgetting rather than trying to remember everything forever.

The AI we have today is not a forgetful version of a human, but a different kind of system entirely, and once we understand it that way, the limitations stop being obstacles to fight against and become constraints to design around.

Keyboard shortcuts

Navigation

Go to About g then a
Go to Blog g then b
Go to Photography g then p
Go to Work g then w
Scroll to top g then g

Actions

Search /
Keyboard shortcuts Ctrl /

Post Lists

Navigate posts j k
Open selected post Enter

Articles

Jump to nth heading 1 9
Next heading ]
Previous heading [
Previous / Next item
Go back to list Esc
Esc to close