Retrieval is where most RAG quality is won or lost. If the right passage never reaches the model, no prompt will save the answer. And the two common ways of finding that passage each have a blind spot.
Two retrievers, two kinds of miss
BM25 ranks by term matches. It's strong on exact things: error codes, product names, plan names, identifiers. It has no idea that "get my money back" and "refund" mean the same thing.
Embedding search has the opposite profile. It handles paraphrase well and can be weak on the exact token someone typed, because similar-sounding text scores close together even when the specific code or name differs.
So you run both. That leaves one awkward question: how do you merge two ranked lists?
Why adding the scores doesn't work
The obvious approach is a weighted sum, something like 0.5 times BM25 plus 0.5 times cosine. The trouble is that these numbers don't live on the same scale. BM25 scores are unbounded and shift with the query and the corpus. Cosine similarity sits in a narrow range. To add them you have to normalize them and then tune a weight, and that weight quietly goes stale as your documents change.
Reciprocal rank fusion ignores scores completely
Reciprocal rank fusion uses only each document's position. A document earns 1 divided by (k + rank) from every list it appears in, and you add those up. With the usual k of 60, this is the core of the fusion step in agentic-rag-evals:
pythonfused: dict[int, float] = {} for ranking in (np.argsort(-bm25), np.argsort(-dense)): for rank, idx in enumerate(ranking[:max(k * 3, 10)]): if bm25[idx] > 0 or dense[idx] > 0.15: fused[int(idx)] = ( fused.get(int(idx), 0.0) + 1.0 / (60 + rank + 1) ) order = sorted(fused, key=fused.get, reverse=True)[:k]
A worked example shows what this rewards. Say document A is first in BM25 and fifth in embeddings: 1/61 + 1/65 gives 0.0318. Document B is second in both: 1/62 + 1/62 gives 0.0323. B wins. Agreement between two different methods counts for more than one strong opinion, and that's usually the behaviour you want.
The constant keeps any single list from dominating. The gap between rank 1 and rank 2 is small, so one retriever being very sure can't drown out the other.
Fuse by rank, not by score, and BM25 and cosine never need normalizing against each other.
Decide what "nothing found" means
Here's the detail that matters most in production. Embedding search always returns its nearest neighbours, however unrelated they are. Ask about something outside your documents and you still get results, the model sees context, and now it has material to build a confident wrong answer from.
My search handles this at the last step. A hit only survives if it has at least one lexical match:
python# Require at least one lexical match so unrelated # queries return nothing. return [ Hit(chunk=self.chunks[i], score=round(fused[i], 5)) for i in order if bm25[i] > 0 ]
When retrieval returns nothing, the agent abstains, and the unanswerable case in the golden set checks that it keeps doing so. This rule is a trade-off. It's a good fit here because the project's embeddings are hashed features, chosen so the project runs offline. With a real embedding model you may want a similarity threshold instead, so a pure paraphrase with no shared words can still get through.
Small choices that add up
Chunking affects retrieval as much as ranking does. Paragraphs are a natural boundary, long ones get windowed with overlap so a fact isn't cut in half, and I keep each heading as context for the paragraph after it. A passage that says "customers have 30 days" is far more findable when "Refund policy" travels with it.
Fusion also runs on more candidates than it returns, taking the top three times k, or at least 10, from each list. A document ranked twelfth in one list and third in the other still gets a fair chance to reach the final results.
When to reach for this
If your documents contain codes, names or jargon that users type exactly, hybrid search is worth adding early, and RRF is the cheapest way to do it: no tuning, no training, and about ten lines of code. A learned reranker can do better, but it adds a model and latency. I'd start with RRF, put a golden set behind it, and let the evals show whether anything more is needed.



