4.4.14 · D3Alignment, Prompting & RAG

Worked examples — Reranking and hybrid search

3,250 words15 min readBack to topic

This page is the "run every case through the machine" companion to Reranking and hybrid search. We will not introduce new theory — we will exercise every corner of it: every fusion tie, every degenerate rank, every zero, and the limits where the formulas do something surprising.

Before any number appears, three plain-word definitions so no symbol is used unearned:

Before any number appears, one reminder of the two knobs we'll turn over and over:

Recall The two formulas we are exercising

RRF (rank-fusion): — uses only positions, never raw scores. BM25 saturation: — term frequency with diminishing returns; , (doc length) and (average doc length) defined above. Cosine: — the semantic score.


The scenario matrix

Every worked example below is tagged with the cell it covers. Read this table first — it is the whole space of things this topic can throw at you.

# Cell (case class) What is being stressed Example
C1 Rank tie / cross-verification doc in both lists beats a #1 in one Ex 1
C2 Only-one-list doc a doc missing from a retriever entirely Ex 2
C3 Choice of (limit and ) how smoothing changes winners Ex 3
C4 BM25 TF saturation limit () diminishing returns ceiling Ex 4
C5 BM25 length normalisation, vs long-doc penalty extremes Ex 4
C6 IDF sign: rare vs super-common term when IDF is large, small, or ≈0 Ex 5
C7 Cosine signs: aligned / orthogonal / opposite , , cases; the zero vector Ex 6
C8 Real-world word problem full hybrid→rerank pipeline decision Ex 7
C9 Exam twist: "bigger top-k vs rerank" lost-in-the-middle trade-off, numeric Ex 8
C10 Degenerate: rerank cannot recall doc absent from top-100 Ex 9

Prereqs if any cell feels shaky: BM25 and TF-IDF, Embeddings and Bi-encoders, Cross-encoders and Sentence Transformers, Evaluation - Recall@k and MRR.


Example 1 — C1 · The cross-verified doc wins a tie

  1. Write each doc's contributions. Why this step? RRF is a sum of over the lists the doc appears in — nothing else matters, so we just list the ranks.

  2. Evaluate. Why this step? We need the actual numbers to compare — the fractions are close, so intuition can mislead.

  3. Compare. , so A wins here — barely. Why this step? This is the deliberate contrast with the parent note's tiny example (where B won). The difference: there A was rank 4 in dense; here A is rank 5 but its #1 is strong enough. RRF is a genuine trade-off, not a rule of thumb.


Example 2 — C2 · A doc that only one retriever found

  1. Model "absent" correctly. Why this step? If a doc is not in a retriever's returned list, it contributes nothing from that retriever (the term is simply omitted, not set to some huge rank). This is the crux of the case.

  2. Sum D's two contributions. Why this step? D is cross-verified — present in both lists — so it accumulates two terms.

  3. Compare. , so D wins comfortably. Why this step? This is the whole philosophy of hybrid: agreement across modalities (lexical and semantic) beats a lone strong signal. A doc found by both retrievers is safer evidence.


Example 3 — C3 · The limit behaviour of

  1. Case (winner-take-all). Why this step? Setting makes rank-1 worth , dwarfing everything. This exposes what was protecting us from. A wins by a landslide — a single #1 dominates.

  2. Case large, e.g. . Why this step? Large flattens the gap between ranks, so what matters is how many lists you appear in and their average rank, not the exact position. The two are a dead heat to five decimals — A still edges B by less than , so the near-tie is the real lesson: rank position has almost stopped mattering.

  3. Read the limit. As , every , so a doc in lists scores only the count of appearances survives, ranks vanish. Why this step? This tells you why the default is a compromise: small enough that rank order still matters, large enough that rank-1 isn't dictatorial. Both A and B appear in lists, so at the infinite- limit they become exactly equal.


Example 4 — C4 & C5 · BM25 saturation and the two length extremes

  1. Set up the saturating fraction with . Why this step? With the length term collapses to , isolating pure TF saturation.

  2. Evaluate the ladder. Why this step? Watch the diminishing returns: going adds ; adds only ; the hard ceiling is . That is the "50th cat tells us nothing" effect made numeric.

  3. Now length, , , doc twice as long. Why this step? turns on full length normalisation; a long doc (its is twice ) is "diluting" its 5 hits. Compare to the value at which was : the long doc is penalised from down to .

The figure below plots this. The lavender curve is (length ignored) and the coral curve is on a doc twice the average length — notice how coral sits below lavender everywhere (the length penalty) and how both flatten toward the mint dashed ceiling at as grows. The two slate dots mark on each curve, the exact numbers from step 3.

Figure — Reranking and hybrid search

Example 5 — C6 · IDF across the sign spectrum: rare, common, and ubiquitous terms

  1. Rare term, . Why this step? This is the discriminating case — the whole point of IDF is to reward rarity.

  2. Common term, (half the corpus). Why this step? At exactly half the corpus the log argument is , so and IDF flattens to the floor. This term barely discriminates.

  3. Ubiquitous term, . Why this step? The log goes negative — the raw BM25 IDF can be negative for terms in almost every doc. This is why production BM25 often floors IDF at : a "stopword-like" term shouldn't actively subtract from relevance.


Example 6 — C7 · Cosine at every sign, and the degenerate zero vector

  1. Compute once. Why this step? Cosine normalises out magnitude — only direction matters — so we need the length. .

  2. — same direction. Perfect semantic alignment → score . Why: , so same direction regardless of scale.

  3. — perpendicular. Unrelated meaning → score . Why: dot product zero means the vectors share no directional overlap.

  4. — opposite. Anti-aligned → score (the floor of the range). Why: .

  5. — the degenerate case. Why this step? An empty/padding chunk can embed near-zero. The denominator has , so cosine is — undefined. In code this is a divide-by-zero. Fix: guard with an or drop zero-norm vectors before ranking.

The figure shows all four as arrows from the origin against the lavender query arrow : the mint doc points the same way (score ), the butter doc is at a right angle (score ), the coral doc points in exactly the opposite direction (score ), and the slate dot at the origin is the zero vector — it has no direction at all, so its cosine is undefined. Reading the picture, the closer a doc arrow's direction is to the lavender query arrow, the higher its cosine — that single geometric fact is the whole of dense scoring.

Figure — Reranking and hybrid search

Example 7 — C8 · Real-world pipeline decision

  1. RRF each chunk. Why this step? Fusion ranks . Q wins because it's strong in both lists, even without the literal code.

  2. Cross-encoder pass (precision step). Why this step? Cross-encoders read query+chunk jointly. R contains AUTH_88 but is about a build tag, not about resetting MFA — joint attention detects the mismatch and scores R low despite the exact token. P and Q both genuinely answer; Q gives the actual reset steps. Expected reranked order: Q > P > R.

  3. Decision. Send Q as top-1, P as top-2, drop R. Why this step? This is the whole thesis of the parent note in one example — lexical recall keeps P and R in the pool, semantic recall surfaces Q, fusion prefers the cross-verified Q, and the reranker punishes R's surface-only match.


Example 8 — C9 · Exam twist: "just raise top-k into the LLM"

  1. Usefulness with reranking, . Why this step? Reranking places the true answer near the top, so it sits at a low position.

  2. Usefulness without reranking, . Why this step? A raw large top-k dumps the answer wherever retrieval happened to rank it — often deep in the middle.

  3. Fraction lost. Why this step? This is the numeric spine of the lost-in-the-middle mistake — a bigger, unranked context can throw away ~77% of the answer's usefulness, plus adds latency and cost.


Example 9 — C10 · The degenerate limit: rerank can never recall

  1. Recall@100. Why this step? Recall@k = (relevant items in top-k) / (total relevant). The gold chunk is at 137, outside 100.

  2. Best possible Recall@5 after reranking. Why this step? A reranker can only reorder its input set. The gold chunk was never in the input, so it cannot appear in any reranked output. No matter how good the cross-encoder is, is the ceiling.

  3. The lesson. Reranking is a precision operation on a fixed pool; it has zero power to recall a missing document. Why this step? This is the fourth parent-note mistake as a hard number: invest in retrieval recall (hybrid, better chunking, larger candidate pool) before spending on reranking.


Recall check

Recall When does a lone rank-1 doc lose to a rank-3 doc in both lists?

When the two mid-rank contributions sum above the single strong one — i.e. cross-verification beats a spike once is large enough to soften rank-1's dominance (Ex 1–3).

Recall What is the hard ceiling of a BM25 term contribution as

? — term frequency saturates, so the 100th occurrence adds almost nothing (Ex 4).

Recall What do

and mean in BM25? = length (token count) of the document being scored; = average token count across the corpus. Their ratio says how long this doc is versus typical (Ex 4).

Recall Why is cosine undefined for a zero-norm document embedding?

The denominator becomes , giving ; guard with or drop zero vectors (Ex 6).

Recall Can a perfect reranker fix a document that retrieval placed at rank 137 of a top-100?

No — reranking only reorders its input pool; recall must be fixed at retrieval time (Ex 9).

Back to parent: Reranking and hybrid search.