Rerank the top candidates with a cross-encoder
The fused list is a good pool, but its order is rough.
| Bi-encoder | Cross-encoder | |
|---|---|---|
| reads | the query and each chunk apart, as vectors | the query and the chunk together, in one model |
| runs | ahead of time, once for every chunk | now, once for every query and chunk pair |
| used for | searching the whole index, fast | rescoring only the top candidates, slower and more accurate |
First-stage retrieval uses a bi-encoder: the query and each chunk are embedded separately. Every chunk's vector is ready ahead of time, which is what makes searching an index fast.
A cross-encoder reads the query and the chunk together and scores the pair. It's slower and more accurate. The Sentence Transformers documentation puts the trade in one line: cross-encoders perform better than bi-encoders, but they don't scale well to large datasets.
So the standard pattern retrieves with the fast model and reranks only the top hits. The documentation's example reranks 100 hits. Anthropic reranked the top 150 retrieved chunks down to 20.
The cost grows with the number of candidates. Part 4 prices it.
In the editor, write rerank(fused, n, keep): rescore the top n of the fused list, and keep the best. cross_score stands in for the cross-encoder, and it rates c30 far above the rest, so a cut of 30 or fewer never sees it.