Two-Stage Retrieval and Reranking for RAG
2026
Course project for Deep Machine Learning (SSY340): a fixed bi-encoder retrieves candidate passages, then a fine-tuned cross-encoder reranks them. The interesting part was not the model but the evaluation — BEIR benchmarks, paired bootstrap and an end-to-end latency budget.
- Python
- PyTorch
- sentence-transformers
- Cross-encoder
- BEIR
- RAGAS
- Evaluation
- Fixed `all-MiniLM-L6-v2` bi-encoder retrieves top-100; compared the public MS MARCO cross-encoder against a `distilbert-base-uncased` model with a new scoring head, fine-tuned on up to 100k pairs.
- Trained with random, hard, denoised and mixed negatives and evaluated on BEIR SciFact, NFCorpus and FiQA with HR@10, MRR@10, nDCG@10 and latency.
- Added RAGAS faithfulness and answer relevancy on ~100 FiQA answers from a local LLM, so the answer quality was measured and not just the ranking.
- Retrieval stayed flat at ~7.5 ms; reranking scaled linearly with depth, our model ran 2–2.7× slower, and the LLM's ~4 s dominated end-to-end latency.
The question
A RAG system usually retrieves with a cheap bi-encoder and then reranks a shortlist with a cross-encoder that sees query and passage together. The second stage is more accurate and much more expensive. The practical question is whether a model you fine-tune yourself can beat the public reranker at a latency you can actually serve.
So the comparison was deliberately fixed on one side: the same `all-MiniLM-L6-v2` bi-encoder retrieves the top 100 for every method. Everything after that is what we varied.
How it works
- The bi-encoder is held fixed and retrieves the top 100 candidates, so the reranker is compared on the same shortlist rather than on a different retrieval quality.
- The public baseline is `ms-marco-MiniLM-L-6-v2`, a cross-encoder trained for exactly this job.
- Our model is `distilbert-base-uncased` with a new scoring head and training loop, fine-tuned on up to 100k MS MARCO query-passage pairs.
- Negative sampling was the main lever: random negatives, hard negatives mined from the retriever, denoised negatives, and a mixed schedule combining them.
- Evaluation runs on three BEIR datasets with different characters — SciFact for scientific claims, NFCorpus for biomedical text and FiQA for financial questions — using HR@10, MRR@10, nDCG@10 and measured latency.
- Answer quality is checked separately with RAGAS faithfulness and answer relevancy on ~100 FiQA answers generated by a local LLM.
- Differences are tested with a paired bootstrap over 2,000 resamples rather than treating a small metric gap as real.
Results
The public reranker's gain is clear on SciFact and NFCorpus, and much less clear on FiQA. Our fine-tuned model came out below MiniLM overall, with a tie on NFCorpus. More training pairs helped, but not enough to close the gap.
The latency result was the one that changed how I think about the pipeline. Retrieval stayed flat at about 7.5 ms regardless of depth. Reranking grew linearly with the number of candidates, our model ran 2–2.7× slower than MiniLM, and the LLM's roughly 4 seconds dominated end-to-end latency by an order of magnitude. Optimising the reranker is not where the user-perceived time goes.
What I learned
Fixing the retriever was the right call. Without it, a better reranker and a better shortlist are indistinguishable, and the result says nothing about the component you meant to test.
The honest result is that a small fine-tune on 100k pairs did not beat a model trained for the task by people with more data and more compute. What it did produce was a defensible comparison, a latency budget and a clear statement of where the remaining error lives — which is the part I would trust in a production decision.