What is reranking?
Definition
Reranking is a second search stage that reorders the top results of a fast first-stage retriever with a slower, more accurate model, usually a cross-encoder that reads the query and each candidate together. It improves which results come first, for users or for a RAG prompt, but cannot recover documents the first stage missed.
How does reranking work?
Search over millions of documents has to be cheap per document, so the first pass is fast and somewhat rough. Reranking adds a second, slower pass over a short list. The Sentence Transformers Retrieve & Re-Rank guide describes the pipeline in two stages:
- Retrieve candidates. A keyword engine or a vector search returns a large list, "e.g. 100 possible hits", for the query.
- Score each pair. A cross-encoder reads the query and one candidate together and gives the pair a relevance score.
- Sort and cut. The candidates are sorted by that score, and only the top few go to the user or into the prompt of a RAG system.
The second stage cannot add documents. It only reorders what the first stage found, so a relevant passage missing from the candidate list stays missing.
Bi-encoder vs cross-encoder: why not rerank everything?
Dense retrievers are bi-encoders: they embed the query and each document separately, so document vectors can be computed once and indexed. A cross-encoder sees both texts at once. The Sentence Transformers guide puts the trade-off plainly. Cross-encoders perform better "as they perform attention across the query and the document", and yet: "Scoring thousands or millions of (query, document)-pairs would be rather slow."
| Bi-encoder (first stage) | Cross-encoder (reranker) | |
|---|---|---|
| Input | Query and document encoded separately | Query and document read together |
| Precompute documents? | Yes, once, into an index | No, every pair is scored at query time |
| Cost per query | One query embedding plus an index lookup | One model run per candidate |
| Scale | Millions of documents | Tens to hundreds of candidates |
| Strength | Recall: find everything plausibly relevant | Order: put the best match on top |
Example: two rerankers on the same candidate list
The script below retrieves candidates for an HR question by counting shared words, a crude stand-in for BM25. Then it reranks the top six with two open cross-encoders through the fastembed library, on CPU. The first model, Xenova/ms-marco-MiniLM-L-6-v2, is the MS MARCO MiniLM-L6 cross-encoder with ONNX weights. The right answer is the "Unused vacation days" policy, which never uses the words "roll over" or "next year".
# Two-stage retrieval: a cheap keyword pass picks candidates, a cross-encoder reorders them.
import re, time
from fastembed.rerank.cross_encoder import TextCrossEncoder
docs = [
"Vacation days: request vacation days in the HR portal at least two weeks before the first day off.",
"Unused vacation days: up to five unused days carry forward and expire on March 31.",
"Public holidays next year are listed in the company calendar; they do not count as vacation days.",
"Sick leave does not reduce your vacation balance; send a doctor's note after three days.",
"Parental leave: tell HR at least eight weeks in advance; your vacation days keep accruing.",
"Expense reports for travel next year must use the new template.",
"Laptop roll-out: new laptops roll over to all teams next year, starting with support.",
]
query = "Do leftover vacation days roll over to next year?"
STOP = {"a", "an", "the", "i", "can", "into", "in", "to", "of", "at", "for", "your", "you", "do", "not", "they", "and", "on", "after", "must", "use"}
def terms(text):
return {w for w in re.findall(r"[a-z']+", text.lower()) if w not in STOP}
# Stage 1: rank by the number of query terms each document contains (a stand-in for BM25).
first = sorted(docs, key=lambda d: len(terms(query) & terms(d)), reverse=True)[:6]
print("stage 1, keyword overlap:")
for i, d in enumerate(first, 1):
print(f" {i}. [{len(terms(query) & terms(d))} terms] {d[:60]}")
# Stage 2: a cross-encoder reads the query and each candidate together and scores the pair.
for name in ["Xenova/ms-marco-MiniLM-L-6-v2", "BAAI/bge-reranker-base"]:
model = TextCrossEncoder(name)
scores = list(model.rerank(query, first)) # warm-up call, also the scores we print
times = []
for _ in range(5):
start = time.perf_counter()
list(model.rerank(query, first))
times.append((time.perf_counter() - start) * 1000)
ms = sorted(times)[2] # median of 5 warm runs
print(f"stage 2, {name.split('/')[1]} ({len(first)} pairs, median {ms:.1f} ms):")
for i, (score, d) in enumerate(sorted(zip(scores, first), reverse=True), 1):
print(f" {i}. [{score:6.2f}] {d[:60]}")
Run on 2026-11-19 with fastembed 0.9.1 and onnxruntime 1.32.0, Python 3.11 on an Apple M1 Pro. Timings are the median of five warm runs on one machine and will vary with hardware and load:
stage 1, keyword overlap:
1. [4 terms] Public holidays next year are listed in the company calendar
2. [4 terms] Laptop roll-out: new laptops roll over to all teams next yea
3. [2 terms] Vacation days: request vacation days in the HR portal at lea
4. [2 terms] Unused vacation days: up to five unused days carry forward a
5. [2 terms] Sick leave does not reduce your vacation balance; send a doc
6. [2 terms] Parental leave: tell HR at least eight weeks in advance; you
stage 2, ms-marco-MiniLM-L-6-v2 (6 pairs, median 16.2 ms):
1. [ 0.41] Public holidays next year are listed in the company calendar
2. [ -1.58] Unused vacation days: up to five unused days carry forward a
3. [ -3.03] Laptop roll-out: new laptops roll over to all teams next yea
4. [ -6.81] Sick leave does not reduce your vacation balance; send a doc
5. [ -6.94] Parental leave: tell HR at least eight weeks in advance; you
6. [ -7.17] Vacation days: request vacation days in the HR portal at lea
stage 2, bge-reranker-base (6 pairs, median 100.5 ms):
1. [ 6.13] Unused vacation days: up to five unused days carry forward a
2. [ -3.70] Parental leave: tell HR at least eight weeks in advance; you
3. [ -7.20] Vacation days: request vacation days in the HR portal at lea
4. [ -7.51] Public holidays next year are listed in the company calendar
5. [ -8.65] Sick leave does not reduce your vacation balance; send a doc
6. [ -9.57] Laptop roll-out: new laptops roll over to all teams next yea
What the run shows:
- Keyword retrieval put the answer fourth, behind two documents that share "next year" and "roll over" with the query.
- The small reranker moved it to second. It also pushed the laptop notice down, but kept the public-holidays page on top.
- The larger reranker put it first by a wide margin, at about 6 times the latency of the small one (a median of 100.5 ms vs 16.2 ms for six pairs).
- Scores are not comparable across models. The top score was 0.41 for one model and 6.13 for the other. The MS MARCO model card's own example prints 8.607138 and -4.320078, so treat scores as an order within one query and one model, not as probabilities.
Stage 1 cut the seventh document, the expense note, only by list order: it also matched 2 terms. Had the vacation policy been the one cut, neither reranker could have found it.
How many candidates should you rerank?
Reranking cost grows linearly with the candidate count, and model size sets the slope. The MS MARCO cross-encoder model card lists throughput measured on a V100 GPU: 9,000 documents per second for TinyBERT-L2-v2, 1,800 for MiniLM-L6-v2 and 960 for MiniLM-L12-v2. On that card the L12 model scores 74.31 NDCG@10 on TREC DL 19 against 74.30 for L6, at about half the speed. A bigger model is not automatically a better trade.
Start from your latency budget, measure the per-pair time of your model on your hardware, and pick the largest candidate count that fits. Then check recall at that count on labeled queries: if the right passage is often outside the candidate list, fix retrieval first, because reranking cannot.
What changes with a hosted rerank API?
Hosted rerankers move the model run to a vendor and add their own limits. Cohere's Rerank best practices (updated October 21, 2026) give examples worth checking in any provider:
- Documents per request: up to 10,000 for
rerank-v5.0-proandrerank-v5.0-fast. - Truncation: long documents are cut to
max_tokens_per_doc, which defaults to 4096 for v5.0, so the end of a long document may never be scored. - Structured data: records can be sent as YAML strings, and since long strings get truncated, "the order of the keys is especially important."
Open models carry their own constraints. The bge-reranker-base model card (last changed June 2024, an older source), for example, lists Chinese and English as its languages and an MIT license.
How is reranking different from hybrid search and semantic search?
Semantic search and keyword search are first-stage retrievers: they decide which documents are candidates. Hybrid search runs both and merges their lists by rank or score. Reranking comes after either one. It rereads the top of the list with a more expensive model and changes the order, not the set. A pipeline can use all three: hybrid retrieval for recall, then a cross-encoder for the final order.
What should you check before adding a reranker?
- A labeled query set, scored before and after reranking. Track how often the right passage lands in the top few results, the ones that go into the prompt.
- Latency at your real candidate count, measured at peak load, not one query on a laptop.
- Truncation. Chunk long documents yourself so the relevant part is inside the model's window.
- Language coverage of the model for every language your users write in.
- No thresholds on raw scores unless you calibrate them; ranges differ by model, as our run shows.
- Permissions before reranking. Filter candidates per user first, so the reranker never reads text the user may not see.
Re-ranking is part of the retrieval-augmented generation work in our generative AI development service, together with chunking, embeddings, hybrid search and source citations in answers. Our AI-ready data engine work carries document and row permissions into the index and filters retrieval for each user, with automated tests for those rules.
Sources
- Retrieve & Re-Rank, Sentence Transformers documentation, 2026-04-01
- cross-encoder/ms-marco-MiniLM-L6-v2, Hugging Face model card (Sentence Transformers), 2026-08-09
- BAAI/bge-reranker-base, Hugging Face model card (BAAI), 2024-06-24
- Best Practices for using Rerank, Cohere docs, 2026-10-21
- Is ChatGPT Good at Search? Investigating Large Language Models as Re-Ranking Agents, arXiv (Sun et al.), 2304.09542 v3, 2024-12-28
Frequently asked questions
Does reranking improve RAG answers?
It can, when the right passage is retrieved but ranked too low to make it into the prompt. If the passage is not retrieved at all, fix chunking, embeddings or the keyword path instead.
Can an LLM be used as a reranker?
Yes. A general LLM can be prompted to score or order candidates. A 2023 study of ChatGPT and GPT-4 found that properly instructed LLMs can deliver results competitive with, even superior to, state-of-the-art supervised methods on popular IR benchmarks. Compare its quality, latency and cost with a small cross-encoder on your own labeled queries before you choose.
Is reranking the same as re-ranking?
Yes. Both spellings name the same second-stage step; documentation uses either, and Sentence Transformers writes Re-Rank.
Should I rerank results that are already ordered by hybrid search?
Often, yes. Hybrid fusion only combines ranks or scores from the first-stage lists, while a cross-encoder reads the text of each candidate against the query.
Read next
Related terms
Mikhail BodnarchukFounder of Codeception and CodeceptJSBoth are open-source testing frameworks: Codeception for PHP, CodeceptJS for JavaScript.LinkedInGitHub