Back to Hub

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.

Documents split into sections, a first search, a reranker, and the top five sections
How the search works.

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

Line chart of recall and mean reciprocal rank as each change is added
Each point adds one change to the one before. 50 questions.
StepRecall@5MRR@10Median query
Fixed windows, embeddings0.6400.5243 ms
+ chunk by headings0.7600.5534 ms
+ full-text search0.6800.5277 ms
+ reranker0.8800.739107 ms
+ query rewriting0.9200.799280 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.

Source code