Sub topic 10
Failure modes and debugging
This chapter assumes you have built a retrieve-then-rerank pipeline, can read cross-encoder scores, and know recall@k and MRR. It shows how to find which stage is failing when results look wrong.
Locate the failing stage first
A bad final ranking has one of two causes. Either the relevant passage never reached the reranker, or the reranker saw it and ranked it too low. The fixes differ, so test this before changing anything.
Run this check over a labeled query set:
def diagnose(pool_ids, reranked_ids, relevant, k=3):
if not set(pool_ids) & relevant:
return "pool_miss"
if set(reranked_ids[:k]) & relevant:
return "ok"
return "reranker_miss"
cases = {
"q1": (["d4", "d9", "d2"], ["d2", "d4", "d9"], {"d2"}),
"q2": (["d4", "d9", "d2"], ["d4", "d9", "d2"], {"d2"}),
"q3": (["d4", "d9", "d5"], ["d5", "d4", "d9"], {"d7"}),
}
for name, (pool, ranked, rel) in cases.items():
print(name, diagnose(pool, ranked, rel, k=1))The output is ok, reranker_miss, and pool_miss. If most failures are pool misses, a better reranker will not help. Raise the candidate depth, add lexical retrieval (see the hybrid fusion chapter), or fix your chunking.
Common reranker misses
Truncation
A cross-encoder reads the query and passage as one sequence and cuts it at max_length, often 512 tokens. If the answer sits in the cut-off tail of a long passage, the model never sees it. The score is computed from the visible part only, and no error is raised.
To debug, tokenize your passages and count how many exceed the limit. If many do, split them into smaller chunks, score each chunk, and take the maximum score per document.
Domain mismatch
Models trained on web search data, such as MS MARCO, can do poorly on legal, medical, or code text. Typical signs are that the reranker scores below the first stage's order on your labeled set, or that it favors fluent generic passages over passages with exact identifiers. Compare MRR before and after reranking. If reranking lowers it, try another model or fine-tune on your own data.
Misreading scores
Raw scores from many models are logits. They are not calibrated probabilities. Two mistakes are common:
- Setting a fixed threshold such as 0.5 and expecting it to mean "relevant".
- Comparing scores across different queries. Scores order passages within one query, and that is all they are reliable for.
If you need a cutoff, pick it from a labeled validation set for your own model and data.
Smaller causes
- Ties and unstable order. Sort with a fixed tie-breaker, such as the first-stage rank, so results are reproducible.
- Input order mismatch. Keep the scores aligned with the passage ids. Sorting the scores separately from the passages is a frequent bug.
- Query format. Using a query prefix or instruction that the model was not trained with can shift scores.
A debugging routine
- Build 50 or more labeled queries from real traffic.
- Compute the pool recall@depth. This is the upper bound on what the reranker can achieve.
- Compute MRR and nDCG before and after reranking.
- Read the 10 worst
reranker_misscases by hand. Check length, domain terms, and score values. - Change one thing at a time and re-run.
Exercise
Your reranked MRR is low, and 40% of your labeled queries are classified as pool_miss. Should you swap to a larger cross-encoder? What do you do instead?
Show answer
No. For those queries the relevant passage never reaches the reranker, so a larger model cannot help. Raise the candidate depth, add lexical retrieval with rank fusion, or fix chunking so the relevant text is retrievable. Then re-measure pool recall before judging the reranker.