Contrastive Retrieval Heads for Improved Attention-Based Reranking

Linh Tran, Yulong Li, Radu Florian, Stacy Patterson, Ana Milanova, Wei SunNeurIPS 2026

TL;DR

When you ask a Large Language Model (LLM) to find the best documents for a search query by inspecting its internal attention patterns, listening to every attention head actually hurts performance—most are just generating noise. By using a training-free, contrastive test to find the tiny fraction (<1%) of heads that simultaneously spotlight right answers and ignore plausible distractors, we get a dramatically better document reranker. Better yet, because these "Contrastive Retrieval" heads live almost exclusively in the middle of the neural network, you can chop off the top half of the model during inference—slashing memory and latency while keeping accuracy virtually intact.

What Problem Does This Paper Address?

Modern search engines and Retrieval-Augmented Generation (RAG) pipelines rely on a two-step dance: a fast, lightweight retriever grabs dozens of candidate documents, and a heavier "reranker" reads them carefully to put the best ones on top. Recently, researchers realized we can use long-context LLMs as fast, single-pass rerankers without waiting for them to generate text. Instead, we feed all the candidate documents and the query into the prompt, and simply measure how much attention the query tokens pay to each document's tokens.

The catch? An LLM has thousands of attention heads, and summing them all up (an approach called In-Context Reranking, or ICR) introduces massive redundancy and noise. Prior attempts to filter this down—like Query-Focused Retrieval (QR) heads—selected heads that paid the highest raw attention to relevant documents. However, reranking is fundamentally contrastive. A head that pays high attention to the right answer, and equally high attention to a tricky, near-duplicate wrong answer, is useless for sorting. As a result, picking heads based on positive attention alone can actually perform worse than just using all heads blindly.

Figure 1: nDCG@10 on Quora top-40.

Methods

The authors introduce CoRe (Contrastive Retrieval) heads and a resulting training-free reranker (CoRe-R).

Instead of training a model, they run a one-time, post-hoc "head detection" diagnostic (taking under an hour on a single GPU). They feed an open-weight LLM (like Mistral, Llama-3.1, Qwen-3, or Granite) prompts containing a query, 1 gold-standard positive document, and 49 "hard negatives" (plausible distractors).

  • What's standard: Computing a document's relevance score within a head by summing query-to-document attention, and applying contextual calibration (subtracting the baseline attention of a content-free dummy query like "N/A" to mitigate document-length bias).
  • What's new: Each head is evaluated using an InfoNCE-inspired softmax ratio ($S_{CoRe}$). This score measures how well a head concentrates probability mass on the true positive relative to the 49 hard negatives. The authors pick just the top 8 heads per model—fewer than 1% of all heads—and throw away signals from the rest during zero-shot reranking.

Datasets

No training occurs, and no brand-new benchmarks are introduced, though the authors curate specific slices of existing data:

  • Calibration / Head Detection: 1,000 samples from the Natural Questions (NQ) training set paired with hard negatives (plus BioASQ, SciFact, FiQA, and FEVER to test stability).
  • Evaluation: The 15-task BEIR benchmark for standard retrieval, BRIGHT for reasoning-intensive out-of-domain retrieval, MLDR for multilingual retrieval (6 languages), and MuSiQue for multi-hop reasoning. They also construct an extreme length-imbalance subset (>4,000 BEIR examples where the right answer is at most 20% the length of the longest distractor) to test length bias.

Key Insights and Ideas

  • Less is genuinely more: Retrieval computation in transformers is shockingly sparse. Performance peaks at just 4 to 9 heads; adding lower-ranked heads actively degrades accuracy by reintroducing noise.
  • Universal generalization: The exact same 8 heads found using general Wikipedia Q&A (NQ) generalize zero-shot to code, math, finance, multi-hop reasoning, and foreign languages. Swapping the calibration dataset changes 1 or 2 boundary heads at most.
  • Middle-layer localization: Across different model families, CoRe heads consistently cluster in the middle transformer layers, aligning with interpretability theories that middle layers handle rich semantic matching while upper layers prepare for next-token generation.
  • Free efficiency via layer pruning: Because the upper layers aren't needed once the middle-layer CoRe heads have spoken, you can completely slice off the final 50% of the LLM's layers during reranking without hurting accuracy.
  • Implicit length-bias defense: Sparse head selection naturally filters out "lazy" heads that blindly attend to long documents, making CoRe-R far more resilient to document-length bias even before calibration is applied.

Key Results

Across four 4B–8B models and a 70B Llama model, CoRe-R consistently beats dense retrievers, ICR, and QR-R.

  • Accuracy: On BEIR (top-40), CoRe-R boosts average nDCG@10 over QR-R by +2.0 points on Mistral-7B (reaching 50.9) and +3.8 points on Qwen3-4B (reaching 52.4). On Quora—a dataset packed with near-duplicate hard negatives—Qwen's QR-R collapses to 61.0, while CoRe-R hits 81.2.
Table 1: nDCG@10 on the BEIR benchmark top-40.
  • Long-Context Scaling: On Llama-3.1 8B, as candidate lists grow from top-40 to top-100 documents, baseline methods degrade slightly while CoRe-R actually improves, widening its lead.
Figure 3: Average nDCG@10 on BEIR with various top-k using Llama-3.1 8B.
  • Pruning Speedups: Pruning the top 50% of layers in Mistral and Llama preserves virtually identical BEIR accuracy while cutting GPU memory usage by ~40% and inference latency by ~20%, placing CoRe-R on the accuracy-latency Pareto frontier alongside GPT-4-based RankGPT and supervised rerankers.

Limitations and Future Work

Because attention-based rerankers require access to internal attention matrices, CoRe-R can only be used with open-weight models, ruling out closed APIs. Furthermore, the authors note that attention patterns are sensitive to prompt phrasing. Using a single universal QA-style instruction across all datasets caused rerankers to occasionally trail the base retriever on specialized tasks like duplicate-question detection (Quora) or counter-argument retrieval (ArguAna). Preliminary tests show task-specific prompts fix this, pointing toward automated prompt adaptation as a promising next step.

Summary updated

Abstract

The strong zero-shot and long-context capabilities of recent Large Language Models (LLMs) have enabled highly effective list-wise reranking systems. Attention-based rerankers leverage transformer attention patterns as retrieval signals, but not all attention heads contribute equally: many introduce noise and redundancy, limiting both reranking quality and efficiency. In this work, we introduce CoRe heads, a small subset of retrieval-specialized heads identified through a contrastive scoring objective that rewards attention to relevant documents while penalizing attention to distractors. This contrastive criterion isolates highly discriminative retrieval heads and yields a strong training-free list-wise reranker. Our analysis reveals that retrieval-relevant computation in transformer rerankers is highly sparse and structurally localized: fewer than 1% of attention heads account for most reranking performance across models and datasets, and these heads consistently concentrate in middle transformer layers. This localization enables aggressive layer pruning for efficient reranking: removing the final 50% of transformer layers preserves nearly identical reranking accuracy while substantially reducing inference latency and GPU memory usage.
BibTeX
@inproceedings{tran2026contrastive,
  author = {Linh Tran and Yulong Li and Radu Florian and Stacy Patterson and Ana Milanova and Wei Sun},
  title = {{Contrastive Retrieval Heads for Improved Attention-Based Reranking}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2026},
  url = {https://openreview.net/forum?id=el3L9KxeOE},
}
Figure