Sub topic 7
How many candidates to rerank
This chapter assumes you can run the two-stage pipeline from the previous chapters. You should also know recall@k and MRR from the evaluation chapter. Here you will choose the candidate depth: the number of passages the first stage hands to the cross-encoder.
Why depth is a trade-off
A reranker can only reorder what it receives. If the relevant passage is not in the candidate pool, no model can promote it. The pool size is k_retrieve in the pipeline code.
- A small pool is fast, but it risks missing the relevant passage.
- A large pool raises the chance of including it, but cross-encoder cost grows linearly with the pool size. Each candidate needs one full forward pass.
- A very large pool also gives the reranker more near-miss passages that can outscore the right one.
Measure recall at several depths
Use the first-stage recall@k as an upper bound on what reranking can achieve. Compute it for several values of k on a labeled set of queries, then look for the point where gains flatten.
def recall_at_k(ranked_ids, relevant, k):
return len(set(ranked_ids[:k]) & relevant) / len(relevant)
def recall_curve(runs, depths):
# runs: list of (ranked_ids, relevant_set), one per query
return {
k: sum(recall_at_k(r, rel, k) for r, rel in runs) / len(runs)
for k in depths
}
runs = [
([f"d{i}" for i in [4, 9, 2, 7, 1, 3, 8, 5, 6, 0]], {"d1"}),
([f"d{i}" for i in [2, 1, 5, 3, 4, 6, 7, 8, 9, 0]], {"d1", "d5"}),
([f"d{i}" for i in [6, 3, 8, 0, 2, 9, 4, 7, 5, 1]], {"d1"}),
]
for k, value in recall_curve(runs, [1, 3, 5, 10]).items():
print(f"recall@{k} = {value:.2f}")On this toy data, recall rises from 0.00 at k=1 to 1.00 at k=10. In a real system you would test depths such as 10, 25, 50, 100, and 200.
Pick a depth
- Compute recall@k for the first stage at several depths.
- Find the smallest k where recall is close to its plateau. For example, choose the depth that reaches 98% of the recall you see at the largest depth.
- Run the full pipeline at that depth and at a few neighbors. Compare the final MRR or nDCG@10.
- Check latency at the chosen depth against your budget. If it is over budget, reduce k and accept the lower recall, or use a smaller model.
Typical starting points are 50 to 100 candidates for a small cross-encoder such as MiniLM. Treat these as starting points only. The right value depends on your corpus, your first stage, and your latency budget.
When a bigger pool hurts
Final quality can fall when you increase depth. A cross-encoder trained on a general dataset may score a loosely related passage above the correct one. More candidates means more chances for this. If your quality curve peaks and then declines, use the depth at the peak. Then look at the failure modes chapter to find out why the extra candidates hurt.
Exercise
A first stage has recall@20 = 0.90, recall@50 = 0.96, and recall@200 = 0.97. Reranking 200 candidates takes four times as long as reranking 50. Which depth would you start with, and why?
Show answer
Start with 50. Going from 50 to 200 adds only one point of recall (0.96 to 0.97) while quadrupling reranker latency. Then check final MRR or nDCG at 50 and its neighbors to confirm the choice.