HeadMem: Turning an LLM's Retrieval Heads into a Compact Memory for Later Question
Documents, codebases and agent histories are read long before their questions arrive and are then queried many times. Their memory may serve any later question. Compressing the KV cache before the questions keeps this memory small but loses the evidence. Storing the full cache keeps the evidence but costs gigabytes per document, and dense retrievers bring an embedding model and an index of their own. We show that the LLM already contains a retriever that keeps the memory small and still finds the evidence. Its retrieval heads, detected once per model, find the evidence even when they read the question alone. They are token-matching heads, and masking them hurts the model's own long-context reading far more than masking random heads. \ours{} stores only the compressed keys of these heads, using $290\times$ less memory than the KV cache of Llama-3.1-8B. For each question, the heads' own softmax selects the tokens the model re-reads. It needs no training, no model besides the LLM and no pass over the context per question. On multi-question RULER-style contexts, \ours{} alone beats four KV compression methods by a wide margin. Because it only proposes tokens to re-read, it combines…
- arXiv
- 2611.41395
- Authors
- Qingsen Ma, Dianyun Wang, Jiahong Liu, Yaoye Wang, Irwin King
- Categories
- cs.AI