Attention in Large Language Models Yields Efficient Zero-Shot Re-Rankers

Shijie Chen, Bernal Jimenez Gutierrez, Yu Su

Introduction

Information retrieval (IR) systems increasingly rely on Large Language Models (LLMs) for zero-shot re-ranking to ensure the most relevant documents appear at the top of search results. However, traditional LLM-based re-ranking relies on text generation, which is computationally expensive and slow.

Researchers have developed In-Context Re-ranking (ICR), a novel method that transforms LLMs into highly efficient search re-rankers by analyzing their internal attention patterns rather than asking them to generate text. This approach reduces latency by over 60% and allows smaller, open-weight models to match or outperform proprietary giants in ranking accuracy.

The Problem with Generative Re-ranking

In a standard "retrieve-then-re-rank" pipeline, a fast system (like BM25) retrieves a broad set of documents, and a more complex model re-orders them. Recently, LLMs have become the gold standard for this step using generative re-ranking (e.g., RankGPT), where the model is prompted to output a ranked list of document identifiers.

This generative approach has two major drawbacks:

  1. Efficiency: It requires at least $O(N)$ forward passes (where $N$ is the number of documents) because the model generates tokens sequentially. This makes the process slow and computationally expensive.
  2. Reliability: Smaller models often struggle to follow complex formatting instructions, leading to malformed outputs and "broken" rankings.

The authors hypothesize that autoregressive generation is not strictly necessary. Instead, the "knowledge" of relevance is already encoded within the model's internal states during the reading phase.

Methodology: In-Context Re-ranking (ICR)

To bypass text generation entirely, the authors propose In-Context Re-ranking (ICR), which directly leverages the model's attention weights. The process involves three main steps:

  1. Prompting: The model receives a prompt containing the retrieved documents followed by the search query. Placing the query at the end ensures the model attends to the preceding documents based on the query's context.
  2. Attention Aggregation: As the model processes the query tokens, it naturally "attends" to the document tokens. ICR aggregates these attention weights across all layers and attention heads to compute a raw relevance score for each document.
  3. Calibration: LLMs exhibit intrinsic biases, such as favoring documents at the beginning of a list or focusing on specific punctuation. To mitigate this, ICR performs a second pass using a "content-free" query (e.g., "N/A"). By subtracting the attention scores of this calibration query from the actual query's scores, ICR isolates the true relevance signal.
Overview of the In-Context Re-ranking (ICR) method, highlighting the attention aggregation and calibration steps.

Because ICR only requires one forward pass for the input and one for calibration, its computational complexity is $O(1)$ relative to the number of documents, making it substantially faster than generative methods.

Experimental Setup

The researchers evaluated ICR across a variety of standard IR benchmarks:

  • Single-hop (BEIR): Datasets like TREC-COVID, SciFact, FiQA, and NFCorpus test the model's ability to find a single document that directly answers a query.
  • Multi-hop: Datasets like MuSiQue, 2WikiMultiHopQA, and HotpotQA require the model to synthesize information across multiple documents to determine relevance.

Key Results and Insights

ICR demonstrates that an LLM’s internal attention mechanism is a highly sensitive instrument for determining relevance, often capturing deeper semantic links better than text-generation outputs, which can be easily skewed by position biases or superficial word-matching.

  • Speed and Efficiency: In practical tests, ICR cut latency by more than 60% compared to RankGPT.
  • Superior Performance: Using the open-weight Llama-3.1 8B model, ICR outperformed RankGPT by 8.4 points on single-hop tasks and 2.2 points on multi-hop tasks.
  • Closing the Gap: ICR enables an 8-billion parameter open-source model to match the performance of much larger proprietary models, like GPT-4o mini, on several retrieval benchmarks.
  • Guaranteed Formatting: Because it relies on internal states rather than generated text, ICR guarantees a well-formed ranking every time.
Comparison of latency and performance between ICR and RankGPT across different numbers of retrieved documents (K).

Furthermore, the calibration step proved essential; without it, performance dropped significantly due to the model's natural distraction by document positions. ICR also excelled in complex reasoning tasks, such as fact-checking, where it successfully identified documents that contradicted a claim—a task where generative models often fail due to high lexical overlap.

Limitations and Future Work

While highly effective, ICR is not without limitations:

  • Lexical Bias: ICR still exhibits some bias toward exact word matches, occasionally over-ranking documents that share many words with the query but lack semantic relevance.
  • Adversarial Vulnerability: Because the method relies on attention weights, malicious actors could potentially inject specific phrases into documents to artificially inflate their attention scores and ranking.
  • Architecture Specificity: The current implementation is designed for decoder-only LLMs. Future research could adapt ICR for encoder-decoder architectures or emerging long-context models.

By shifting the paradigm from what an LLM generates to what it attends to, ICR offers a promising blueprint for building faster, more efficient, and highly intelligent search systems.

Summary updated

BibTeX
@inproceedings{chen2025attention,
  author = {Shijie Chen and Bernal Jimenez Gutierrez and Yu Su},
  title = {{Attention in Large Language Models Yields Efficient Zero-Shot Re-Rankers}},
  booktitle = {International Conference on Learning Representations},
  year = {2025},
  url = {https://openreview.net/forum?id=yzloNYH3QN},
}
Figure