M07 · Retrieval-augmented generation (RAG)07-0730 min read

Lesson 47 of 106 · Module 8 of 14 · Week 4

Threads:The measurement threadThe weights threadThe infrastructure threadThe control thread

Reranking with a cross-encoder in RAG: how and when to use it

Reranking re-scores an already-retrieved candidate list with a cross-encoder — a model that reads the query and the passage together in one forward pass and outputs a single relevance score. Because it never precomputes anything, it is far more accurate than the bi-encoder that retrieved the candidates and far too expensive to search a corpus with, which is why it runs as a second stage over tens of candidates rather than millions. It is the most reliable single quality improvement available in a RAG pipeline, and it fixes ordering rather than recall: a chunk that was never retrieved cannot be reranked into the answer.

01

What reranking with a cross-encoder is

Reranking is a two-stage retrieval architecture. Stage one is cheap and wide; stage two is expensive and narrow.

text
query
  │
  ├─► stage 1: RETRIEVE  (bi-encoder / BM25 / hybrid fusion — 07-06)
  │            cheap per corpus item, precomputed index
  │            returns N candidates, N ≈ 25–200
  │
  └─► stage 2: RERANK    (cross-encoder)
               one model forward pass PER CANDIDATE
               returns the same N candidates, reordered
                          │
                          ▼
               truncate to the top k (k ≈ 3–8) → context assembly (07-08)

The pattern has a name in information retrieval: retrieve-and-rerank, or a cascade. The general principle behind cascades is that you spend compute in proportion to how much a decision matters. Deciding that 999,950 of a million documents are irrelevant deserves almost no compute each; deciding which of the surviving 50 goes into a context window with room for five deserves a lot.

What the cross-encoder actually outputs. Not an embedding. A single scalar — typically a logit that a sigmoid turns into a 0–1 relevance probability, or an unbounded score depending on the model. There is no vector to store, no index to build, and no re-embedding project when you change models. That last point is a genuine and underrated advantage: swapping rerankers is free, while swapping embedding models means re-encoding the corpus (12-12).

What reranking is not. It is not fusion (07-06) — fusion merges two lists using ranks; reranking re-scores one list using a model. It is not a retriever — it cannot search. It is not an LLM answering the question, though an LLM can be used as a reranker (§9). And it is not a filter, though a score threshold applied to reranker output is a reasonable way to drop weak candidates, and is far more meaningful than thresholding cosine similarity (07-02).

In the NVIDIA stack framing, reranking is part of what a retrieval service does to achieve retrieval accuracy at scale — NeMo Retriever is NVIDIA's retrieval offering and the NVIDIA AI Blueprint for RAG is the reference workflow that assembles these stages [NVIDIA-DOC]. 07-09 covers the full assembled pipeline.

02

How a cross-encoder works, and why it beats a bi-encoder

L1 — The intuition you can carry into an exam

Bi-encoder: two people summarise a question and a document separately, then someone compares the two summaries. Fast, because the document summary is written once and reused for every question. Lossy, because the document was summarised without knowing the question.

Cross-encoder: one person reads the question and the document side by side and says how well the document answers it. Accurate. And it has to be repeated for every question–document pair, because the judgement depends on both.

Three facts to attach:

  • The cross-encoder outputs a score, not a vector. Nothing is precomputable.
  • Cost is per candidate, so pool size is a direct latency multiplier.
  • Reranking fixes ordering, not coverage. Recall comes from stage one.

L2 — The mechanism

A cross-encoder is typically a transformer encoder (BERT-family, 04-03) with a classification head, fed a single sequence that contains both texts with a separator:

text
input:  [CLS] why does my client cert handshake fail [SEP]
              the server MUST abort the handshake when the presented
              certificate chain cannot be validated ... [SEP]

           ▼  full self-attention across BOTH segments
        ┌──────────────────────────────┐
        │  transformer encoder layers  │   query tokens attend to passage tokens
        └──────────────┬───────────────┘   and vice versa, at every layer
                       ▼
                  [CLS] vector
                       ▼
                 linear head → 0.94   (relevance score)

The critical line in that diagram is "query tokens attend to passage tokens". In a bi-encoder those two texts never meet inside the model; the only interaction is a dot product at the very end, between two vectors each computed in ignorance of the other. In a cross-encoder they interact at every attention layer. That is why the cross-encoder can do things similarity fundamentally cannot:

CapabilityWhy joint encoding enables it
Term-level alignmentThe model can check whether this specific query term is addressed, rather than whether the overall topics match
Negation sensitivitynot in the passage can be attended to in relation to the query's assertion — the 07-03 limit, partially corrected
Distinguishing mention from explanationA passage that merely names the query's subject attends differently than one that answers about it
Multi-constraint queries"Python 3.12 on ARM with FIPS enabled" — a bi-encoder averages the three constraints into one vector; a cross-encoder can check each
Rejecting near-missesTwo passages about the same topic where only one answers the question look nearly identical as vectors and clearly different jointly

Cross-encoders are trained on labelled (query, passage, relevance) data — often derived from large relevance-judgement collections — with a classification or ranking objective. Because they are scoring rather than embedding, they can be smaller than you might expect and still outperform a much larger bi-encoder on ranking quality, and this is one of the reasons reranking is such a good deal in practice.

L3 — The cost model, and how to control it

The arithmetic is the whole engineering problem, and it is worth writing as a formula rather than a feeling.

text
rerank latency ≈ ceil(N / batch_size) × per_batch_forward_time
rerank cost    ≈ N × (query_tokens + passage_tokens) processed

Three consequences:

Latency is roughly linear in N. Doubling the candidate pool roughly doubles reranking latency (modulo batching efficiency). This makes N the single most important tuning parameter in the stage, and the one to set from measurement rather than from a default.

Cost is linear in passage length too. Reranking 50 candidates of 200 tokens each is a quarter the work of reranking 50 candidates of 800 tokens. Chunk size (06-02) therefore shows up as a reranking cost, which is a connection people miss. Long chunks are expensive twice: once in the context window (04-06) and once in the reranker.

Cross-encoder inputs have a length limit. The model has a maximum sequence length covering query and passage together. A chunk longer than that budget is truncated — silently, in most implementations — so the reranker may score a passage on its first half only. If your chunks exceed the reranker's window, you are reranking on partial evidence and will not be told.

Levers for controlling the cost:

LeverEffectCaution
Reduce Nlinear latency savingtoo small and there is nothing to reorder — reranking a top-5 pool is nearly pointless
Batch the candidateslarge throughput gain on GPUneeds a serving stack that batches (12-06 on batching)
Use a smaller rerankerfaster per passmeasure the quality loss on your own eval set
Cache (query, chunk) scoreshelps with repeated querieshit rate is usually low for natural-language questions
Shorten chunkscheaper per candidateinteracts with chunking strategy (06-02)
Rerank only when stage one is uncertainsaves the average caseadds a routing decision that itself can be wrong

The last one is worth naming because it is a genuine production pattern: if stage one returns a candidate with an overwhelming score and a large gap to second place, reranking will probably not change the outcome, so skip it. This is an optimisation to apply after you have measured, not before.

One structural caution. The reranker is on the critical path of every request, and it is usually a GPU-backed model call. That makes it a latency floor, a capacity planning item (12-10), and an availability dependency. A RAG system with a hard sub-100-ms budget may not be able to afford a reranker at all — which is one of the honest counter-cases for RAG architecture generally (07-12).

03

Cross-encoder reranker vs bi-encoder retriever vs fusion vs LLM-as-judge

Bi-encoder (retriever)Cross-encoder (reranker)RRF fusionLLM as rerankerLLM-as-a-judge
Inputone text at a timequery + passage togethertwo ranked listsquery + passages, as a promptquestion, answer, maybe reference
Outputa vectorone relevance scoreone merged rankingan ordering or per-passage scoresa quality rating
Precomputableyes — that is the pointnon/anono
Cost unitper corpus item, onceper candidate, per querynegligibleper candidate or per batch, largeper evaluation
Can search a corpusyesnononono
Improves recallyesnoyesnono
Improves precision/orderingweaklyyes — its whole jobsomewhatyesno
Handles negationpoorlybest availablebarelywelln/a
Needs calibrationnononoprompt designprompt + bias control
Swap costre-embed the corpusfree — nothing storedfreefreefree
Where it runsindex time + query timequery time, stage 2query timequery timeoffline evaluation

Four readings the exam probes.

Bi-encoder and cross-encoder are not competing designs; they are the two stages of one cascade. A question that offers "replace the bi-encoder with a cross-encoder for retrieval" is describing something computationally infeasible at corpus scale. A question that offers "add a cross-encoder to reorder retrieved results" is describing the correct architecture.

Fusion and reranking do different jobs and compose. Fusion (07-06) is a recall intervention that merges lists. Reranking is a precision intervention that reorders one list. The canonical order is retrieve → fuse → rerank → truncate, and the worked example in 07-06 ended precisely at the point where reranking is needed.

LLM-as-reranker and LLM-as-a-judge are different things. A reranker orders retrieved passages at query time, in production, on the critical path. A judge scores generated answers, usually offline, as part of evaluation (09-10). Both use an LLM; they sit in different parts of the system and are confusable in exam options.

The "swap cost" row is the sleeper advantage. Because a reranker stores nothing, you can A/B two rerankers this afternoon on the same index. Trying two embedding models requires embedding the corpus twice. That asymmetry means reranking is usually the cheapest experiment available in a RAG pipeline, and it is a good reason to reach for it early when quality is disappointing.

04

Worked example: reranking the fused pool from the hybrid-search lesson

This continues the constructed example from 07-06 with invented scores, so the mechanism is inspectable end to end. These are not measurements.

The query was:

"getting ERR_CERT_AUTHORITY_INVALID when the client connects — why?"

And RRF fusion produced this ranking, with two acknowledged defects:

Fused rankidText (abridged)RRF scoreVerdict
1d1"ERR_CERT_AUTHORITY_INVALID is returned when the presented certificate chain terminates in an untrusted root."0.032522correct — the direct answer
2d3"Common client connection errors and their remediation steps."0.031498generic index page
2d6"Why connections fail: an overview of TLS handshake failure causes."0.031498topical overview
4d4"Certificate pinning configuration reference."0.030770largely irrelevant
5d2"The client aborts the connection if the server certificate cannot be validated against a configured trust anchor."0.016393the second-best chunk, buried
6d5"ERR_CERT_AUTHORITY_INVALID appears in the changelog for release 4.2."0.016129mentions the string, answers nothing

The two defects, restated: d2 — a correct mechanistic explanation — sank to rank 5 because it appeared in only one leg's list; and d4 — a pinning reference with no bearing on the question — rose to rank 4 because it scraped the bottom of both lists. RRF's bias toward mutual presence produced both.

If the context budget takes the top 3, the model receives d1, d3, and d6: one good chunk and two generic ones, while d2 sits unused.

Step 1 — score every candidate with the cross-encoder

Each of the six is concatenated with the query and passed through the model. Constructed relevance scores (0–1 after sigmoid):

text
d1  0.96    names the exact error AND explains its cause
d2  0.89    explains the mechanism precisely, without the error string
d6  0.54    correct topic, no specific answer
d3  0.31    an index of error pages; does not answer anything itself
d5  0.22    mentions the error string in a changelog context
d4  0.11    pinning configuration — different subject

Step 2 — read the reordering

Reranked: d1 (0.96) > d2 (0.89) > d6 (0.54) > d3 (0.31) > d5 (0.22) > d4 (0.11).

Compare the three configurations side by side:

RankSparse onlyDense onlyHybrid (RRF)Hybrid + rerank
1d1d2d1d1
2d5d1d3/d6d2
3d3d6d4d6
4d6d3d2d3
5d4d4d5d5
6d6d4

Four specific things the reranker did that no earlier stage could:

It promoted d2 from rank 5 to rank 2. Reading the query jointly with d2, the model can see that "the client aborts the connection if the server certificate cannot be validated against a configured trust anchor" is the answer to "why does this happen when the client connects" — even with zero lexical overlap and only one leg's vote. Neither BM25, nor cosine similarity, nor RRF had any mechanism for recognising this.

It demoted d4 from rank 4 to last. Joint encoding reveals that a pinning configuration reference shares vocabulary with the query and answers nothing in it. Both retrievers were fooled by vocabulary; the reranker was not.

It separated d1 from d5 decisively — 0.96 versus 0.22 — even though both contain the exact error string. This is the "mention versus explanation" distinction, and it is the single clearest demonstration of what joint encoding buys. BM25 gave d5 rank 2 for containing a rare term; the reranker recognised that containing a term and explaining it are different things.

The scores are interpretable enough to threshold. There is a visible gap between d2 at 0.89 and d6 at 0.54, and another between d6 and d3 at 0.31. A threshold around 0.5 keeps d1, d2, and d6 and discards the rest — a defensible cut. Compare this with cosine similarity, where unrelated passages score 0.2–0.5 (07-02) and no natural cut exists. Reranker scores are more thresholdable than similarity scores, because the model was trained on a relevance objective rather than a similarity one. This is not a promise of calibration — you still have to pick the threshold on your own labelled data — but the signal is genuinely more separable.

Step 3 — the resulting context, and what it costs

The top-3 context is now d1, d2, d6: the direct answer, the mechanistic explanation, and useful background. Compare to hybrid-only's d1, d3, d6. The same retrieval, the same corpus, the same query — one extra stage, and one of the three context slots went from a generic index page to the second-best passage in the corpus.

The cost, stated honestly: six extra model forward passes for this toy example; in a realistic setting, N = 50 forward passes on the critical path of every request. If your budget cannot absorb that, you do not get this improvement — which is the trade-off, not a hidden catch.

Step 4 — what reranking could not fix

Suppose the corpus also contained d7: "ERR_CERT_AUTHORITY_INVALID means the CA that signed the certificate is not in the client's trust store; import the CA certificate to resolve it." — a chunk that is better than d1, because it also gives the remedy.

If neither leg retrieved d7, the reranker never sees it, never scores it, and cannot promote it. The final answer is missing the remedy, and no amount of reranking quality changes that.

This is the recall/precision division made concrete. d7's absence is a stage-one failure, addressed by better chunking, a better embedding model, deeper retrieval, or hybrid coverage — the 07-06 and 06-02 interventions. Reranking is powerless against it, and diagnosing which failure you have is precisely the discipline 07-10 teaches.

05

Decision table: when to add a reranker and when not to

SituationAdd a reranker?Reasoning
The right chunk is retrieved but ranked below the context cutoffYes — this is the canonical caseOrdering is exactly what reranking fixes
The right chunk is never in the top-50NoRecall problem; fix stage one (07-06, 06-02, 03-03)
Context budget is tight and only 3 chunks fitYes, stronglyThe fewer slots you have, the more ordering matters
Retrieved passages are all on-topic but only one answersYesRejecting near-misses is a cross-encoder strength
Queries carry multiple constraints ("3.12 on ARM with FIPS")YesA bi-encoder averages constraints; a cross-encoder checks them
Answers invert polarity ("not supported" vs "supported")Yes — best available fixThe 07-03 negation limit is partially corrected here
Corpus mixes authoritative and community sourcesHelps, but not the primary fixTrust-tier metadata is the primary fix (07-03); reranking supplements it
Complaint is "outdated documents are cited"NoRecency is metadata, not relevance (07-03)
Complaint is "users see documents they shouldn't"No — and urgentlyAccess control is stage-one filtering (07-05)
Hard latency floor under ~100 ms end to endProbably notA per-candidate model pass is a latency floor you may not have room for (12-10)
No GPU or inference budget availableConsider a small reranker, or noneThe cost is real and per-request
You want the cheapest quality experiment availableYes, try it firstNothing is stored, so swapping rerankers is free — unlike embedding models (12-12)
Stage one has not been measured yetMeasure firstYou cannot tell a recall problem from a precision problem without looking at the candidate list
Corpus under ~10k chunksYes, and it is easyStage one is trivial at this scale (07-04); the reranker is the interesting part

The diagnostic that makes the whole table usable, repeated because it is the highest-leverage habit in this module: retrieve top-50 for a failing query and find out where the correct chunk actually is.

Where the correct chunk sitsDiagnosisFix
Rank 1–3, answer still wronggeneration failure07-10, 07-11
Rank 4–50precision / ordering failurereranking
Absent from top-50recall failurehybrid (07-06), chunking (06-02), embedding model (03-03)
Not in the corpus at allingestion or curation failure06-01, 08-01

Half of all RAG debugging time is saved by asking this before anything else, which is why 07-10 exists as its own lesson.

06

Why reranking with a cross-encoder is on the NCA-GENL exam

Reranking appears explicitly in the course's RAG coverage — the pipeline description includes ingest, chunk, overlap, and rerank as named stages — and it serves:

  • 1.3 / 4.2 — Build LLM use cases such as RAG, chatbots, and summarizers [OFFICIAL]. Retrieve-and-rerank is standard production architecture.
  • 1.8 — Select and use models to create text embeddings [OFFICIAL]. Knowing that a cross-encoder does not produce embeddings is part of understanding what an embedding model is for.
  • 1.4 — Curate and embed content datasets for RAGs. Chunk length is a reranking cost as well as a context cost.
  • 4.1 / 1.1 — Assist in deployment and evaluation of model scalability, performance, and reliability [OFFICIAL]. A per-candidate model pass on the critical path is a scalability decision.
  • 4.4 — Identify system data, hardware, or software components required to meet user needs. A reranker is an additional model to serve.

On the stack side, NeMo Retriever is NVIDIA's retrieval offering aimed at retrieval accuracy at scale, and the NVIDIA AI Blueprint for RAG is the reference workflow [NVIDIA-DOC]. Reranking models are commonly served as inference microservices, which connects to the NIM and Triton material in 12-13. Note the [FIELD] calibration that NVIDIA-branded options tend to be favoured when two answers are technically defensible — useful as a tie-breaker, not as a substitute for understanding the architecture.

Exam depth is general-level [FIELD]. Know what a cross-encoder is, know that it scores jointly and cannot be precomputed, know it runs as a second stage over a small pool, and know it improves precision rather than recall. Do not memorise architecture details or training objectives.

Question phrasings you should recognise:

PhrasingTestingAnswer shape
"Which model type encodes the query and document together to produce a relevance score?"naming ita cross-encoder
"Why is a cross-encoder not used for first-stage retrieval?"the cost modelit cannot precompute; one forward pass per candidate is infeasible at corpus scale
"The correct passage is retrieved at rank 8 but the context holds 3 chunks. What should be added?"precision fixa reranking stage
"The correct passage is never retrieved. Will reranking help?"recall vs precisionno — reranking only reorders what stage one returned
"What is the main cost of adding a reranker?"per-candidate latencyone model pass per candidate, on the critical path
"Which stage best addresses passages that are topically similar but do not answer the question?"near-miss rejectionreranking
"What is the difference between a bi-encoder and a cross-encoder?"the core distinctionindependent encoding with precomputable vectors versus joint encoding with a per-pair score
"Which is cheaper to replace: the embedding model or the reranker?"the swap asymmetrythe reranker — nothing is stored, so no re-embedding is needed

Distractor families:

  • "Use a cross-encoder to search the corpus." Computationally infeasible; the definitive wrong answer.
  • "Reranking improves recall." It cannot. It reorders an existing list.
  • Reranking offered as the fix for recency, authority, or permissions. It helps with authority indirectly at best; the others need metadata (07-03, 07-05).
  • "A reranker produces embeddings you store in the vector database." It produces a score. Nothing is stored.
  • Reranking conflated with RRF fusion. Fusion merges lists by rank with no model; reranking re-scores one list with a model.
  • Reranking conflated with LLM-as-a-judge. One orders retrieved passages in production; the other evaluates generated answers, usually offline (09-10).
  • "Reranking is free because it does not touch the index." It is free of storage cost and expensive in per-request compute.
  • "Increase k instead of reranking." More context is not better context — see 07-08 on lost-in-the-middle.
07

Common mistakes with reranking

#SymptomCauseFix
1Reranker added, quality barely movedThe correct chunks were never in the candidate pool — a recall problem misdiagnosed as a precision problemCheck where the correct chunk sits in the top-50 before choosing an intervention (07-10)
2Reranking a top-5 pool changes almost nothingThe pool is too shallow — there is nothing meaningful to reorderRetrieve and fuse deeper (top-50 to top-100), then rerank, then truncate
3Latency became unacceptable after adding a rerankerPool size N was set without measuring; cost is linear in NSweep N against quality on the eval set and pick the knee; batch the candidates
4Long chunks score erraticallyThe chunk exceeded the cross-encoder's maximum sequence length and was silently truncatedKeep chunks inside the reranker's window; verify the limit explicitly
5Reranker scores treated as calibrated probabilities across corporaThey are trained relevance scores, not calibrated for your dataPick a threshold on your own labelled set; re-verify after any model change
6Reranking made results worse for some query typesModel–domain mismatch (e.g. a general-domain reranker on highly technical text), or a multilingual mismatchEvaluate the reranker on your own eval set; try a domain- or language-appropriate model
7Reranker used as the retriever for a small corpusFeasible at very small scale but wasteful and unscalable; also an architectural habit that will not survive growthKeep the cascade even when the corpus is small
8Permission filter applied only before reranking, not before retrievalRetrieval already read restricted data (07-05)Filter in stage one, in every leg
9Reranking added at the same time as three other changes; nobody can attribute the gainNo isolationOne change at a time against a frozen eval set (01-08, 03-04)
10Reranker is a single point of failure and the whole system errors when it is slowNo fallback pathDegrade gracefully to the fused ranking on timeout — a slightly worse order beats no answer
11Reranker output truncated to top-3 but all three score below 0.2No relevance floor appliedThreshold on reranker score and let the model decline when nothing clears it (07-11)

Mistakes 1 and 2 together account for most disappointing reranker deployments. The pattern is: quality is bad, a reranker is added because it is the well-known fix, the pool is left at top-5 because that is the existing retrieval config, and nothing improves — because the pool was thin and the real problem was recall. The corrective habit is the top-50 diagnostic, and it takes ten minutes.

Mistake 10 is worth building in from the start. The reranker is a network call to a model server on every request. Give it a timeout and a fallback to the pre-rerank ordering. A degraded ranking is a far better failure mode than an error page, and this is the kind of resilience the deployment objectives care about (12-14 on monitoring).

08

Why can't a cross-encoder be used for first-stage retrieval?

Because nothing about it is precomputable, and retrieval requires precomputation to be tractable.

Compare the work at query time for a corpus of N documents:

Bi-encoder retrievalCross-encoder scoring
Precomputed at index timeN passage vectorsnothing
Query-time model calls1 (encode the query)N (one per passage)
Query-time arithmeticN dot products, or sublinear with an ANN index (07-04)none — the model is the arithmetic
Feasible at N = 1,000,000yes, in millisecondsno — a million forward passes per query

The asymmetry is structural, not a matter of optimisation. A bi-encoder's passage vector is independent of the query, which is exactly what lets you compute it once and store it. A cross-encoder's score is a function of both texts jointly, so it cannot exist before the query arrives. The cross-encoder's accuracy and its unusability for retrieval come from the same property. That trade-off is the single most exam-relevant fact in this lesson, and it also explains why the two-stage cascade is not a workaround but the correct design: cheap-and-precomputable for the wide filter, expensive-and-joint for the narrow decision.

A related question people ask: why not use a cross-encoder to build a better index? You cannot, because there is no vector to index. Some research directions try to recover part of the cross-encoder's accuracy in a precomputable form — late-interaction models (ColBERT-style) store per-token vectors and do a cheap interaction at query time, landing between bi-encoder and cross-encoder on both cost and quality. Know that this middle ground exists; the exam's taxonomy is bi-encoder retrieval plus cross-encoder reranking.

09

Can an LLM be used as a reranker instead of a cross-encoder?

Yes, and it is a real technique with a clear trade-off.

How it works. Present the query and the candidate passages to an instruction-following LLM and ask it to rank them, score each, or select the most relevant. Variants include scoring one passage at a time, comparing pairs, and ranking a whole list in one prompt.

Cross-encoder rerankerLLM reranker
Model sizesmall to medium encoderlarge decoder
Cost per candidatelowhigh
Latencymodestsubstantial
Outputone scalar, directly sortabletext that must be parsed
Determinismhighlower — ordering can vary between runs (09-11)
Reasoning about complex constraintslimitedbetter
Needs prompt engineeringnoyes (05-02)
Positional biasminimalreal — list-wise prompts favour early or late items, related to 07-08
Suitable on the critical pathyessometimes, for low-volume or high-value queries

The honest summary: a cross-encoder is the right default for a production reranking stage because it is cheap, fast, deterministic, and purpose-trained. An LLM reranker is worth considering when queries carry complex multi-part constraints that benefit from actual reasoning, when volume is low enough that the cost is acceptable, or when you are prototyping and do not want to deploy another model.

Two cautions specific to LLM reranking. List-wise prompts have positional bias: the model's judgement is influenced by where a passage sits in the prompt, which is the same attention phenomenon that 07-08 covers as lost-in-the-middle. Shuffling and averaging across permutations mitigates it and multiplies the cost. And output parsing is a failure surface: an LLM asked to return a ranked list of ids will occasionally return prose, a hallucinated id, or a truncated list, so the code path needs validation and a fallback (05-05 on structured output).

Do not confuse either with LLM-as-a-judge (09-10), which scores generated answers during evaluation rather than retrieved passages during serving.

10

How do I measure whether reranking improved my RAG system?

By extending the same frozen-eval-set table this module has built since 07-01, and by measuring the right metric — which for reranking is not recall@10.

Use rank-sensitive metrics. Recall@10 asks whether the correct chunk is in the top 10. Reranking's job is to move it up within those 10, so recall@10 may not move at all while quality improves substantially. Metrics that see the improvement:

MetricWhat it capturesWhy it matters for reranking
recall@k for small k (k = 3, 5)is the correct chunk inside the real context budgetthe practical question — your context holds 3–5 chunks, not 10
MRR (mean reciprocal rank)1/rank of the first correct chunk, averageddirectly rewards moving the answer up
nDCG@kgraded relevance, discounted by positionthe standard ranking metric when some chunks are partially relevant
Precision@kfraction of the top-k that is relevantcatches the "two of three slots are generic" problem the worked example showed

09-05 covers metric selection generally and 09-07 covers RAG-specific metrics; the point here is narrower: a precision intervention measured with a recall metric will look like it did nothing. That mismatch is a common reason teams wrongly conclude reranking was not worth it.

The measurement sequence:

Configurationrecall@3MRRnDCG@5latency p95
Sparse only (07-01)
Dense only (07-02)
Hybrid, RRF (07-06)
Hybrid + rerank, N=25
Hybrid + rerank, N=50
Hybrid + rerank, N=100

The three N rows are the point. Reranking is not one decision but a pool-depth curve, and the curve has a knee: quality rises with N and then flattens while latency keeps climbing linearly. Find the knee on your own data and set N there. A default of 100 copied from a blog post is a latency bill you may be paying for nothing.

Two further checks:

Look at the queries that changed, not just the average. Confirm they moved for the reason you expect — a near-miss demoted, a paraphrase promoted, a mention-versus-explanation distinction made. If the wins are unexplainable, you may be measuring noise on a small eval set (09-09 on sample size).

Measure retrieval separately from generation. Reranking changes what enters the context; whether the answer improves also depends on assembly (07-08) and grounding (07-11). Attribute at the stage boundary, which is the whole method of 07-10.

Glossary recap: the terms this lesson introduced

TermDefinition
RerankingRe-scoring an already-retrieved candidate list with a more expensive model to improve its ordering
Cross-encoderA model that takes query and passage concatenated as one input and outputs a single relevance score
Bi-encoderA model that encodes query and passage independently so passage vectors can be precomputed (07-02)
Retrieve-and-rerank cascadeThe two-stage architecture: cheap wide retrieval, then expensive narrow re-scoring
Candidate pool / NHow many stage-one results are passed to the reranker; the dominant latency parameter
Joint encodingQuery and passage attending to each other inside the model at every layer — the source of the cross-encoder's accuracy
Precision interventionA change that improves ordering within retrieved candidates, as opposed to a recall intervention that improves coverage
Near-miss rejectionDemoting passages that are topically similar but do not answer the question
Mention versus explanationThe distinction between a passage containing the query's terms and one answering the query — invisible to similarity, visible jointly
Relevance floor / score thresholdA minimum reranker score below which candidates are dropped and the model may decline (07-11)
Late interactionMiddle-ground architectures (ColBERT-style) storing per-token vectors for a cheap query-time interaction
LLM rerankerUsing an instruction-following LLM to order candidates; more reasoning, higher cost, positional bias
MRR / nDCGRank-sensitive metrics that reveal a reranking improvement recall@10 would miss
Graceful degradationFalling back to the pre-rerank ordering when the reranker times out

Key takeaways on reranking with a cross-encoder

  • A cross-encoder reads query and passage together and outputs one relevance score. Joint encoding is why it beats a bi-encoder; not being precomputable is why it cannot retrieve.
  • Reranking improves precision, never recall. A chunk absent from the candidate pool cannot be promoted.
  • The worked example's headline result: the reranker separated d1 at 0.96 from d5 at 0.22, even though both contain the exact same rare error string. BM25 ranked d5 second for containing the term; the reranker recognised that mentioning a term and explaining it are different things.
  • Same example, second result: the second-best chunk moved from rank 5 to rank 2, rescuing exactly the document RRF's mutual-presence bias had buried.
  • Cost is per candidate, on the critical path. Latency is roughly linear in pool size N, so N must be set from a measured quality/latency curve, not from a default.
  • Reranking is the cheapest experiment in a RAG pipeline because nothing is stored — unlike changing the embedding model, which means re-embedding the corpus (12-12).
  • Measure it with rank-sensitive metrics — recall@3, MRR, nDCG@5. Recall@10 will often show no change while quality has improved substantially.
  • Diagnose before intervening. Correct chunk at rank 4–50 means rerank; absent from the top-50 means fix stage one; at rank 1 with a wrong answer means the problem is generation.
  • Give it a timeout and a fallback. Degrading to the fused ranking beats failing the request.

Next: assembling context and the lost-in-the-middle problem

You now have a small, correctly ordered set of passages. The obvious next move — paste them into the prompt and ask the question — turns out to contain a decision nobody mentions: in what order? Models do not attend uniformly across a long context, and information placed in the middle is systematically under-used compared with the same information placed at the start or the end. Next: 07-08 covers context assembly and the lost-in-the-middle effect: why a carefully reranked list can be squandered by a careless paste, how many chunks is too many, and why "more context" and "better context" are not the same thing.