The recording
You were last reading slide 1.
Architectural lookup
Information retrieval for AI
30 November 2026
Seong Joon Oh - KAIST AI
Upcoming sessions
2 December - Weights or an explicit store
The anchor paper is LMLM (Zhao et al., ICLR 2026). Preparation is due 1 December, 18:00 KST.
7 December and 9 December - recorded lectures, no live class. Retrieval from the context, parts 1 and 2.
Roles and readings are in the course schedule.
Today
Session 20 covered the two ends of one axis.
- A datastore is traced and updated by lookup. Every token needs a nearest-neighbour search, and the store grows with the corpus.
- A dense network runs regular, parallel arithmetic. It is traced approximately, through influence functions.
The middle could keep the cost of the dense end and the addresses of the datastore. Today asks which designs do.
- From datastore back to weights
- Memory inside the network
- Updating and tracing memory
From datastore back to weights
In this section
- Memory Decoder: train a module to imitate the datastore.
- MeMo trains a separate memory model and queries it in text.
- The distilled module gains speed and loses deletion and attribution.
- Three tests for any store inside the network: address, isolation, and provenance.

Memory Decoder imitates the datastore
The datastore costs a nearest-neighbour search on every token, and it grows with the corpus. Memory Decoder moves it to the dense end. A small network gives the datastore’s output without the search.
A small transformer decoder learns to match the kNN distribution over a domain corpus. The loss is
At inference it runs beside the frozen model, and the two distributions are interpolated. There is no search.
Across biomedicine, finance, and law, perplexity falls by 6.17 points on average. The overhead is 1.28 times the base model, against 2.17 for kNN-LM.
Cao et al., 2025, abstract, §3, and §4.

A large memory lifts a small model above a larger one
In Memory Decoder at Scale, a 6.9B memory beside Pythia-410M raises its average over 17 benchmarks from 29.86 to 37.34. Pythia-12B scores 37.24.
Memory Decoder at Scale, 2026, abstract and Fig. 1.

MLP Memory applies the same imitation to the pretraining data
Same loss as Memory Decoder, from the same group. A 1B MLP imitates the retriever over the pretraining data.
- Like kNN-LM, it mixes the retriever’s distribution into the output. On Mistral-7B, QA accuracy over five benchmarks rises 12.3% relative to the base model.
- For 5B tokens, a 40 TB datastore becomes a 4 GB MLP, in the paper’s example.
- Time to first token is 27 ms, against 22 for the base and 151 for kNN-LM.
Wei et al., 2025, §1, §3, Fig. 1, and Table 1.
MeMo trains a separate memory model
The LLM reads the memory model only through text, so it needs no access to the LLM’s weights or logits. Retrieval cost does not grow with the corpus.
Like Memory Decoder, it has no entry to delete and no source to cite.
Quek et al., arXiv 2026, abstract, §1, and Fig. 1.
MeMo answers questions that span documents
The memory model reads the whole corpus in training, so one answer can combine facts from many documents. RAG passes the LLM separate passages. Memory Decoder mixes output distributions, so it needs the LLM’s logits.
| RAG | Memory Decoder | MeMo | |
|---|---|---|---|
| LLM weights unchanged | ✓ | ✓ | ✓ |
| No index to search | ✗ | ✓ | ✓ |
| Works with a closed LLM | ✓ | ✗ | ✓ |
On NarrativeQA with Gemini-3-Flash, MeMo scores 53.58. The best retrieval baseline, NV-Embed-V2, scores 26.62, and perfect retrieval 60.41. On BrowseComp-Plus, where the answer must be read from the evidence, graph-based RAG is level or ahead.
Quek et al., arXiv 2026, Table 1, Table 2, and §5.1.
The distilled memory trades deletion and attribution for speed
| Explicit datastore | Distilled memory | |
|---|---|---|
| Cost per token | Search over stored keys | One extra forward pass |
| Delete a document | Drop its entries | Retrain or edit the module |
| Name the source | Read the retrieved entries | No entries to read |
Addressability means a computable address, isolated slots, and a trace to the data
- Address. Can you compute which parameters a token reads?
- Isolation. Can you change one slot without disturbing the rest?
- Provenance. Can you trace a slot to the training data that wrote it?
A datastore passes these tests. Memory Decoder and MeMo fail them: the distilled module has no entry to change and no source to cite.
Memory inside the network
In this section
- A feed-forward layer is a key-value memory read densely.
- Mixture of experts routes each token to a few experts (e.g. Mixtral).
- A memory layer reads a few slots from a table of hundreds of thousands.
- Memory Layers at Scale scales the table.
- Engram computes the address from the text itself.
The designs follow the spectrum from left to right.
The first matrix holds keys and the second holds values
Mixture of experts and memory layers each replace this layer.
Rows of
Every token reads every slot, so more slots cost more computation, and the address test fails.
Geva et al., EMNLP 2021. Replacement of the FFN: Lample et al. 2019, Fig. 3; Berges et al. 2024, §1.
A router sends each token to the top k experts
Only the top
The first step from the dense end. One address selects a whole expert, thousands of parameters.
Shazeer et al., ICLR 2017.

Mixtral activates 13B of its 47B parameters per token
Each layer has 8 feed-forward experts. The router selects 2 for every token at every layer.
Each token can use 47B parameters but uses 13B active parameters.
With 5 times fewer active parameters, Mixtral matches or beats Llama 2 70B on most of the reported benchmarks.
Jiang et al., arXiv 2024, abstract, §3, and Fig. 3.

Mixtral’s experts follow syntax rather than topic
Expert assignment on The Pile is very similar for ArXiv, PubMed Abstracts, and PhilPapers, at the first, middle, and last layers. DM Mathematics differs slightly.
The router shows structure in syntax instead. self in Python and indentation tokens go to the same experts. Consecutive tokens often share an expert.
In Mixtral’s analysis, expert assignment does not map to topics.
Jiang et al., arXiv 2024, §5, Figures 7-8 and Table 5.
An expert is a coarse address with no record of its data
- Address. The router’s choice can be read off for each token.
- Isolation. Coarse. An expert is a full feed-forward network that many tokens share.
- Provenance. Fails in Mixtral. FlexOlmo (Shi et al., 2025) trains one expert per closed dataset, so a data owner’s expert can be included or excluded at inference with no further training.
A memory layer can be read as a mixture of experts with one small expert per memory slot. That shrinks the address to a single slot.
Shi et al., 2025, abstract. Lin et al., 2025, §3, after He (2024).
A memory layer is a sparse feed-forward layer with a huge hidden layer
Read a feed-forward layer as a memory: hidden units are slots, the first matrix holds keys, the second holds values.
Now make the hidden layer enormous, hundreds of thousands to a million slots, and let each token read only the
That is a memory layer. Capacity grows with the number of slots. Computation grows with
Lample et al., NeurIPS 2019.
A memory layer reads like attention over fixed keys
| Keys come from | Number of keys | Read | |
|---|---|---|---|
| Feed-forward layer | learned parameters | hidden size, thousands | dense |
| Self-attention | the current context | context length | dense |
| Memory layer | learned parameters | up to about a million | top |
A transformer computes its key-value reads densely. A memory layer keeps the same read and makes it sparse over a fixed, very large set of keys.
“the keys and values do not correspond to input tokens but are free embedding vectors, and the number of values (memory size) is very large”
Lample et al., NeurIPS 2019, §3.1 and Eqs. 1-3.
Product keys find the best of a million keys in a small corner
Split the query in two. Each half scores its own subkeys. A full key pairs one subkey from each half, and its score is the sum of the two.
Sort each half by score. The top
Lample et al., NeurIPS 2019, §3.2.

A memory layer beats a model twice as deep at almost twice the speed
On a 28-billion-word news corpus, a 12-layer model with one memory layer reaches perplexity 15.6. The 24-layer model without memory reaches 16.0.
The memory has
Lample et al., §4.3, Table 1 and Fig. 4.
Quick quiz: how much does the product-key search compute?
Each half of the query has 1024 subkeys, so there are
How many query-subkey dot products does the search compute?
Sign in with your course account to choose. The lecturer will reveal responses and the answer.
A memory layer passes the address and isolation tests but not provenance
- Address. Computed by exact key search. You can list the slots a token reads.
- Isolation. A slot’s value can be updated alone. Sparse memory finetuning uses this.
- Provenance. Fails. The method records no link from a slot to the documents that trained it.

Scaled memory layers beat denser models on factual QA
Memory Layers at Scale (Berges et al., 2024) keeps the product-key lookup and scales it. It replaces the feed-forward layer in a few transformer layers, and all of them share one pool of keys and values.
They scale memory to 128B parameters, with base models up to 8B, trained on up to 1 trillion tokens.
Memory-augmented models beat dense models with more than twice the computation, and beat MoE matched for compute and parameters. Gains are largest on factual QA.
A 1.3B model with 64 million keys approaches Llama 2 7B on factual QA, which used 10 times more FLOPs.
Berges et al., arXiv 2024, abstract, §1, §3.1.1, §5.2, and Fig. 1.
Engram computes the address from the text itself
Why a lookup: a plain transformer spends several early layers of attention and feed-forward computation to combine the, Eiffel, and Tower into one representation of the name. Engram looks that representation up instead.
How it differs from product-key memory: there, a query from the hidden state is scored against keys. Engram scores nothing. A hash of the last
Cheng et al., arXiv 2026, abstract, §1, §2.2, and §2.3.

Inside an Engram block
- Hash the last 2 and the last 3 tokens, with several hash heads each.
- Read one row per head from the 2-gram and 3-gram tables, and concatenate the rows.
- Project them to a key and a value. The hidden state scores the key, and the score gates the value.
- A short causal convolution follows, and the result is added to the residual stream.
Only some layers carry an Engram block, before attention and MoE.
Cheng et al., §2.2-§2.4 and Fig. 1.

A text-based address lets the table sit in CPU memory
The address depends on the input tokens alone, so it is known before the forward pass.
The table can sit in the server’s CPU memory, which is far larger than GPU memory. The CPU sends the needed rows to the GPU ahead of time, while the GPU computes the earlier layers.
Offloading a 100B-parameter table costs under 3% overhead.
Cheng et al., §1, §2.5, and Fig. 2.

Engram complements experts under a fixed budget
Fix the total and active parameters. Let
Validation loss is U-shaped in
At 10B scale, loss falls from 1.7248 at
Guided by this, the authors train Engram-27B. Against an MoE with the same parameters and FLOPs, it gains 3.4 points on MMLU and more on reasoning, 5.0 on BBH.
Cheng et al., abstract, §3.1, and Fig. 3.
Engram names its rows by text rather than by documents
- Address. A hash of the last few tokens, computed before the forward pass.
- Isolation. A row can be updated alone. Hash collisions can put several n-grams in one row; multi-head hashing reduces collisions.
- Provenance. A row stands for an n-gram, and an n-gram occurs in many documents. The method records no link from a row to documents.
Cheng et al., §2.2.
Updating and tracing memory
In this section
- Sparse memory finetuning changes a new fact in its own slots, with less forgetting than full finetuning.
- Hierarchical memories key memory blocks by clusters of training documents, so a block can be traced and blocked.
Finetuning on a new fact disturbs old ones
Full finetuning updates every parameter that a new fact’s gradient touches. Many of those parameters also serve other facts.
Learning a stream of new facts therefore erodes old knowledge. This is catastrophic forgetting.
A memory layer gives a finer handle: each token reads only about 32 slots per head, out of a million.

Update only the slots that are specific to the new fact
The problem: finetuning every slot the new fact reads still causes forgetting. Some of those slots serve many inputs, for example predicting syntax.
The fix borrows TF-IDF from document retrieval. Count how often each slot is read on the new batch,
Only the top
Lin et al., arXiv 2025, §4, §6, and Fig. 2.
Forgetting falls from 89% to 11%
Train on a stream of TriviaQA facts, then measure NaturalQuestions, which the model knew before.
The three methods reach the same level of new-knowledge acquisition.
A finer address lets a correction target the parameters a fact uses.
Lin et al., arXiv 2025, abstract and §1.

Memory blocks keyed by document clusters can be traced
The problem: product-key memory and Engram link no slot to the documents that trained it, so both fail the provenance test. FlexOlmo makes the link only at the size of a whole expert.
Pouransari et al. build the link in. They cluster the pretraining documents and give each cluster a block of memory parameters. At inference, a small model fetches the blocks for its context.
Retrieval fetches weights, not tokens. Each block can be traced to a cluster of documents.
Blocking 1/16 of the memory bank cut accuracy on one class of facts from 70% to 20%. This is a preliminary test, not deletion.
Pouransari et al., ICLR 2026, Fig. 2.
Finer addresses pass more tests, and cost storage and sharing
| Design | Address | Isolation | Provenance | Storage | One entry serves |
|---|---|---|---|---|---|
| Dense FFN | all slots read | no | no | thousands of slots per layer | every token |
| MoE | learned router | coarse, per expert | no | all experts kept, 47B in Mixtral | many tokens |
| Memory layer | exact key search | per slot | no | up to millions of slots | tokens that select it |
| Engram | hash of the text | per row | partial: rows are n-grams | 100B-parameter table, in CPU memory | one n-gram |
| Hierarchical memories | document cluster | per block | yes, by cluster | memory bank of billions of parameters | one document cluster |
| kNN-LM datastore | nearest neighbours | per entry | yes | one entry per training token | one training token |
good partial poor
Towards the bottom, each entry serves fewer inputs. Addresses and deletion get easier, the store grows, and less is shared across inputs.
Next time
2 December discussion: should factual knowledge live in the weights or in an explicit store? Anchor: LMLM.
Next lecture: retrieval from the context, starting with attention as a lookup and the KV cache.