A very typical bad case: among the 30 fused candidates, the passage that actually answers the question ranks 11th. Recall is fine—Recall@30 equals 1. But the final context only holds 5 items, and the model never sees it.
Switching embedding models or tuning RRF parameters won’t change this ranking. The problem isn’t “can it be recalled,” but “has the ranking model looked at both the query and the document together.”
The first stage optimizes for recall, the second for precision. That single sentence is the entire reason reranking exists.
Post 9/15 in this series · Previous: Hybrid Retrieval: Sparse, Dense, and Score Fusion · Next: Context Construction: It Only Begins After Recall
Dual encoders rank poorly, and no amount of tuning fixes it
As covered in post 6, a dual encoder compresses the query and the document into vectors separately, with zero interaction during encoding. This design makes retrieval over tens of millions of candidates possible, at the cost that qualifiers, negations, time ranges, and comparisons in the query never get to align token by token with the specific wording in the document. A vector can only express “how similar overall.”
A reranking model adds the interaction back. The most typical is the cross-encoder, which concatenates the two texts into a single sequence and feeds it to the model:
1 | [CLS] 查询文本 [SEP] 候选文档文本 [SEP] → 相关性 logit |
Self-attention is fully connected between query tokens and document tokens, so the model can see details like “the document says 2024 edition, but the query asks for 2026 edition.”
The cost is equally direct: the document side can’t be precomputed. Every candidate requires a fresh forward pass against the current query—30 candidates means 30 inferences (or one batched pass). So a cross-encoder can only sit after recall, where candidates have already been narrowed to a few dozen, and can never be used to scan the whole corpus.
This is the economics of the two-stage architecture: use a cheap, precomputable method to shrink N to K, then use an expensive, interactive method to order K.
flowchart LR A[全库候选 N] --> B[双编码器召回] B --> C[候选 K 约 30 条] C --> D[Cross-Encoder 重排] D --> E[Top 5 进上下文] E --> F[生成]
Three kinds of rerankers: where the cost is, where the savings are
Cross-Encoder: full interaction, highest precision, usually also the slowest. Suited to scenarios with 20–50 final candidates and tolerance for tens to hundreds of milliseconds of extra latency. One easily overlooked point: it outputs logits, not probabilities, which aren’t comparable across queries and can only be used for ranking within a single query. If you want to use it to “refuse to answer when relevance is below a threshold,” calibrate on the same batch of candidates first—don’t just slap on a 0.5.
Late-interaction models (ColBERT and the like): the query and document are each encoded into token-level vector sets; scoring takes the max over the most similar document token for each query token, then sums over the query side—i.e., MaxSim. The document-side token representations can be precomputed offline and stored; online you only compute the query side and a set of MaxSim operations. It sits between the dual encoder and the cross-encoder: it preserves more word-level alignment than a dual encoder and costs far less than a cross-encoder. The price is storage bloat—each chunk stores a set of token vectors instead of one, and at millions of chunks the index size can be an order of magnitude larger. This is a very real trade-off; do the storage math before choosing, or you’ll find out at launch that the index doesn’t fit in memory.
LLM reranking: hand the candidate list with indices to a large model and have it output a ranking. Three forms:
| Form | Input | Output | Characteristics |
|---|---|---|---|
| Pointwise | A single (q, d) | Relevance score/grade | Parallelizable, but can’t see relative relationships among candidates |
| Pairwise | (q, d1, d2) | Which is better | Good precision, but the number of comparisons grows with the square of candidates |
| Listwise | All candidates at once | Reranked index list | One call, but affected by context length and position bias |
Listwise saves the most calls, but has two pitfalls. First, it’s sensitive to input order—how candidates are arranged affects the output, so you usually need to shuffle or run multiple sliding windows. Second, as candidates grow, stuffing indices and text in together drives up both context cost and attention dilution. I generally use listwise only for 10–20 candidates, and require the model to output only the index sequence with no explanations, for easy parsing and validation.
The real advantage of LLM reranking is handling complex judgments: timeliness, authority, whether it directly answers the question or merely grazes the keywords. These are awkward to write as rules. The cost is latency (hundreds of milliseconds to seconds) and expense, plus unstable output—index validity, deduplication, and filling in missing entries all need validation.
The reranking budget: K, L, and model tier
Total two-stage latency is roughly:
1 | T_total ≈ T_recall(两路并发) + T_rerank(batch) + T_context + T_generate_first_token |
The reranking term is determined by three quantities: the number of candidates K, the token length per item L, and model size plus whether a GPU is used. A cross-encoder typically batches (q, d_i) into one forward pass, so latency grows roughly linearly with K (until you hit VRAM or batch limits), not as K serial calls.
My tuning process is to fix an evaluation set and sweep “candidate depth × model tier,” recording nDCG@5 and P95 latency:
| K | Small model P95 | nDCG@5 | Large model P95 | nDCG@5 |
|---|---|---|---|---|
| 10 | Low | Limited gain | Medium | Medium |
| 30 | Medium | Clear gain | High | Better |
| 50 | Medium–high | Gains flatten | Very high | Gains flatten |
Real numbers vary widely with model, corpus, and hardware; this table only shows the shape: the benefit curve usually flattens after K=20–40 while latency keeps rising. So don’t blindly set reranking candidates to 100. The more cost-effective order is usually to ensure recall depth is sufficient (50 per route, as in post 8), keep reranking candidates around 30, and leave the saved budget for generation.
A few concrete ways to cut latency, ordered from low to high effort:
- Cache reranking scores for identical queries or identical (query, chunk_id) pairs—this pays off almost immediately on high-frequency Q&A;
- Truncate candidates to the reranking model’s limit by embed_text length—don’t stuff in the whole parent document, since the longest item in the batch determines the time;
- Cascade: use a very lightweight model to filter 50 down to 15, then a strong model to rank those 15;
- Distill: score on business logs with a strong cross-encoder or LLM, distill a small model for production—the biggest investment, but the most worthwhile for high-QPS systems;
- Run reranking concurrently with the parts of context construction that don’t depend on the ranking result (fetching parent documents, pulling metadata).
How you use it after ranking is more likely to go wrong than how you rank
Scores are not comparable across batches. Cross-encoder logits, LLM-assigned grades, and RRF fusion scores cannot be used as global confidence. When I discuss refusal in article 11, I’ll stress: to use a threshold to judge “is there relevant material,” you need to make relative judgments within the same candidate batch (the gap between top1 and top2, whether top1 is clearly above the median), or train a separately calibrated discriminator.
Don’t use reranking as a filter too aggressively. Some queries genuinely need multiple pieces of complementary evidence; keeping only top1 discards supporting material. I typically send 5–8 items in the end, with a source-diversity constraint (the same doc_id contributes at most 2 items, unless they come from different sections).
Monitor ranking stability. LLM reranking is especially prone to giving different results for the same input twice, which shows up in production as answer jitter. I log the top5 IDs before and after each rerank, and turn the proportion of “inconsistent ordering across repeated requests for the same query” into a monitoring metric; when it exceeds the threshold, fall back to the more deterministic cross-encoder.
Degradation path. If the rerank service times out or returns invalid output, just take top N from the original fused order, mark degraded=true, and never let the whole request fail. This branch must actually be exercised in load testing; article 7 said the same thing—a degradation path that has never been walked is equivalent to not existing.
nDCG went up but answers didn’t improve—where’s the problem
The recall stage looks at Recall@K; the ranking stage is better suited to nDCG@K or MRR: the former cares about “whether it’s there,” the latter about “ranked near the top with reasonable relevance grading.” I track three sets of numbers at once:
- Retrieval layer: Recall@30 of the fused candidates—this is the ceiling for reranking; reranking cannot rescue what wasn’t recalled;
- Ranking layer: nDCG@5 and MRR of the top5 after reranking;
- End-to-end: faithfulness and answerability of the final answer, plus P95 latency and per-request cost.
Looking only at the second set is self-deception. nDCG goes up but answers don’t improve—the common cause is that the final context already had room for the correct answer, so the ranking gain didn’t translate into generation benefit. Conversely, end-to-end getting worse may also be the fault of context construction (article 10), not entirely reranking. Only by looking at all three sets together do you know which layer to invest people in.
When you shouldn’t add reranking
Benefits: with recall width unchanged, push the correct answer to the position the model will actually read; handle fine-grained judgments that require interaction, such as recency, negation, and multiple conditions; and it also allows the first stage to use cheaper, rougher retrieval—reranking will fix it later, and the overall cost often ends up lower.
Costs: an extra model service and latency; candidate depth, model tier, and truncation length form a new parameter space; LLM reranking also brings uncertainty and cost; scores are not comparable, so refusal requires separate design.
When not to do it: when the corpus is small and each query has only one or two relevant documents, ranking is meaningless (my own blog RAG with a few hundred chunks doesn’t use reranking); when the latency budget is extremely tight, or there’s no GPU in the deployment environment at all; and when recall itself is inadequate—when Recall@50 is low, go back and fix chunking, embeddings, and hybrid retrieval first; adding reranking just arranges the wrong candidates more neatly.
By this article, the pipeline from corpus to “sorted candidate chunks” is complete. But even with the chunks correctly ranked, the answer can still be wrong: five chunks are all relevant, yet change the concatenation order and the model answers the opposite; chunks are too long, and key information gets squeezed into the middle of the context where nobody looks. The next article covers context construction after recall. How many chunks are you currently sending into the model in production, and what position is the most relevant one usually at?
Comments