Re-ranking
After this lesson, you will be able to:
- Explain why a two-stage retrieve-then-rerank pipeline beats single-stage retrieval — first stage casts a wide net, second stage applies a smarter (slower) model
- Use cross-encoder rerankers (Cohere Rerank, BGE-Reranker, MS MARCO MonoT5) to improve retrieval quality at the cost of extra latency per query (measure both on your data)
- Apply ColBERT/ColBERTv2 late-interaction for the best of both worlds — reranker quality at retrieval speed
- Pick the right reranker tier (bi-encoder retrieval, cross-encoder reranking, late-interaction) based on latency and corpus size
Before you start
Open the /play/reranking-stage playground to step through how a cross-encoder re-scores a candidate set retrieved by bi-encoder. Notice how documents at rank 47 jump to rank 2 — that's the NDCG@10 lift you're paying 100× per query for.
#Why Two Stages?
#Cross-Encoder Rerankers
[CLS] query [SEP] document [SEP], and output a relevance score.#How a Reranker Is Trained: The Pairwise Loss
The score above is a sigmoid of a raw number z, called the logit. Rankers are often trained on pairs: for one query, a relevant document i and a non-relevant document j. The model says the probability that i beats j is the sigmoid of the logit gap (the Bradley-Terry form, derived in Evaluating LLMs in 2026: MMLU-Pro, GPQA, SWE-Bench & Agentic Evals, with its loss gradient in RLHF & DPO: Aligning LLMs with Human Preferences). Nogueira and Cho's monoBERT instead trains each pair separately with cross-entropy. Open the derivation for the pairwise logistic loss (the RankNet loss) and its gradient, which is the part that is specific to reranking.
Production rerankers (2026)
A snapshot as of October 2026. Model names and versions change, so verify before you choose.
| Model | Hosted? | Notes |
|---|---|---|
| Cohere Rerank 3 | Yes (API) | Multilingual hosted API |
| BGE-Reranker-v2 | Open weights | BAAI; open weights; can run on a single GPU |
| MonoT5 / MonoBERT | Open weights | Original cross-encoder lineage; still strong |
| Voyage Rerank-1 | Yes (API) | Hosted; positioned for technical and long documents |
| Jina Reranker | Yes / open | Multilingual + multilingual-code |
#ColBERT: Late Interaction
A quick check before we get to the production rubric — make sure the cost intuition lands.
A bi-encoder serves 1M docs in under 5ms. A cross-encoder reranker takes ~100ms for 100 candidates. Why is the two-stage pipeline still faster than a 'cross-encoder over the whole corpus'?
#Decision Rubric
Your single-stage dense retriever gets 70% recall@10 on a customer-support QA system. You add a cross-encoder reranker. What's the most likely outcome?
The recall claim above is a short result. Open the derivation to see why the final recall can never exceed what stage 1 handed over, and what the pipeline costs.
| Scenario | Recommended pipeline |
|---|---|
| Hobby project, low traffic | Bi-encoder retrieval only |
| Production Q&A | Hybrid (BM25 + dense) → cross-encoder rerank top-100 to top-10 |
| Latency-critical (<50ms p95) | ColBERT/ColBERTv2 single-stage |
| Multilingual customer support | Cohere Rerank 3 (multilingual) |
| Self-hosted, cost-sensitive | BGE-Reranker-v2-m3 + bi-encoder |
#The Math of NDCG, MRR, and the Lift You Actually Get
A reranker shifts gold-relevant docs up the ranking. The way you measure that shift matters — recall@10 only checks "did the doc make the cut," but NDCG and MRR reward where in the top-k it landed. Use the playground below to build intuition for how a reranker's reordering changes each metric.
#Hands-On
The cell below runs a two-stage retrieval in plain numpy. Stage 1 turns each text into a vector on its own and ranks by cosine. Stage 2 reads the query and each candidate together, which is what a cross-encoder does. Both stages are toys so the cell runs on this page; watch the document that stage 1 ranks second move to first.
Tests: Verify that the stage-2 order differs from the stage-1 order, and that the document containing 'reset' and 'password' next to each other moves to the top.
The real models (a sentence-transformers bi-encoder and a cross-encoder) need a package and a download that this page cannot run. The version below is read-only. Copy it to Google Colab (run the pip line first).
# Copy to Colab: needs sentence-transformers (and a model download), so it cannot run on this page.
# Two-stage retrieval: bi-encoder (top-50) → cross-encoder rerank (top-10)
# !pip install sentence-transformers
import numpy as np
from sentence_transformers import SentenceTransformer, CrossEncoder
corpus = [
"RAG combines retrieval with LLM generation to ground answers in source documents.",
"Vector databases use HNSW indexing for fast approximate nearest-neighbor search.",
"Pinecone offers serverless vector search with built-in hybrid retrieval.",
"BM25 is a sparse retrieval algorithm based on term frequency.",
"Cross-encoder rerankers compute a relevance score between query and document jointly.",
"BGE embeddings are produced by the Beijing Academy of AI's open-weight encoder.",
"Cohere Rerank 3 is a multilingual cross-encoder reranker with hosted API.",
"ColBERT uses late-interaction MaxSim scoring for efficient cross-encoder-quality retrieval.",
"Long-context LLMs can read very long prompts but cost more per query.",
"Self-RAG and CRAG add retrieval critic loops for adaptive RAG pipelines.",
]
# --- Stage 1: bi-encoder retrieval ---
biencoder = SentenceTransformer('all-MiniLM-L6-v2')
doc_embs = biencoder.encode(corpus, normalize_embeddings=True)
query = "How do I improve RAG retrieval quality?"
q_emb = biencoder.encode(query, normalize_embeddings=True)
sim = doc_embs @ q_emb
top_50 = np.argsort(-sim)[:50] # capped at len(corpus) here
print("Stage 1 (bi-encoder top-5):")
for i in top_50[:5]:
print(f" {sim[i]:.3f} {corpus[i]}")
# --- Stage 2: cross-encoder rerank ---
crossencoder = CrossEncoder('cross-encoder/ms-marco-MiniLM-L-6-v2')
candidates = [(corpus[i], i) for i in top_50]
pairs = [[query, doc] for doc, _ in candidates]
scores = crossencoder.predict(pairs)
reranked = sorted(zip(candidates, scores), key=lambda x: -x[1])
print("\nStage 2 (cross-encoder rerank top-5):")
for (doc, idx), score in reranked[:5]:
print(f" {score:.3f} {doc}")
print("\nNotice: the reranker often promotes candidates from positions 6-50")
print("of the bi-encoder into the final top-5. That's the lift.")
print("\nCHALLENGE: Use 'BAAI/bge-reranker-base' instead of MiniLM-L-6.")
print("Benchmark NDCG@5 on your own QA dataset.")#Key Takeaways
- Two-stage retrieve-then-rerank is the production default — bi-encoder casts wide net, cross-encoder picks best of top-50/100
- Cross-encoders see query and doc together, catching subtle relevance signals bi-encoders miss; cost ~50-200ms per query
- ColBERT late interaction gets closer to cross-encoder quality while staying fast enough for retrieval, via per-token embeddings + MaxSim
- Always rerank from top-50 or top-100, not top-10. The reranker's wins come from promoting hidden candidates
- A hosted reranker API (for example Cohere Rerank) is the easy way to start; BGE-Reranker-v2 is an open-weight self-hosted alternative
#Quick Check
Why does a cross-encoder achieve higher quality than a bi-encoder for the same query-document pair?