# HeadMem: Turning an LLM's Retrieval Heads into a Compact Memory for Later Question

> HeadMem stores compressed keys from selected LLM attention heads and uses each later question alone to choose context tokens for rereading. On Llama-3.1-8B's 128k RULER-MQ test, HeadMem+BM25's macro score was 73.9 versus BM25's 66.0 at a 2,048-token reading budget.

- arXiv: https://arxiv.org/abs/2611.41395
- Authors: Qingsen Ma, Dianyun Wang, Jiahong Liu, Yaoye Wang, Irwin King
- Published: 2026-12-01
- Topic: Inference & systems
- Visual carousel: https://instaxiv.com/p/2611.41395
- Explanation by InstaXiv, a secondary educational summary. Cite the original paper for exact results. InstaXiv is not affiliated with or endorsed by arXiv or Cornell University.

## Can an LLM keep evidence without its whole cache?

**290×** less memory/token than Llama-3.1-8B bf16 KV

## When context comes before questions

**Full KV cache:** Llama-3.1-8B's bf16 cache takes 16 GiB at 128k tokens, preserving every position.

**KV eviction:** It fixes a subset before later questions are known, so dropped positions cannot be recovered.

HeadMem uses compact keys and the frozen LLM's heads, with no second neural retriever.

## How HeadMem identifies its retrieval heads

![Figure 2](https://cdn.instaxiv.com/figures/2611.41395/figure2.webp)

On a separate 80-question split, each bare question is read alone. Heads are ranked by attention mass on gold-answer tokens; the top 16 are selected once per model. (Figure 2)

## Build once; retrieve per question

1. **Index each context once**: Run the frozen LLM on 4,096-token chunks; store product-quantized (PQ-32) selected-head keys and token IDs, not values. This lets indexed contexts exceed its window.
2. **Score the bare question**: Forward each question alone; each selected head's softmax scores every stored position. Average over question tokens, then sum head scores.
3. **Reread selected text**: Smooth scores, select 2,048 context tokens, restore original order, then let the full LLM answer.

## A narrow raw edge, not a significant win

| Method | Macro score (×100) |
| --- | --- |
| BM25 | 66.0 |
| Dense RAG + reranker | 66.2 |
| BM25 + dense | 72.5 |
| **HeadMem + BM25 (+1.4 pts)** | **73.9** |

_Llama-3.1-8B RULER-MQ, 128k; 8 questions/context, B=2,048. HeadMem+BM25 fixed w=0.5; BM25+dense dev-tuned. Δ=+1.40, 95% CI [-1.40,+4.24]._

## Ablations isolate the retrieval signal

![Figure 3](https://cdn.instaxiv.com/figures/2611.41395/figure3.webp)

On Llama-3.1-8B development answer-presence tests, aggregating all heads stays near random; a per-head softmax over detected heads with exact keys rises above BM25. (Figure 3)

## Split the reading budget between cache and retrieval

| Method | Macro score (×100) |
| --- | --- |
| StreamingLLM (2,048 entries) | 12.1 |
| SnapKV (2,048 entries) | 13.4 |
| KVzip (2,048 entries) | 22.3 |
| **KVzip + HeadMem** | **69.1*** |

_RQ3: Llama RULER-MQ, 64k (episodes 0-5); combo uses 1,024 KV entries + 1,024 HeadMem tokens. *Significant vs KVzip._

## HeadMem helps when query and needle barely overlap

| Method | Character-name match (%) |
| --- | --- |
| FullKV | 31.7 |
| BM25 | 9.0 |
| Dense RAG + reranker | 20.7 |
| **HeadMem (448 B/token)** | **34.8** |

_NoLiMa, Llama-3.1-8B, 8k, n=290; retrieval B=2,048, FullKV all 8k. Paired HeadMem-FullKV Δ=+3.06, 95% CI [-2.33,+8.44], not significant._

## HeadMem-2 is 13× faster across eight queries

**FullKV:** On an idle H200 NVL, FullKV takes 21.73 s end-to-end for eight questions on a 128k Llama-3.1-8B context.

**HeadMem-2:** Two layer-2 heads share one KV head: 32 B/token and 1.63 s end-to-end for eight questions. Its 128k RULER-MQ macro score is 70.4 vs FullKV's 69.4.

The score difference is not significant; that does not establish equivalence.

## Where this memory still misses

- **Answer locations shape detection**: Per model, 80 RULER-MQ questions with located gold answers rank the heads; removing the two QA families sharply lowers Llama's retrieval scores.
- **Chains expose a retrieval gap**: At 128k on Llama variable tracking, the score is 35.8; supplying all five chain statements in the 2,048-token selection raises it to 98.8.
- **Results vary by model**: On Mistral-7B, HeadMem alone trails BM25 at 64k and 128k; its fusion is not significantly different from BM25 there.

Best used when: Best when one context serves later questions and query tokens can point toward evidence; fuse with another retriever when useful.

## Key takeaways

- Compressed keys keep every context position reachable without retaining the full KV cache.
- For repeated queries, index once, then use the frozen model's detected heads to select 2,048 tokens for rereading.
- The open problem is finding later linked facts after retrieval finds only the chain's first statement.

## Links

- arXiv: https://arxiv.org/abs/2611.41395
- PDF: https://arxiv.org/pdf/2611.41395

## Citation

```bibtex
@article{ma2026headmem,
  title   = {HeadMem: Turning an LLM's Retrieval Heads into a Compact Memory for Later Question},
  author  = {Ma, Qingsen and Wang, Dianyun and Liu, Jiahong and Wang, Yaoye and King, Irwin},
  journal = {arXiv preprint arXiv:2611.41395},
  year    = {2026},
  url     = {https://arxiv.org/abs/2611.41395}
}
```
