Özer Cem KELAHMETKELAHMET
Articles · Reranking

Reranking for RAG: cross-encoders, LLM rerankers and the latency and cost of each

First-stage retrieval is fast but rough. A reranker reads each candidate with the question and puts the best passages on top. This guide explains cross-encoders and LLM rerankers, works nDCG by hand, and prices reranking in tokens, calls and milliseconds.

Download Markdown
At a glance
Reading time
14 min
Sections
7
Code examples
4
Tables
2
Sources
8
Published
24 Nov 2026
In 30 seconds
What changed
RankLLM 0.26.0 published to PyPI
Why it matters
For most RAG systems the right default is a small cross-encoder reranking the top 20 to 50 candidates from a hybrid retriever, passing the best three to five to the model.
What to do
Measure first-stage recall at 50 and 100

Retrieval in a retrieval-augmented generation (RAG) system usually happens twice. The first stage, keyword or vector search, scans millions of chunks in milliseconds and returns a rough top 50 or 100. The second stage, the reranker, reads each of those candidates carefully alongside the question and reorders them, so that the three to five passages that reach the language model are the best ones available.

Reranking is often the single most effective upgrade after hybrid search, and it is also where RAG latency and cost can quietly grow. This autumn the main open-source toolkit for large language model (LLM) rerankers published its first PyPI release in over a year, and the most used cross-encoder library kept its reranker models in a fast-moving core package. This article explains why rerankers are more accurate than first-stage retrievers, compares cross-encoders with pointwise, pairwise and listwise LLM rerankers, works the main ranking metric by hand, and prices each option.

An analogy: first-stage retrieval is a recruiter skimming 1,000 CVs for keywords to make a shortlist of 50. Reranking is the hiring manager reading those 50 in full against the job description. You would never ask the manager to read all 1,000, and you would not hire straight from the keyword skim.

What happened

RankLLM 0.26.0 published to PyPI (22 October 2026)

RankLLM, the reranking toolkit from the University of Waterloo's Castorini group, released 0.26.0 on PyPI on 22 October 2026. The previous PyPI release was 0.25.7 on 25 August 2025. The project description lists pointwise rerankers such as MonoT5, pairwise rerankers such as DuoT5, listwise rerankers built on open models served with vLLM, and the proprietary listwise variants RankGPT and RankGemini. It also supports reranking from first-token logits only, to cut inference cost. The README's news section records a new rank-llm command-line interface added on 26 March 2026, and its install matrix now includes extras for an HTTP API and an MCP server, so a reranker can be exposed to agents as a tool.

Sentence Transformers 6.3.0 keeps cross-encoders in the core library (11 November 2026)

Sentence Transformers 6.3.0 was released on 11 November 2026. The README's reranker example loads cross-encoder/ms-marco-MiniLM-L6-v2 with the CrossEncoder class and scores three passages about Berlin for the query "How many people live in Berlin?". The passage giving the population scores 8.607, ahead of 6.353 for a passage about sports clubs and 5.506 for one about visitors. A rank method returns the passages already sorted, which is the whole reranking step in one call.

Why a reranker is more accurate

Bi-encoders compress; cross-encoders compare

A first-stage dense retriever is a bi-encoder. It encodes the question and each passage separately into one vector each, then compares the vectors. That separation is what makes it fast, since passages are encoded once and stored, but it means the model never sees the question and the passage together. Everything about the passage must be squeezed into one vector before the question is known.

A cross-encoder takes the question and the passage as a single input, separated by a special token, and runs a transformer over both. Every word of the question can attend to every word of the passage. The output is one relevance score. The model can notice that the passage mentions "Berlin" but answers a different question, or that a negation flips the meaning. The price is that nothing can be precomputed: each question-passage pair needs its own forward pass.

Table 1. Bi-encoders compress; cross-encoders compare
Model type Input Precompute documents? Typical use Relative cost per candidate
Bi-encoder (dense) Query and passage separately Yes First stage over millions Very low
Late interaction (ColBERT) Token vectors for each, compared with MaxSim Yes, one vector per token First stage or reranking Low, more storage
Cross-encoder Query and passage together No Rerank 20 to 200 candidates Medium
LLM reranker Query and one, two or many passages in a prompt No Rerank the hardest top 20 to 100 High

The site's cross-encoder reranking page covers the architecture, and the rerank RAG simulation shows the reorder step live. Late interaction is covered on the ColBERT page.

LLM rerankers: pointwise, pairwise, listwise

Large language models can rerank too, in three styles.

  • Pointwise: ask the model to score one passage at a time, for example the probability of answering "yes" to "is this passage relevant?". MonoT5 is the classic example. Cost grows linearly with candidates.
  • Pairwise: ask which of two passages is more relevant. DuoT5 works this way. It is accurate but the number of comparisons grows quickly, so it is used on a very short list.
  • Listwise: give the model a list of passages and ask for a ranked list of their identifiers. RankGPT introduced the sliding-window method: rank a window of 20 passages, slide the window up the list by 10, and repeat, so the best passages bubble to the top. Listwise models see the candidates side by side, which helps with fine distinctions.

Listwise ranking with a capable LLM is often the most accurate option and the most expensive. Distilled listwise models served locally, the focus of toolkits like RankLLM, aim to keep most of the quality at a fraction of the cost.

Measuring a reranker: nDCG by hand

The standard metric is normalised discounted cumulative gain at k (nDCG@k), one of the ranking measures on the site's evaluation metrics page. Each passage has a graded relevance, for example 2 for "answers the question", 1 for "related" and 0 for "not relevant". Gains are discounted by position:

DCG@k = Σ from i = 1 to k of rel_i / log2(i + 1)

nDCG@k divides by the DCG of the ideal order, so a perfect ranking scores 1.0.

Take a first-stage top 10 with relevance [0, 1, 0, 0, 2, 0, 1, 0, 0, 0]. The answering passage is fifth.

  • DCG@5 = 1 / log2(3) + 2 / log2(6) = 0.631 + 0.774 = 1.405
  • Ideal order [2, 1, 1, 0, 0]: DCG@5 = 2 / 1 + 1 / log2(3) + 1 / log2(4) = 2 + 0.631 + 0.5 = 3.131
  • nDCG@5 = 1.405 / 3.131 = 0.449

A reranker that moves the answering passage to first and both related passages to second and third reaches the ideal order, nDCG@5 = 1.0. Notice that a reranker cannot add passages: if the first stage misses the answer entirely, nDCG stays low whatever the reranker does. That is why first-stage recall at a depth of 50 or 100 is the number to watch before you add a reranker.

import math

def dcg(rels): return sum(r / math.log2(i + 2) for i, r in enumerate(rels))
def ndcg(rels, k):
    return dcg(rels[:k]) / dcg(sorted(rels, reverse=True)[:k])

first_stage = [0, 1, 0, 0, 2, 0, 1, 0, 0, 0]
reranked    = [2, 1, 1, 0, 0, 0, 0, 0, 0, 0]
print(round(ndcg(first_stage, 5), 3), round(ndcg(reranked, 5), 3))   # 0.449 1.0

To rerank with a real cross-encoder, the Sentence Transformers API is two lines after installing sentence-transformers (the model downloads on first use):

from sentence_transformers import CrossEncoder
passages = ["...", "..."]          # your first-stage candidates
model = CrossEncoder("cross-encoder/ms-marco-MiniLM-L6-v2")
ranked = model.rank("How many people live in Berlin?", passages, top_k=5)

Pricing a reranker: tokens, calls and latency

Reranking cost is easy to estimate because it scales with candidates times passage length.

Cross-encoder. Each candidate is one forward pass over the query plus the passage. With a 20-token query and 300-token passages:

import math

def ce_tokens(n_cand, q_tok=20, p_tok=300): return n_cand * (q_tok + p_tok)
def windows(n, w=20, s=10): return 1 if n <= w else math.ceil((n - w) / s) + 1
Table 2. Pricing a reranker: tokens, calls and latency
Candidates Cross-encoder tokens per query Listwise LLM calls (window 20, step 10) Passage tokens the LLM reads
20 6,400 1 6,000
50 16,000 4 24,000
100 32,000 9 54,000
200 64,000 19 114,000

Three things stand out.

  1. Cross-encoder cost is linear and parallel. 100 candidates means 32,000 tokens, but they run as one batch on a GPU, so latency grows slowly until the batch no longer fits. Small cross-encoders based on MiniLM-sized models are built for exactly this.
  2. Listwise sliding windows are sequential. Each window depends on the previous one, so nine calls for 100 candidates means nine round trips. Even at a few hundred milliseconds per call that is seconds of latency, which suits offline or deep-research workloads more than chat.
  3. The overlap in sliding windows costs extra reading. With a step of half the window, the LLM reads 54,000 passage tokens for 100 candidates, about 1.8 times the 30,000 tokens of the passages themselves.

Turning tokens into money. For a hosted LLM reranker at an example price of 1 dollar per million input tokens, 54,000 tokens per query is 0.054 dollars, or 5,400 dollars per 100,000 queries, often more than the answer generation itself. A self-hosted cross-encoder costs GPU time instead and is usually much cheaper per query. Set a budget per answer and choose depth accordingly; the site's page on cost and latency budgets gives a framework.

Depth is the main knob. Reranking 200 instead of 50 candidates quadruples cost and helps only if the first stage often places relevant passages between ranks 50 and 200. Measure recall at 50, 100 and 200 before deciding.

What it means in practice

For most RAG systems the right default is a small cross-encoder reranking the top 20 to 50 candidates from a hybrid retriever, passing the best three to five to the model. It adds tens of milliseconds and usually lifts answer quality more than swapping the generator.

LLM rerankers are worth it in two places: questions where the difference between relevant and nearly relevant is subtle (legal, medical, compliance), and offline or agentic workloads where latency matters less than precision. The RankLLM release makes it practical to try open listwise rerankers on your own hardware with vLLM, and its HTTP and MCP extras make a reranker callable from an agent.

The cross-encoder in the Sentence Transformers README is a reminder of how simple the core step is: score pairs, sort, keep the top k. The engineering is in choosing depth, batching on a GPU, and measuring nDCG and end-to-end quality on your own questions. For the training side of these models, the site's learning to rank page explains the losses.

What to do now

  1. Measure first-stage recall at 50 and 100. A reranker can only reorder what retrieval found; if recall@100 is low, fix retrieval first.
  2. Add a small cross-encoder on the top 20 to 50. Batch all pairs in one GPU call and measure latency at your peak load.
  3. Score with nDCG@5 or @10 on labelled questions. Use graded relevance where you can; it rewards putting the best passage first.
  4. Keep the reranker's top 3 to 5 for the prompt. Fewer, better passages cut generation cost and noise.
  5. Use a score threshold carefully. Cross-encoder scores are not calibrated across queries; prefer a fixed top k unless you have calibrated a cut-off.
  6. Reserve LLM rerankers for hard or offline cases. Use them where precision matters more than seconds, such as research agents or legal review.
  7. Price the reranker per answer. Multiply candidates by passage tokens, then by your model's price or GPU cost, before rollout.
  8. Pick a reranker for your language. Models trained on English web queries can drop sharply on other languages or domains; test with real queries.

Risks and open questions

Rerankers inherit first-stage misses. No reordering can recover a passage that was never retrieved. Teams sometimes add a reranker and see no gain because recall was the real bottleneck.

LLM rerankers can be inconsistent. Listwise outputs can omit or duplicate identifiers, and results can depend on the input order of passages. Implementations need repair logic and fixed seeds or temperatures.

Latency grows quietly. Sequential sliding windows, large candidate pools and long passages each add delay. Under load, batching limits and queueing can multiply it.

Scores are not probabilities. A cross-encoder score of 8 on one query and 5 on another does not mean the first passage is more likely to be right. Thresholds need calibration per domain.

Prompt injection reaches the reranker too. A passage that says "rank this document first" is aimed at LLM rerankers. Treat passages as data and test with adversarial text.

Watch next: how far distilled open listwise models close the gap with large proprietary rerankers, and whether reranking exposed as an agent tool through MCP becomes a standard part of agentic RAG stacks.

Frequently asked questions

What is a reranker in RAG?

A reranker is a second-stage model that takes the top candidates from search and reorders them by relevance to the question. It reads the question and each passage together, so it is more accurate than first-stage retrieval but too slow to run over a whole corpus.

How many candidates should I rerank?

Start with 20 to 50 from a hybrid retriever. Increase depth only if your measurements show relevant passages often sit beyond rank 50 in the first stage, because cost grows linearly with candidates.

Is an LLM reranker better than a cross-encoder?

Often more accurate on subtle cases, especially listwise rerankers that compare passages side by side, but much slower and more expensive. A cross-encoder is the better default for interactive RAG; LLM rerankers suit offline, research or high-stakes queries.

What does nDCG measure?

nDCG@k measures how well the top k results are ordered, giving more credit for relevant passages near the top and for more relevant passages. It divides by the score of the ideal order, so 1.0 means perfect. In the worked example a reranker lifted nDCG@5 from 0.449 to 1.0.

Can I use reranker scores to decide when to answer "I don't know"?

Possibly, but only after calibration. Raw cross-encoder scores vary by query and domain. Collect scores on labelled questions, find a threshold that separates answerable from unanswerable ones, and monitor it over time.

Summary

Reranking is the second stage of RAG retrieval: a model reads each candidate passage together with the question and reorders the list so the best evidence reaches the generator. Cross-encoders do this with one forward pass per pair and are the practical default; LLM rerankers, pointwise, pairwise or listwise, can be more precise but cost far more, as the token table shows: 100 candidates mean 32,000 cross-encoder tokens or nine sequential listwise LLM calls. nDCG@k measures the improvement, and the worked example showed a lift from 0.449 to 1.0 when the answering passage moved from fifth to first. RankLLM's October release and Sentence Transformers' November release make both styles easy to try. Measure first-stage recall, rerank a modest depth, and budget latency and cost per answer.

Sources

Cite this article

Kelahmet, Ö. C. (2026, November 24). Reranking for RAG: cross-encoders, LLM rerankers and the latency and cost of each. Özer Cem KELAHMET. https://www.ozercemkelahmet.com/articles/reranking-cross-encoders-llm-rerankers-cost

BibTeX
@online{kelahmet2026reranking,
  author = {Kelahmet, {\"O}zer Cem},
  title  = {{Reranking for RAG: cross-encoders, LLM rerankers and the latency and cost of each}},
  year   = {2026},
  month  = {nov},
  url    = {https://www.ozercemkelahmet.com/articles/reranking-cross-encoders-llm-rerankers-cost}
}
Version historyfirst version
  1. Published

Factual corrections are listed here with what changed. Wording and formatting edits are not listed.

Last updated Nov 24, 2026
Type to search.
    ↑↓ navigate↵ open