Reading tools and contents
Retrieval Engineering

Chapter 7 of 10

Reranking, late interaction, and result diversity

Ranking

About 4 minutes · includes examples, an exercise, and references

Chapter at a glance

  • Reranking can reorder candidates but cannot repair candidate-recall failures.
  • Cross-encoder inputs, truncation, and model version are part of the ranking contract.
  • Diversity optimizes the returned set, not only independent document scores.

Candidate retrievers compress interaction to gain speed. BM25 uses term statistics; a dual encoder compares independently computed vectors. Reranking restores richer query-document interaction over a bounded candidate set. A cross-encoder jointly encodes the query and passage, allowing attention between their tokens before predicting relevance. It can distinguish fine qualifications and negation that a single vector misses, but it cannot economically score the entire corpus.

The reranking contract begins with candidate recall. If relevant evidence is absent from the candidate pool, a perfect reranker cannot recover it. Measure recall at the exact reranker input depth. Then measure whether reranking improves ordering through nDCG, MRR, precision, and task-specific grades. Keep a no-reranker baseline. A stronger final metric with poor candidate recall may conceal brittle dependence on a narrow test set.

Cross-encoder input construction affects behavior. Decide whether to include title, heading path, source type, dates, and limited surrounding text. Use delimiters and a deterministic truncation policy. Putting the query first does not guarantee the decisive end of a long passage survives. Track truncation. Never insert confidential metadata solely as hidden ranking hints if it is not authorized for model processing.

BERT passage reranking established a common pattern: retrieve with an efficient first stage, then apply a pretrained transformer to query-passage pairs. Modern rerankers vary in training objective and output. A logit is not a calibrated relevance probability. Use ranking metrics directly; if a product needs a threshold for “no useful result,” calibrate on representative held-out judgments and monitor drift. Do not reuse a threshold across model versions.

Late-interaction models such as ColBERT precompute token-level document vectors and compare each query token with its strongest document-token match. They retain more granular interaction than a single-vector dual encoder while reusing document computation. The trade-off is larger storage and a specialized retrieval path. They can act as candidate generator or reranker. Benchmark the complete system, including index size and query-time aggregation.

Ranking one passage at a time can produce a redundant list. Several adjacent chunks from the same source may occupy every slot. Diversification balances relevance with novelty. Maximal Marginal Relevance selects an item using query relevance minus a penalty for similarity to already selected items. Business rules may cap passages per parent document, prefer source diversity, or ensure coverage of requested facets. Such rules should operate on stable metadata and be evaluated for both relevance and coverage.

Reranking may incorporate non-text features: freshness, authority, source quality, product version, popularity, or user context. Separate hard constraints from learned preferences. An expired or unauthorized document should be filtered, not merely downweighted. Feature provenance and time must be explicit. Popularity can create a feedback loop in which already visible documents accumulate signals and suppress better new content.

Training data deserves careful negative design. Random negatives teach easy separation; retrieved hard negatives teach distinctions near the decision boundary. False negatives are especially damaging when multiple passages answer a query but only one was labelled. Use graded judgments or positive sets when available. Split by time or topic to avoid near-duplicate leakage. Evaluate zero-shot behavior if the service spans domains not represented in training.

Serving needs dynamic batching, model versioning, deadlines, and fallbacks. Group query-passage pairs while respecting tenant isolation and latency. If the reranker exceeds its budget, choose a declared policy: return fused candidates labelled with fallback, reduce depth, or fail for high-consequence workflows. Never silently mix scores from old and new model versions within one response. Log candidate order before and after, input hashes, truncation, model digest, latency, and fallback reason.

Debug by paired comparison. For an incorrectly promoted passage, inspect the exact model input, truncated text, component retrieval evidence, and nearby judged alternatives. Check whether the model exploited boilerplate or query repetition. For a demoted relevant passage, inspect missing context, numbers, negation, and domain terminology. Use counterfactual tests that alter one factor—date, heading, phrase, or negation—while preserving others.

Reranking earns its cost when it resolves ambiguities that fast retrieval cannot. Diversity earns its cost when the user needs coverage rather than repeated evidence. Both are policies within a measured pipeline, not universal finishing steps.

Key points

  • Reranking can reorder candidates but cannot repair candidate-recall failures.
  • Cross-encoder inputs, truncation, and model version are part of the ranking contract.
  • Diversity optimizes the returned set, not only independent document scores.
  • Hard constraints must be enforced as filters rather than learned ranking preferences.

Diversify a ranked candidate list with MMR

Read the expected behavior in the surrounding walkthrough, then copy and run this reference implementation.

Diversify a ranked candidate list with MMRpython
def mmr(candidates, relevance, similarity, limit=3, weight=0.75):
    chosen = []
    remaining = list(candidates)
    while remaining and len(chosen) < limit:
        def value(item):
            redundancy = max((similarity(item, prior) for prior in chosen), default=0.0)
            return weight * relevance[item] - (1 - weight) * redundancy
        best = max(remaining, key=lambda item: (value(item), item))
        chosen.append(best)
        remaining.remove(best)
    return chosen

scores = {"a": .95, "b": .92, "c": .80, "d": .76}
parent = {"a": 1, "b": 1, "c": 2, "d": 3}
similarity = lambda x, y: .95 if parent[x] == parent[y] else .15
print(mmr(scores, scores, similarity))

Exercise

Evaluate a reranking layer

Add reranking and diversity to a hybrid documentation search system.

  1. Define deterministic model inputs, truncation, and fallback behavior.
  2. Compare fused and reranked results by candidate recall, final nDCG, latency, and domain slice.
  3. Add a diversity policy and measure source coverage versus relevance loss.

Success criteria

  • Candidate misses are not attributed to the reranker.
  • A timeout returns a declared, observable outcome.
  • Hard authorization and validity rules remain outside the learned score.

Reflect: Which ambiguity requires query-document interaction rather than a better embedding?

References and further reading