Retrieval Heads are Dynamic

Yuping Lin, Zitao Li, Yue Xing, Pengfei He, Yingqian Cui, Yaliang Li, Bolin Ding, Jingren Zhou, Jiliang TangarXiv 2026

TL;DR

This paper challenges the conventional view that "retrieval heads" in Large Language Models (LLMs) are a fixed, static subset of attention heads. Instead, the authors demonstrate that retrieval heads are highly dynamic, shifting token-by-token during text generation, and that their future activation patterns are surprisingly predictable from the model's internal hidden states. Leveraging these dynamic heads in a Retrieval-Augmented Generation (RAG) framework yields substantial performance gains over static alternatives.

What Problem Does This Paper Address?

To extract information from massive input contexts, LLMs rely on specialized attention heads known as retrieval heads, which are responsible for "copy-pasting" relevant tokens from the prompt into the generated output.

Prior mechanistic interpretability research has typically identified these heads by aggregating attention statistics across entire datasets, treating them as a fixed, static group of "generalist" heads. However, this average-case perspective completely overlooks the fine-grained temporal dynamics of autoregressive generation. A head that is statistically dominant on average might be idle during a critical token generation step, while a "less significant" head might be entirely irreplaceable in a specific context. The authors set out to investigate whether retrieval heads are actually a dynamic set conditioned step-by-step on the generation state.

Methods

The authors analyze retrieval heads through three core lenses:

  1. Dynamic Tracking: They define token-level retrieval scores for both exact token matching (in copy-paste tasks) and a relaxed, attention-proportion metric for reasoning tasks.
  2. Head Ablation: To test if dynamic heads are truly unique, they perform controlled ablation studies—masking out dynamic heads, top static heads, or random heads at specific timesteps to observe the degradation in model performance.
  3. Predictability Probing: They apply Canonical Correlation Analysis (CCA) and train Multi-Layer Perceptron (MLP) probes on the model's final hidden states to determine if the LLM encodes a predictive signal for future retrieval head activations.
  4. Dynamic RAG Integration: They adapt a dynamic RAG framework (DRAGIN), substituting full context retrieval with targeted attention unmasking based on the top positions attended to by the predicted dynamic retrieval heads.

Datasets

The approach was evaluated using two primary tasks:

  • Needle-in-a-Haystack (NIAH): A synthetic benchmark testing the retrieval of a specific piece of information hidden inside a long document. To prevent data leakage from training sets, the authors used dynamically generated UUID strings as the "needle."
  • HotpotQA: A multi-hop question-answering dataset that requires the model to find and integrate multiple discrete supporting facts across a long context, moving beyond simple token copying into true semantic reasoning.

Key Insights and Ideas

  • Retrieval is a Relay Race, Not a Solo Act: Attention heads fluctuate wildly in their retrieval behavior from token to token. As shown in Figure 1, different heads activate and deactivate dynamically across the generation steps.
Figure 1: Dynamism of Retrieval Heads. The retrieval scores of individual attention heads fluctuate across the generation process. Dark color indicates heads having a retrieval score of 1, as defined by Equation (1). The x-axis denotes the generation step, labeled by the token generated at that step. The y-axis shows the 10 most variated retrieval heads, selected based on their retrieval score variance over the entire generation process. Lx- Hy denotes the y-th head (starting from 0) on the layer x (starting from 0).
  • Dynamic Heads are Irreplaceable: When the active dynamic heads at a specific step are masked, the model's retrieval capability collapses. Crucially, the top-ranked static heads cannot step in to fully compensate for this loss, proving that retrieval functionality is context-specific and highly localized in time.
  • LLMs Plan Their Retrieval Ahead of Time: There is an incredibly strong linear correlation between the model's hidden state at timestep $n$ and the retrieval head activations at future timesteps $n+1$ and $n+2$. This implies that the model's internal state acts as a predictive planning mechanism for retrieval operations before they are executed.

Key Results

  • Severe Ablation Degradation: Masking dynamic retrieval heads caused catastrophic drops in NIAH accuracy to near 0% across almost all context lengths and depths, far exceeding the damage caused by masking static or random heads.
Figure 2: Impact of Head Ablation on Retrieval Performance. Comparison of NIAH test scores after masking three different sets of attention heads: dynamic retrieval heads, top-ranked static retrieval heads, and randomly selected heads on llama3.1-8b. The x-axis shows different haystack lengths. The y-axis shows the different locations (“depth”) where the needle is inserted. The evaluation metric is Accuracy (exact string match). The average number of masked heads is kept consistent across all conditions. Masking dynamic heads (identified at each timestep via Eq. (1)) results in the most significant performance degradation, indicating their critical role in retrieval.
  • High Decoding Accuracy: The MLP probes successfully predicted future head activations from hidden states, achieving high F1-scores (0.80 to 0.86) and AU-PRC values exceeding 0.88 across multiple open-source models (including Llama-3.1-8B and Qwen3-8B).
  • Dynamic RAG Superiority: In the HotpotQA case study, dynamically selecting heads via the MLP probe outperformed the static head selection baseline across 4 out of 5 models. For Llama-3.1-8B, the dynamic strategy boosted the F1-score from 0.5098 to 0.5586—nearly a 10% relative improvement.

Limitations and Future Work

While compelling, the authors note a few limitations:

  • Simulated RAG: The dynamic RAG case study utilized attention masking to simulate retrieval rather than physically fetching and concatenating text chunks as done in production RAG pipelines.
  • Probe Imperfection: The MLP probe is highly accurate but not an oracle; prediction errors can introduce noise into the retrieval process.
  • Task Scope: The analysis focused primarily on retrieval-intensive QA tasks. Whether these dynamic patterns hold true for other long-context tasks like abstractive summarization remains an open question.

Future Directions: The authors highlight that these findings open the door to dynamic KV cache compression (evicting or loading KV pairs on the fly based on predicted head activations) and token-level hallucination detection (flagging factual claims generated when no internal retrieval heads are active).

Summary updated

BibTeX
@misc{lin2026retrieval,
  author = {Yuping Lin and Zitao Li and Yue Xing and Pengfei He and Yingqian Cui and Yaliang Li and Bolin Ding and Jingren Zhou and Jiliang Tang},
  title = {{Retrieval Heads are Dynamic}},
  year = {2026},
  eprint = {2602.11162},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2602.11162},
}
Figure