What actually improved retrieval? An ablation on real documentation
What is RAG?
Before an AI model can answer questions about your documents, the relevant parts have to be found and given to it. This project improves that search one step at a time and checks whether the section with the answer is found.
The question
There are many suggested ways to improve retrieval-augmented generation (RAG), and it is easy to add all of them without finding out which ones helped. I wanted to add them one at a time to the same corpus and the same questions, and measure each.
How it works
The corpus is the Model Context Protocol documentation: 37 documents. The evaluation set is 50 questions, each with the passage that answers it marked. A retrieved chunk counts if it holds at least half of that passage, so different ways of chunking can be compared fairly. Storage is Postgres with pgvector for embeddings and its built-in full-text search. All models run locally.
Results
| Step | Recall@5 | MRR@10 | Median query |
|---|---|---|---|
| Fixed windows, embeddings | 0.640 | 0.524 | 3 ms |
| + chunk by headings | 0.760 | 0.553 | 4 ms |
| + full-text search | 0.680 | 0.527 | 7 ms |
| + reranker | 0.880 | 0.739 | 107 ms |
| + query rewriting | 0.920 | 0.799 | 280 ms |
The reranker helped the most. Adding full-text search made things worse: merged with embedding search it lowered recall within a 6,000-character budget from 0.80 to 0.68. Under the reranker those extra candidates may recover a little (recall@5 0.84 without them, 0.88 with), but 50 questions cannot establish that.
What I learned
"Hybrid search" is often presented as a free improvement. Here, simply merging a weaker set of results with a stronger one made the results worse. It may be different on other documents, so it is worth measuring.
The test itself also matters. The final pipeline failed three questions, and for each one a passage near the top did answer it, just not the one passage marked as correct. A single "correct" passage per question undercounts, which only showed up on reading the failures. The scores are reported as measured.
Disclosure: this project was written with AI coding agents, including the 50 questions and their marked passages. Nobody has independently reviewed them.
What's next
Several acceptable passages per question, questions written by someone who has not read the documents, a larger corpus, tuned fusion weights, and scoring generated answers as well as retrieval.