Papers › Query-Focused Retrieval Heads Improve Long-Context Reasoning and Re-ranking

Query-Focused Retrieval Heads Improve Long-Context Reasoning and Re-ranking

11 Jun 2025arXiv:2506.09944archive 2025-07-28

Wuwei Zhang, Fangcong Yin, Howard Yen, Danqi Chen, Xi Ye

Recent work has identified retrieval heads (Wu et al., 2025b), a subset of attention heads responsible for retrieving salient information in long-context language models (LMs), as measured by their copy-paste behavior in Needle-in-a-Haystack tasks. In this paper, we introduce QRHEAD (Query-Focused Retrieval Head), an improved set of attention heads that enhance retrieval from long context. We identify QRHEAD by aggregating attention scores with respect to the input query, using a handful of examples from real-world tasks (e.g., long-context QA). We further introduce QR- RETRIEVER, an efficient and effective retriever that uses the accumulated attention mass of QRHEAD as retrieval scores. We use QR- RETRIEVER for long-context reasoning by selecting the most relevant parts with the highest retrieval scores. On multi-hop reasoning tasks LongMemEval and CLIPPER, this yields over 10% performance gains over full context and outperforms strong dense retrievers. We also evaluate QRRETRIEVER as a re-ranker on the BEIR benchmark and find that it achieves strong zero-shot performance, outperforming other LLM-based re-rankers such as RankGPT. Further analysis shows that both the querycontext attention scoring and task selection are crucial for identifying QRHEAD with strong downstream utility. Overall, our work contributes a general-purpose retriever and offers interpretability insights into the long-context capabilities of LMs.

PaperPDFCodeCode Syntology ran

In Syntology Open this paper in Syntology's Atlas, the map of the papers in Syntology's graph and their citations.

For agents, Syntology's MCP tool lists every function and class Syntology harvested from this paper and whether it ran (how to connect): get_harvested_code_for_paper(arxiv_id="2506.09944")

Code

Syntology Ran 5 of 18 code samples harvested from 1 repository linked to this paper; 13 have no recorded run. Of those that ran: 3 ran · our draft was wrong; 2 ran · fixture could not drive it.

By repository: official repository: 18 samples from 1 repository, 5 ran. The run record, sample by sample. “Ran” means executed on a synthesized input, not that the code is correct or reproduces the paper.

princeton-pli/qrhead officialmentioned in papermentioned on GitHubpytorchMIT report

Repository list and official/mentioned flags are the archive's, frozen 2025-07-28. Reachability, where shown, is from one Syntology probe window (2026-09-16 to 2026-09-18); repositories not probed show nothing. GitHub stars are not tracked.

Code Syntology ran Syntology

18 samples harvested; 5 ran; 0 honoured the contract we drafted; 13 have no recorded run. Read from Syntology's graph 2026-09-24; that is when this build read the record, not when the samples ran.

3ran · our draft was wrong
2ran · fixture could not drive it
13unverified

Licence: 0 of the 18 samples are pointer only, meaning Syntology does not serve that copy's text. This page shows no code text for any sample; each one links to its file in the repository.

Harvested from princeton-pli/QRHead. “Ran” means the sample executed on a synthesized input. It does not mean the output is correct, and nothing here reproduces the paper's results. “Honoured” and “violated” refer to a contract Syntology drafted from the code itself; “our draft was wrong” and “fixture could not drive it” are failures of Syntology's instrument, not of the code.

Each sample ends with its code_sha256, Syntology's identity for that exact code. An agent fetches the stored sample with Syntology's MCP tool get_code(code_sha256="…") (how to connect); click an identity to copy that call.

Repository labels, per sample. official repository: The archive marks this repository official for the paper. named in the paper: The archive records that the paper mentions this repository; it is not marked official. community (archive-listed): In the archive's code links for this paper, not marked official and not recorded as mentioned in the paper. found in paper text by Syntology: Syntology found this repository in the paper's own text; whether it is the authors' implementation is not asserted. community: Not in the archive's code links for this paper; a community repository Syntology harvested. Samples from a repository marked official are listed first. Licence labels name the repository's licence as recorded at harvest. “Pointer only” means Syntology does not serve that copy's text, for one of four reasons: no licence file was found; the licence was not identified; the licence is recorded as permissive but that copy's record is not marked cleared; or the licence is outside the permissive list Syntology serves text under (MIT, Apache-2.0, BSD and similar). Some licences outside that list permit redistribution, such as WTFPL, and GPL-3.0 under its conditions; they are simply not on the list. Hover a licence label for the reason. File links open the file on GitHub at the default branch, which may have changed since the harvest.

repeat_kv princeton-pli/QRHead/src/qrretriever/custom_modeling_llama.py official repository ran · fixture could not drive it fingerprinted MIT (permissive) · 30d7eec482ebf6b1 · report
apply_rotary_pos_emb princeton-pli/QRHead/src/qrretriever/custom_modeling_qwen2.py official repository ran · fixture could not drive it MIT (permissive) · d61c483a3c2b3156 · report
apply_rotary_pos_emb princeton-pli/QRHead/src/qrretriever/custom_modeling_llama.py official repository ran · our draft was wrong MIT (permissive) · bac65c3dafaec040 · report
get_anscheck_prompt princeton-pli/QRHead/exp_scripts/generation/eval_generation_lme.py official repository ran · our draft was wrong fingerprinted MIT (permissive) · 8e4f7c8ecedd17fa · report
rotate_half princeton-pli/QRHead/src/qrretriever/custom_modeling_llama.py official repository ran · our draft was wrong fingerprinted MIT (permissive) · b99eea6376d1e212 · report
compute_recall princeton-pli/QRHead/exp_scripts/retrieval/eval_retrieval.py official repository unverified MIT (permissive) · 6485b6194332b150 · report
extract_relevant_rounds princeton-pli/QRHead/exp_scripts/generation/run_generation_lme.py official repository unverified MIT (permissive) · 63bfa7b825473d3d · report
generate_prompt princeton-pli/QRHead/exp_scripts/generation/run_generation_lme.py official repository unverified MIT (permissive) · f8bf3d9d30b922e6 · report
get_doc_scores_per_head princeton-pli/QRHead/exp_scripts/detection/detect_qrhead_beir.py official repository unverified MIT (permissive) · d81d0dbbee1e8828 · report
get_doc_scores_per_head princeton-pli/QRHead/exp_scripts/detection/detect_qrhead_lme.py official repository unverified MIT (permissive) · 009654fea103956a · report
get_top_k_docs princeton-pli/QRHead/exp_scripts/retrieval/eval_retrieval.py official repository unverified MIT (permissive) · 30515a995de52d2d · report
get_topk_doc_idx princeton-pli/QRHead/exp_scripts/generation/run_generation_clipper.py official repository unverified MIT (permissive) · 84ed72a7f256783d · report
lme_eval princeton-pli/QRHead/exp_scripts/detection/detect_qrhead_lme.py official repository unverified MIT (permissive) · 46d639c95b19b2e5 · report
load_config princeton-pli/QRHead/src/qrretriever/config.py official repository unverified MIT (permissive) · 229e3b5a73665fb2 · report
merge_configs princeton-pli/QRHead/src/qrretriever/config.py official repository unverified MIT (permissive) · 1b2be7c22837418d · report
parse_file princeton-pli/QRHead/exp_scripts/generation/eval_generation_clipper.py official repository unverified MIT (permissive) · 1340e53f675329ea · report
prepare_prompt_for_generation princeton-pli/QRHead/exp_scripts/generation/run_generation_clipper.py official repository unverified MIT (permissive) · ff68a23061cdf19a · report
score_heads princeton-pli/QRHead/exp_scripts/detection/detect_qrhead_lme.py official repository unverified MIT (permissive) · b3336deddac204eb · report

Tasks

Re-RankingRetrieval

Results from the paper archive 2025-07-28

No leaderboard rows for this paper in the archive.

Methods

AttentionCopy-PasteSETSoftmax

Report a problem or propose a change · a person checks every report against the paper or source before anything changes; decisions are listed on /corrections