What is Memorilla?
Memorilla is an open-source memory system from Stanford's SNAP group that lets a frozen LLM use far more material than fits in its context window. It sits in the Agent Memory category of the Agents & Automation tools and is open-source, written in Python and licensed Apache-2.0. To get started: clone and install.
Overview
Memorilla is an open-source memory system from Stanford's SNAP group that lets a frozen LLM use far more material than fits in its context window. It reads an entire document collection, such as a user's past chats or a long book, and for each question hands the LLM a fixed set of 16 memory tokens that carry what that question needs, instead of pasting the documents or a handful of retrieved chunks into the prompt. The repository holds the code for the paper Memorilla: Latent Semantic Memory for LLMs (arXiv 2610.21375), released under Apache 2.0, with trained checkpoints on Hugging Face.

Under the hood, a frozen query encoder and a frozen document encoder (Qwen3-Embedding-4B by default) embed the question and every document; a trained memory module with learned latents cross-attends over those embeddings and outputs the memory latents, which are stacked with the question's normal token embeddings and passed to the frozen decoder (Qwen3-8B by default). Because the decoder always reads the same 16 tokens, its cost does not grow with the collection; only the memory module's does. An optional memory cache computes the cross-attention keys and values once when documents are written, which the README reports brings a question over one million documents down to 8.1 ms on a B200, or 5.0 ms with torch.compile.
The README reports that with this budget Memorilla gets the best average score against methods such as Mem0 and MemoRAG, that on FactKG it beats giving the LLM every document (84.33% vs 80.43%) while using 108× fewer tokens, and that as an agent's memory trained with GRPO it raises the average success rate on TextWorld games from 18.6% to 24.2%. It is a GPU research codebase rather than a hosted service: it needs Linux, CUDA GPUs and Python 3.11, and the quick-start example uses one 80 GB GPU.
What it does
- Fixed 16-token memory: a frozen LLM receives the same number of memory tokens however many documents are stored
- Query-dependent compression — the memory module reads the whole collection again for each question, so different questions get different memory tokens
- Python inference API on vLLM: MemoryVLLM.from_pretrained, then write a collection and answer questions against it
- Optional memory cache and torch.compile for fast questions over collections of up to four million documents on one GPU
- Trained checkpoints on Hugging Face (Stage 1–3 plus PersonalizationV4 and PersonaMem-v2 fine-tunes) with Qwen3-8B and Qwen3-Embedding-4B
- Train and evaluate on your own documents and questions from parquet files, with no code changes
- Closed-book, top-5 RAG and full-context baselines, plus a GRPO recipe for agent memory on TextWorld
Getting started
Memorilla runs on Linux with CUDA GPUs and Python 3.11 and installs from source with uv. The quick-start example needs one 80 GB GPU and downloads about 25 GB of models on first run.
Clone and install
Create a Python 3.11 environment with uv and install the package. FlashAttention-2 is only needed for training; evaluation and inference work without it.
git clone https://github.com/snap-stanford/memorilla.git && cd memorilla
uv venv --python 3.11 && source .venv/bin/activate
uv pip install -e .
uv pip install --no-build-isolation flash-attn==2.7.4.post1Answer a question from a document collection
Load the Qwen3-8B checkpoint with a memory module and pass the question plus all documents. This example takes one user's 107 past conversations from the PersonaMem-v2 test set and compresses them into 16 memory tokens.
from memorilla.benchmarks import PERSONA_PROMPT
from memorilla.data import ensure_data, load_split
from memorilla.vllm import MemoryVLLM
row = load_split("pmv2", "test", ensure_data("pmv2", ["test"]))[73]
model = MemoryVLLM.from_pretrained("memorilla/Memorilla-Qwen3-8B", "pmv2")
answer = model.answer(row["question"], row["documents"], system_prompt=PERSONA_PROMPT)
print(answer)Write a collection once, then query it
Turn on the memory cache so the documents are encoded once and each later question only attends over the cached keys and values.
model = MemoryVLLM.from_pretrained("memorilla/Memorilla-Qwen3-8B", "pmv2", memory_cache=True, compile_memory=True)
collection = model.write(row["documents"])
answer = model.answer(row["question"], collection, system_prompt=PERSONA_PROMPT)
Train on your own data
Write one parquet file per split with the columns collection_id, question, answer and documents under my_data/data/my_task/, then train and evaluate. The single_task recipe warm-starts from the Stage 2 checkpoint.
python train.py --config configs/single_task.yaml --data_repo my_data --datasets my_task --output_dir runs/my_task
python evaluate.py --data_repo my_data --config my_task --split test --scoring generation --checkpoint runs/my_task/epoch-04Commands and code are distilled from the project's own documentation — always check the official repo for the latest.
When to use it
- Reach for it to personalise an assistant from a user's whole chat history without stuffing every past conversation into the prompt
- Reach for it to answer questions over very long material such as books and scripts, where the README reports compression of more than 4,000× on NarrativeQA
- Reach for it as a learned alternative to top-k RAG when an answer depends on combining clues scattered across many documents
- Reach for it to research trainable agent memory, using its GRPO recipe on TextWorld games
How Memorilla compares
Memorilla alongside other open-source agent memory tools AI/TLDR tracks, ranked by GitHub stars.
| Tool | Stars | What it does |
|---|---|---|
| Claude-Mem | ★ 121k | Persistent memory layer for coding agents: it captures what an agent does during a session, compresses it into semantic summaries, and injects the relevant parts back into later sessions. |
| Mem0 | ★ 69.7k | A memory layer that you add to existing LLM agents to extract, store, and recall user facts and preferences across sessions using vector, graph, and key-value backends. |
| Hindsight | ★ 64.3k | An agent memory server that stores facts and experiences, consolidates them into observations and mental models, and serves them back through retain, recall, and reflect operations. |
| MemPalace | ★ 60.8k | Local-first agent memory that stores conversations verbatim instead of summarising them, with a structured palace index, pluggable vector backends and an MCP server. |
| OpenViking | ★ 43.1k | A context database that stores an agent's memories, resources, and skills as one browsable viking:// filesystem with three-tier (abstract/overview/details) on-demand loading. |
| Cognee | ★ 33.7k | A graph-native memory engine that turns raw documents and conversations into a queryable knowledge graph for agents that need to build lasting knowledge. |
| Graphiti | ★ 33.2k | A library that builds a temporal knowledge graph from an agent's conversations and data so facts can be tracked and queried as they change over time. |
| Memorilla | ★ 1.7k | Latent memory that packs a whole document collection into 16 tokens for a frozen LLM |
