MEMORILLA

MEMORILLALatent Semantic
Memory for LLMs

A learned memory that reads an entire document collection and supplies a frozen LLM with a compact set of query-dependent memory tokens.

Explore the method
  • Adibvafa Fallahpour*
  • Parsa Idehpour*
  • Vignesh Kothapalli*
  • Nikita Mounier
  • Shirley Wu
  • Shayan Pardis
  • Jure Leskovec

*Equal contribution, sorted alphabetically.

  • Stanford University
  • University of Toronto
  • University of Pennsylvania
  • MIT
  • Vector Institute
  • Arc Institute
Over4,000×document-token compression without sacrificing performanceNarrativeQA · relative to full context
Measured27×lower end-to-end latency512 documents · 0.74 s vs. 19.9 s

Supervised Qwen3-8B experiments. Compression excludes queries and shared instructions. Latency is measured on one H100-80GB at batch size 1. Full context uses YaRN.

Earlier conversationsFEB 03Let’s plan a weekend trip.MAR 12I run before work.JUN 04I eat plant-based.Preferences across a long historyAny lunch ideas?MEMORILLAReads every document16 memory tokensFrozenLLM“Try a lentil–quinoabowl for plant proteinand carbohydratesto support your runs.”Any lunch ideas?Earlier conversationsFEB 03Let’s plan a weekend trip.MAR 12I run before work.JUN 04I eat plant-based.MEMORILLAReads every document16 memorytokensFrozen LLM“Try a lentil–quinoa bowl forplant protein and carbohydratesto support your runs.”
Illustrative example. The answer combines a running routine with a dietary preference to infer a suitable lunch. The number of memory tokens is configurable, and the LLM’s weights remain fixed during memory-module training.

Memory beyond the context window

An LLM’s knowledge is fixed when training ends, yet the world it serves keeps changing. Users reveal their preferences over months, new findings overturn old ones, and agents make mistakes they should not repeat. Retraining for every change is impractical, and a frozen model forgets whatever it learns as soon as the text leaves its context window.

What a question needs is rarely known in advance. A request for energy-boosting foods may hinge on an iron deficiency mentioned months earlier in unrelated words. Placing everything in context is costly and often buries what matters, while retrieval misses information that resembles the question only weakly.

MEMORILLA instead learns to read the entire collection and distill what each question needs into a few memory tokens. Four requirements guide its design.

  1. Collection-wide access

    Each query reads the whole collection, not a few passages chosen in advance.

  2. Query-dependent recall

    What memory returns depends on the question, so one collection serves many requests.

  3. A fixed token budget

    The model receives the same few memory tokens however large the collection grows.

  4. Reusable document embeddings

    Each document is encoded once, and the store grows without re-encoding the past.

How MEMORILLA works

MEMORILLA separates remembering from recalling. A frozen encoder stores each incoming document, such as a conversation or a book chapter, as an embedding. For each question, learned memory slots read the question and the entire store, and become memory tokens that the frozen LLM reads alongside it.

01 / MEMORY WALKTHROUGHIllustrative example

Remember · Session 1 · March 3

My doctor says I have iron-deficiency anemia.

I’ll keep that context in mind for future conversations.

Frozen encoder

Memory storeOne embedding per session

MEMORILLA16 learned slots

Frozen LLMmemory tokens + question

In the first session, the user shares a recent diagnosis.

01 / 10

An illustrative example. The encoders and the LLM stay frozen, and only the memory module is trained. Attention weights are illustrative, not measured.

Growing the memory is cheap. Adding a document costs one encoder pass, as with a retrieval index, and the model always receives a fixed number of memory tokens, sixteen in our supervised experiments. Only the memory module is trained, in stages that move from paraphrasing Wikipedia to general question answering and summarization to the benchmarks’ training splits.

How MEMORILLA differs from RAG

Retrieval-augmented generation (RAG) and MEMORILLA can share the same document embeddings and the same frozen LLM. They differ in how they read the store and in what reaches the model.

02 / RAG AND MEMORILLA SIDE BY SIDEIllustrative example, measured costs

Question What should I eat to keep my energy up during the day?

RAG

Starts from the stored document embeddings

SimilarityAnemia diagnosisHealthy office snacksHalf-marathon planFiling my taxesMeal prep for busy weeksWeekend in LisbonAfternoon energy slumpsFixing a bicycleTop 3Relevant, butbelow the cutoffRetrieved textQuestionFrozen LLM

“Complex carbohydrates such as brown rice, quinoa and oats provide steady energy through the day.”

MEMORILLA

Starts from the same stored embeddings

AttentionAnemia diagnosisHealthy office snacksHalf-marathon planFiling my taxesMeal prep for busy weeksWeekend in LisbonAfternoon energy slumpsFixing a bicycleLearned slots16 memory tokensQuestionFrozen LLM

“Given your iron-deficiency anemia and half-marathon training, choose iron-rich foods such as lentils and spinach.”

Up to 4,212× fewer tokens than full context

Document tokens per query on NarrativeQA

Full context67,385
RAG-503,612
MEMORILLA16

27× lower latency than full context

End-to-end latency with 512 documents

Full context19.9 s
MEMORILLA0.74 s
01 / 6

An illustrative example with schematic scores and text lengths. Token counts and latencies come from our experiments. Tokens exclude the question and shared instructions, and NarrativeQA has the largest gap. In geometric mean across the eight benchmarks, MEMORILLA uses 113 times fewer document tokens than RAG-50. Latency is end to end on one H100-80GB with Qwen3-8B at batch size 1, full context uses YaRN, and RAG was not timed.

RAG gives the model the exact text of the documents it selects, which suits questions whose answer is a name it can find verbatim. MEMORILLA instead reads the whole collection, so it can connect information that resembles the question only weakly, but its fixed number of memory tokens can lose fine details such as exact names.

Results

We test MEMORILLA on eight benchmarks spanning personalization, knowledge-intensive QA and long-document QA, with every method answering through the same frozen Qwen3-8B. MEMORILLA has the highest mean score (49.68) and leads on five benchmarks, while giving the model 394 times fewer document tokens than full context on average.

Scatter plot of mean score against document tokens per query on a log scale. MEMORILLA has the highest mean score, about 50, with 394 times fewer document tokens than full context, and lies on the Pareto frontier with xRAG and the closed-book model. The other baselines use between about 50 and 6,300 tokens and score between 38 and 48.
Mean score across eight benchmarks against the geometric mean of document tokens given to the model, excluding the question and shared instructions. MEMORILLA lies on the Pareto frontier with the highest score.
Results on all eight benchmarks View scores ↗
Primary benchmark metrics. Higher is better. Best baseline includes all evaluated baselines, including full context.
Benchmark / metricFull contextBest baselineMEMORILLA
PersonaMem-v2Accuracy (SA)27.9230.90xRAG44.60Best
PersonalizationV4Accuracy (SA)59.1267.88MemoRAG66.65
PubMedQAAccuracy67.0069.00LLMLingua-259.00
FactKGAccuracy80.4380.43Full context84.33Best
NarrativeQAROUGE-L17.9920.51MemoRAG19.31
TriviaQAExact match52.6056.60MemoRAG57.00Best
LaMP-4ROUGE-L14.2116.10xRAG18.15Best
LaMP-7ROUGE-L43.7146.84xRAG48.37Best

Scores use each benchmark’s primary metric on a 0–100 scale. Higher is better. SA denotes short-answer evaluation. The reported mean combines different metrics. PersonaMem-v2 and PersonalizationV4 receive additional benchmark-specific fine-tuning.

Personalization

A good assistant knows its user without being told twice. In PersonaMem-v2 and our synthetic PersonalizationV4, preferences are rarely stated outright and lie scattered across more than a hundred past conversations. LaMP-4 and LaMP-7 ask the model to write a headline or rewrite a tweet in the user’s own style.

User

What are some suitable foods for me to boost my energy during the day?

No memory

Whole grains, bananas, and nuts provide steady energy for …

Retrieval

Complex carbohydrates like brown rice, quinoa, and oats along with …

MEMORILLA

Given your history of iron-deficiency anemia, include iron-rich foods …

A PersonalizationV4 example. MEMORILLA connects the request to an earlier mention of iron deficiency despite the lack of lexical overlap.

The largest margin appears on PersonaMem-v2, where MEMORILLA reaches 44.60% short-answer accuracy against 30.90% for the strongest baseline, xRAG. Full context reaches only 27.92% while using 1,974 times more document tokens. On LaMP-7, MEMORILLA lifts ROUGE-L from 43.13 without memory to 48.37.

Knowledge-intensive question answering

Some claims hold only when facts connect. Verifying the FactKG claim “AIDAstella was built by a company in Papenburg” requires linking the ship to its builder and the builder to the town.

03 / A TWO-HOP CLAIMFactKG test set, actual predictions

Claim, labeled true AGM-88 HARM is produced by a company that manufactures the ALV X-1.

The triples in this claim’s collection

  1. AGM-88 HARM → weight → 355000.0
  2. AGM-88 HARM → length → 4.1
  3. AGM-88 HARM → diameter → 0.254
  4. AGM-88 HARM → type → Air-to-surface missile
  5. AGM-88 HARM → type → Anti-radiation missile
  6. AGM-88 HARM → origin → United States
  7. AGM-88 HARM → service → 1985
  8. AGM-88 HARM → designer → Texas Instruments
  9. AGM-88 HARM → manufacturer → Texas Instruments, then Raytheon Corporation
  10. AGM-88 HARM → engine → Thiokol SR113-TC-1 dual-thrust rocket engine
  11. Alliant Techsystems → product → AGM-88 HARM
  12. ALV X-1 → height → 54.0
  13. ALV X-1 → height → 16.4592
  14. ALV X-1 → diameter → 1.524
  15. ALV X-1 → diameter → 5.0
  16. ALV X-1 → rocket stages → 2
  17. ALV X-1 → status → Inactive
  18. ALV X-1 → total launches → 1
  19. ALV X-1 → failed launches → 1
  20. ALV X-1 → country origin → United States
  21. ALV X-1 → launch site → Mid-Atlantic Regional Spaceport
  22. ALV X-1 → manufacturer → Alliant Techsystems
  23. ALV X-1 → function → Sub-Orbital Test Vehicle
  24. ALV X-1 → mass → Unknown
  25. ALV X-1 → sites → Mid-Atlantic Regional Spaceport
  26. ALV X-1 → launches → 1
  27. ALV X-1 → mean of transportation/diameter → 1.524

and 24 further triples

RAG-50

Falseincorrect

Reads all 27 triples as text

78.4%accuracy on all claims

MEMORILLA

Truecorrect

Reads all 27 triples into 16 memory tokens

84.3%accuracy on all claims

The collection holds 27 triples, and the claim never names the company that links the missile to the rocket.

01 / 4

One claim from the FactKG test set, with predictions from the released MEMORILLA checkpoint and RAG-50. A single claim does not show overall performance, and each method answers claims the other misses. Accuracy covers all 9,041 test claims.

MEMORILLA verifies 84.3% of claims, ahead of the 80.4% reached with every fact in context, while using 108 times fewer document tokens. Since full context sees every fact, the gap does not come from missing facts. As claims compose more facts, RAG-50 falls from 78.7% to 51.8%, while MEMORILLA stays above 80%.

RAG-50MEMORILLA

Entities in the claim

506070809085.781.51n = 1,29983.177.72n = 3,50283.877.33n = 2,76487.179.54+n = 1,476Number of entities

Facts composed in the claim

506070809089.278.71n = 1,05887.466.92n = 1,12680.861.73n = 73185.851.84n = 456Number of composed facts
FactKG accuracy (%) by the number of entities and composed facts in a claim. RAG-50 retrieves the 50 most similar facts and degrades as claims compose more of them, while MEMORILLA stays above 80%.

Long-document question answering

Long documents bury answers in thousands of tokens, often phrased unlike the question. NarrativeQA asks about entire books and screenplays, and TriviaQA pairs trivia questions with Wikipedia and web documents.

MEMORILLA reaches the best TriviaQA exact match (57.0) with 743 times fewer document tokens than full context. On NarrativeQA, it gains most over RAG-50 on “why” and “how” questions, while RAG-50 wins on “who” and “which” questions, whose answers appear verbatim in the text.

Memory for agents

Memory becomes essential when a model must learn from its own experience. In TextWorld, a frozen Qwen3-4B agent explores up to 65 rooms to complete a quest within 50 turns, while MEMORILLA condenses its growing history into eight memory tokens. Only the memory module is trained, using reinforcement learning on the reward the game provides.

04 / MEMORY FOR AGENTSTextWorld · schematic replay

Full-history prompting

Full history in context

Exploring

Move 0

StartChamberLaundromatStudioCubicleBedroomDish-pitCookhouseSalonVaultPlayroomStudyCanteenRestroom
Full history in context, no memory

MEMORILLA

Full history plus 8 memory tokens

Exploring

Move 0

StartChamberLaundromatStudioCubicleBedroomDish-pitCookhouseSalonVaultPlayroomStudyCanteenRestroom
Memory begins after the first turn
01 / 19

Schematic replay of the held-out game in Figure 7 of the paper. Routes are simplified and observations are paraphrased. Move numbers refer to this illustration, not measured completion times.

Without memory, the agent shuttles between the start, laundromat, studio, salon and vault and runs out of turns. With MEMORILLA, it backtracks briefly between the salon, vault, study and canteen, then reaches the playroom goal through the restroom.

Both agents read the same full history, so the comparison isolates what eight memory tokens add. On held-out games, average success rises from 18.6% to 24.2% and games completed within three attempts from 25.0% to 37.5%. Untrained memory falls below the baseline, so the gain comes from learning, not extra tokens.

Full-history promptingMEMORILLA
Games completed within three attempts
Full-history prompting: 25.0%
MEMORILLA: 37.5%
Average success rate
Full-history prompting: 18.6%
MEMORILLA: 24.2%
Episodes that end before the turn limit
Full-history prompting: 29%
MEMORILLA: 42%

Held-out games with a frozen Qwen3-4B agent. Bars share a scale from 0 to 100%.

Memory and retrieval

Learned memory complements retrieval rather than replacing it. MEMORILLA tends to win when an answer depends on how a collection fits together, while retrieval tends to win when the answer is a name it can find verbatim. On short sources such as PubMedQA, reading the text directly remains the better choice.

RAG-50MEMORILLAOracle union
0%25%50%75%100%
Either
FactKG
RAG-50: 78.4
MEMORILLA: 84.3
Either method: 94.3
PV4
RAG-50: 65.8
MEMORILLA: 66.6
Either method: 80.4
PubMedQA
RAG-50: 67.0
MEMORILLA: 59.0
Either method: 80.0
TriviaQA
RAG-50: 55.6
MEMORILLA: 57.0
Either method: 74.2
LaMP-7†
RAG-50: 37.2
MEMORILLA: 50.1
Either method: 56.1
NarrativeQA†
RAG-50: 32.1
MEMORILLA: 37.9
Either method: 54.3
PMv2
RAG-50: 26.7
MEMORILLA: 44.6
Either method: 53.8
LaMP-4†
RAG-50: 26.6
MEMORILLA: 37.2
Either method: 46.6
Share of questions (%) answered by RAG-50, by MEMORILLA, and by at least one of the two. The shaded bar is the oracle union, not an evaluated hybrid system.
PV4 is PersonalizationV4 and PMv2 is PersonaMem-v2. † Counted as answered at a ROUGE-L of at least 0.20, or MEMORILLA’s median if higher.

Each method answers questions the other misses. On FactKG, 15.9% are solved by MEMORILLA alone and 10.0% by retrieval alone. The union is an oracle bound rather than a measured hybrid, but it makes combining the two a promising next step.

Future directions

We see memory as a path toward language models that keep improving after deployment, carrying what they learn across conversations, tasks and successive models. MEMORILLA is an early step in that direction.

Assistants with continuity
An assistant could grow with a person over years, keeping each user’s memory in a separate store that can stay on their device and be deleted on request.
Experience that improves action
Agents could carry lessons across tasks and avoid repeating mistakes. In TextWorld, learned memory already helps an agent escape loops within a game.
Memory beyond one model
Because the store holds only embeddings, it could extend to images, audio and video, and portable memory modules could let one store serve many models.
Cumulative scientific reasoning
Research systems could connect findings across papers, code and experiments, pairing learned memory for synthesis with retrieval for verifying exact claims.

Getting there requires memory that keeps fine details and improves with use. The nearest steps are pairing memory with retrieval, training encoders for compression, and testing transfer across model families.

Current limits. MEMORILLA can lose fine-grained details such as exact names. Because it writes memory directly into the LLM’s input embeddings, it requires open model weights and a memory module trained for each LLM. All experiments pair a Qwen encoder with a Qwen decoder on text alone, so transfer to other model families and modalities is untested, as are domains such as code and science beyond biomedicine. The TextWorld agent is trained and evaluated on a single game suite with episodes of at most 50 turns, so learning across environments and over long deployments remains to be shown.

Citation

@inproceedings{fallahpour2026memorilla,  title     = {Memorilla: Latent Semantic Memory for {LLM}s},  author    = {Adibvafa Fallahpour and Parsa Idehpour and Vignesh Kothapalli and Nikita Mounier and Shirley Wu and Shayan Pardis and Jure Leskovec},  booktitle = {COLM Workshop on Context Beyond the Window: Persistent Knowledge in Language Models},  year      = {2026},  url       = {https://openreview.net/forum?id=VV0vvzL783}}

References

  1. Côté, M.-A., et al. (2019). TextWorld: A learning environment for text-based games. Computer Games, CGW 2018 revised selected papers. Springer. 41–75. Preprint.
  2. Jiang, B., et al. (2025). PersonaMem-v2: Towards personalized intelligence via learning implicit user personas and agentic memory. arXiv:2512.06688.
  3. Salemi, A., et al. (2024). LaMP: When large language models meet personalization. ACL.
  4. Kim, J., et al. (2023). FactKG: Fact verification via reasoning on knowledge graphs. ACL.
  5. Kočiský, T., et al. (2018). The NarrativeQA reading comprehension challenge. TACL.
  6. Joshi, M., et al. (2017). TriviaQA: A large scale distantly supervised challenge dataset for reading comprehension. ACL.
  7. Jin, Q., et al. (2019). PubMedQA: A dataset for biomedical research question answering. EMNLP-IJCNLP.
  8. Chhikara, P., et al. (2025). Mem0: Building production-ready AI agents with scalable long-term memory. arXiv:2504.19413.
  9. Qian, H., et al. (2025). MemoRAG: Boosting long context processing with global memory-enhanced retrieval augmentation. ACM Web Conference. 2366–2377. Published version.
  10. Cheng, X., et al. (2024). xRAG: Extreme context compression for retrieval-augmented generation with one token. NeurIPS.
  11. Pan, Z., et al. (2024). LLMLingua-2: Data distillation for efficient and faithful task-agnostic prompt compression. Findings of ACL.
  12. Yang, A., et al. (2025). Qwen3 technical report. arXiv:2505.09388.
  13. Peng, B., et al. (2024). YaRN: Efficient context window extension of large language models. ICLR. Preprint.
  14. Shao, Z., et al. (2024). DeepSeekMath: Pushing the limits of mathematical reasoning in open language models. arXiv:2402.03300. Introduces GRPO.