← back

BlockRank: A Faster, Smarter Way to Rank Documents with LLMs

BlockRank is a novel method for in-context ranking that uses structured sparse attention and contrastive training to improve LLM efficiency and accuracy.

Listen

Large language models are transforming how we search for information, especially through a process called in-context ranking. This is where a model looks at a query and a list of documents to find the best match. But as the document list grows, the computational cost skyrockets. Standard models scale quadratically, meaning doubling the documents can quadruple the processing time.

To solve this, researchers have introduced BlockRank. It relies on a key insight: when ranking documents, the model's attention is naturally sparse. It doesn't need to connect every single word across different documents.

BlockRank changes how the model pays attention. Document words only look at other words in the same document. Meanwhile, the query words look at everything to make the final decision. This simple shift drops the computational complexity from quadratic to linear.

To make it even faster, BlockRank uses a special training method that teaches query words to point directly to the right answer. Instead of slowly generating text word-by-word, the system can simply read the model's internal attention scores to rank the documents instantly.

The results are impressive. BlockRank is nearly five times faster than standard models, and it can rank hundreds of documents in less than a second. Best of all, it actually improves accuracy, outperforming existing state-of-the-art rankers.

Large Language Models (LLMs) have revolutionized many areas of natural language processing, and information retrieval is no exception. A promising new paradigm called In-Context Ranking (ICR) leverages the contextual understanding of LLMs to re-rank a list of candidate documents for a given query. However, this power comes at a cost: the computational complexity of the attention mechanism in LLMs scales quadratically with the length of the input context, making it slow and expensive to rank a large number of documents.

Enter BlockRank, a novel method proposed in a recent paper by researchers from UT Austin and Google [1]. BlockRank tackles the efficiency bottleneck of ICR head-on, delivering impressive performance gains without sacrificing accuracy. In this blog post, we’ll dive into the key ideas behind BlockRank, explore its performance, and take a look at the open-source implementation.

The Challenge with In-Context Ranking

In-Context Ranking works by feeding the LLM a prompt containing the query, a list of candidate documents, and a task description. The LLM then identifies the most relevant document(s) from the list. While this approach is effective, it becomes computationally expensive as the number of documents increases. The self-attention mechanism, a core component of LLMs, has a computational complexity of O(n²), where ‘n’ is the length of the input sequence. This means that doubling the number of documents can quadruple the computation time, making it impractical for real-world applications with large candidate lists.

BlockRank’s Key Insights

The authors of the BlockRank paper made two key observations by analyzing the attention patterns of an LLM fine-tuned for ICR:

  1. Inter-document block sparsity: The attention mechanism is not uniformly dense. Instead, it exhibits a block-sparse structure where attention is dense within each document but sparse across different documents.
  2. Query-document block relevance: Certain tokens in the query, particularly those at the end, develop strong attention weights towards the relevant document’s tokens in the middle layers of the model. These
  3. tokens act as “retrieval heads,” effectively pointing to the correct answer.

How BlockRank Works: A Two-Pronged Approach

Based on these insights, BlockRank introduces two key innovations to the standard LLM architecture and fine-tuning process:

1. Structured Sparse Attention

BlockRank modifies the attention mechanism to enforce the observed block sparsity. This is achieved by restricting the attention flow as follows:

  1. Document tokens only attend to other tokens within the same document and to the initial instruction tokens.
  2. Query tokens attend to all tokens in the prompt (instructions and all documents) to gather the necessary context for ranking.

This structured attention pattern reduces the computational complexity from quadratic (O(n²)) to linear (O(n)), resulting in a significant speedup in both training and inference.

2. Auxiliary Contrastive Training

To enhance the

retrieval signal from the query tokens, BlockRank introduces an auxiliary contrastive loss during fine-tuning. This loss encourages the model to increase the attention scores from the query to the relevant document(s) and decrease the scores for irrelevant ones. This not only improves the model’s ability to identify the correct document but also enables a much faster inference method.

Attention-Based Inference

Thanks to the auxiliary contrastive training, the attention scores from the query to the documents become a reliable indicator of relevance. This allows BlockRank to bypass the traditional auto-regressive decoding process, where the model generates the answer token by token. Instead, it can directly use the attention scores from a specific middle layer to rank the documents. This attention-based inference is significantly faster than decoding and is the recommended approach for using BlockRank.

Performance: Faster and More Accurate

The BlockRank paper presents a comprehensive evaluation of the method on several standard information retrieval benchmarks. The results are impressive:

  1. State-of-the-art performance: On the BEIR benchmark, BlockRank outperforms existing state-of-the-art listwise rankers like FIRST, RankZephyr, and RankVicuna.
  2. Significant speedup: BlockRank is 4.7 times faster than a standard fine-tuned Mistral-7B model when ranking 100 documents.
  3. Scalability: BlockRank can rank up to 500 documents (approximately 100,000 tokens) in under a second, with its latency scaling linearly with the number of documents.

Here’s a summary of the key results from the paper:

MetricBlockRank MistralFull-FT MistralFIRST (SOTA)BEIR nDCG@1054.8–54.3MSMarco P@129.1%28.7%–MSMarco MRR@1042.038.3–

As the table shows, BlockRank not only surpasses the performance of the standard fine-tuned model but also the previous state-of-the-art on the BEIR benchmark.

Open-Source Implementation

The authors have released the code for BlockRank on GitHub [2], making it easy for researchers and practitioners to use and build upon their work. The repository includes:

  1. The core BlockRank attention implementation in both standard PyTorch and optimized Triton kernels.
  2. The auxiliary attention loss module.
  3. Training and evaluation scripts.
  4. A pre-trained BlockRank model based on Mistral-7B, available on Hugging Face.
  5. A quickstart notebook to help you get started.

The code is well-documented and provides a solid foundation for experimenting with BlockRank on your own datasets.

Conclusion

BlockRank is a significant step forward in making LLM-based in-context ranking more practical and accessible. By identifying and exploiting the inherent structure of the attention mechanism for this task, the authors have developed a method that is both faster and more accurate than existing approaches. The open-source release of the code and a pre-trained model further lowers the barrier to entry for using this powerful technique.

As LLMs continue to grow in size and capability, methods like BlockRank that focus on efficiency and scalability will become increasingly important. We’re excited to see how the community will build upon this work and apply it to new and challenging information retrieval problems.

References

[1] Gupta, N., You, C., Bhojanapalli, S., Kumar, S., Dhillon, I., & Yu, F. (2025). Scalable In-context Ranking with Generative Models. arXiv preprint arXiv:2510.05396. https://arxiv.org/abs/2510.05396

[2] BlockRank GitHub Repository. https://github.com/dejanai/BlockRank

Dan Petrovic · Nov 10, 14:53