snap-stanford/memorilla
🦍 Memorilla: Latent Semantic Memory for LLMs
What it solves
Large language models (LLMs) can only use information that fits inside their context window, so they forget past chats, long books, or large document collections. Memorilla solves this by reading an entire collection and distilling it into a fixed number of question-specific memory tokens (just 16), letting a frozen LLM answer accurately without needing all the raw text.
How it works
Memorilla adds a trainable memory module on top of a frozen LLM (like Qwen3-8B). When a question comes in, the module encodes the full document collection and produces 16 memory tokens that carry only what that question needs. The LLM then attends to those tokens. The memory module is trained in stages (Wikipedia, mixture, multitask, and personalization benchmarks), and an optional memory cache precomputes cross-attention keys and values so new questions become fast (8.1 ms for one million documents vs. 74 ms without the cache).
Who it's for
Developers building personal assistants, agents, or applications that need long-term memory across many interactions or large documents. Also useful for researchers studying efficient memory mechanisms for LLMs.
Highlights
- Uses only 16 memory tokens regardless of collection size, scaling to millions of documents.
- Achieves the best average performance against Mem0 and MemoRAG; on FactKG, it beats giving the LLM every document (84.33% vs. 80.43%) with 108x fewer tokens.
- Compresses books and movie scripts by more than 4,000x on NarrativeQA.
- Improves agent success rate on TextWorld games from 18.6% to 24.2% using only 8 memory tokens.
- Provides an optional memory cache that makes inference fast (0.74s for 512 documents, vs. 19.9s for full context).
Related
- Project
- Project
- Project
- Project
- Dispatch