Dense retrieval misses error codes and SKUs; BM25 misses paraphrases. Here is how hybrid search fuses both with reciprocal rank fusion, worked through with real numbers, and where a cross-encoder reranker fits.
Most RAG systems that fail on exact identifiers, error codes, and product names are not failing because their embedding model is weak. They are failing because they only run one kind of search, and the fix is hybrid search: run a lexical BM25 query and a dense vector query in parallel, fuse the two ranked lists with reciprocal rank fusion, and then spend a reranker on the small set of survivors.
That sentence is the whole architecture. The rest of this post is about why each stage exists, what the fusion math actually does (with numbers), and where teams get it wrong.
Dense retrieval embeds the query and every chunk into the same vector space and returns the nearest neighbours. It is good at meaning: "how do I cancel my plan" finds a chunk titled "Ending your subscription" with zero words in common. It is bad at strings that carry meaning only as exact tokens. An embedding model has no reason to place ERR_TLS_CERT_ALTNAME_INVALID far from ERR_TLS_CERT_SIGNATURE_FAILURE; to the model they are near-identical error-shaped strings.
Lexical retrieval, almost always BM25, does the opposite. It scores chunks by how often query terms appear in them, weighted by how rare each term is across the corpus and normalised for chunk length. A rare token like an error code or a SKU gets a huge inverse document frequency weight, so the one chunk containing it rockets to the top. But BM25 has no idea that "cancel" and "end" are related.
The BEIR benchmark made this concrete years ago: across 18 heterogeneous retrieval datasets, plain BM25 remained a stubbornly strong zero-shot baseline, and many dense retrievers that beat it on their training domain lost to it elsewhere. Anthropic's contextual retrieval write-up shows the same pattern from the production side: adding a BM25 index alongside embeddings cut retrieval failures meaningfully, and adding a reranker on top cut them further (they report a 49% reduction in top-20 retrieval failures from contextual embeddings plus contextual BM25, and 67% once reranking was added).
| Query type | BM25 | Dense vectors | Why |
|---|---|---|---|
| Exact identifiers (error codes, SKUs, ticket IDs) | Strong | Weak | Rare tokens get high IDF weight; embeddings blur near-identical strings |
| Paraphrase ("cancel plan" vs "end subscription") | Weak | Strong | No shared terms for BM25 to match |
| Proper nouns, API and function names | Strong | Mixed | Depends on whether the name appeared in the embedding model's training data |
| Conceptual questions ("why is my p99 spiky") | Weak | Strong | The answer chunk may never use the user's words |
| Negation and constraints ("without Docker") | Weak | Weak | Neither retriever models logic; this is the reranker's job |
| Typos and inflections | Weak without stemming | Moderate | Subword tokenisation gives embeddings some tolerance |
The last two rows matter: hybrid search widens recall, but neither first-stage retriever understands the query in a strict sense. That is what the third stage is for.
The shape is a funnel. Each stage is more expensive per document and sees fewer documents than the one before it.
Both retrievers run at the same time against the same chunk set, each returning its own top-k (commonly 20 to 100). They do not need to agree on anything, and they should not share a scoring scale, which is the first trap.
How you chunk matters as much as how you search. Chunks that split a function signature from its docstring, or a table header from its rows, hurt both retrievers equally; the tradeoffs are covered in RAG chunking strategies, from fixed-size to late chunking.
The tempting way to merge two result lists is to normalise and add the scores. It does not work well. BM25 scores are unbounded and depend on corpus statistics: one query's top hit might score 14.2, another's 3.1. Cosine similarities from a modern embedding model tend to bunch in a narrow band, often something like 0.75 to 0.85 for everything vaguely relevant. Min-max normalising each list stretches whatever spread happens to exist, so a list of five mediocre hits gets the same 0 to 1 range as a list with one perfect hit and four bad ones.
Reciprocal rank fusion (Cormack, Clarke and Buettcher, SIGIR 2009) sidesteps the problem by throwing scores away entirely and using only rank positions:
from collections import defaultdict
def rrf(ranked_lists, k=60, weights=None):
"""Fuse several ranked lists of doc IDs. Rank 1 is the best hit."""
weights = weights or [1.0] * len(ranked_lists)
scores = defaultdict(float)
for w, ranking in zip(weights, ranked_lists):
for rank, doc_id in enumerate(ranking, start=1):
scores[doc_id] += w / (k + rank)
return sorted(scores, key=scores.get, reverse=True)
Each document earns 1 / (k + rank) from every list it appears in. The constant k (60 in the original paper, and the default rank_constant in Elasticsearch's RRF retriever) flattens the curve so that rank 1 is not worth wildly more than rank 5.
Take the query ERR_TLS_CERT_ALTNAME_INVALID after upgrading node. Suppose the two retrievers return:
With k = 60:
| Doc | BM25 rank | Vector rank | RRF score | Fused rank |
|---|---|---|---|---|
| D1 | 1 | 3 | 1/61 + 1/63 = 0.03227 | 1 |
| D2 | 4 | 1 | 1/64 + 1/61 = 0.03202 | 2 |
| D3 | 2 | 4 | 1/62 + 1/64 = 0.03175 | 3 |
| D4 | none | 2 | 1/62 = 0.01613 | 4 |
| D5 | 3 | none | 1/63 = 0.01587 | 5 |
Two properties fall out. First, any document found by both retrievers (D1, D2, D3) roughly doubles the score of any document found by only one, so agreement between two very different retrieval methods is treated as strong evidence. Second, the exact-match doc D1 wins even though the vector side only ranked it third, because BM25 put it first. Neither retriever alone produced this ordering.
The weaknesses are the mirror image. RRF cannot tell a confident rank 1 from a lucky one; a BM25 list where every hit is noise still contributes full rank credit. That is why most production systems add per-retriever weights (the weights argument above) tuned on real queries, or switch to score-based fusion when they have the evaluation data to calibrate it. Several vector databases now ship both: Qdrant's Query API offers RRF and a distribution-based score fusion, and Weaviate's hybrid search exposes an alpha weight with rank-based and relative-score fusion options.
The first two stages are bi-encoder or lexical: the query and each document are scored independently, which is why they scale to millions of chunks. A reranker is a cross-encoder: it reads the query and one candidate together in a single forward pass and outputs a relevance score. Because the model sees both texts at once, it can notice that the chunk says "this fix does not apply to Node 22" when the user asked about Node 22. Neither BM25 nor cosine similarity can do that.
The price is that cost scales linearly with candidates, and you cannot precompute anything. A typical budget is to rerank the top 30 to 100 fused results and keep 5 to 10. Common choices include hosted APIs (Cohere Rerank, Voyage, Jina) and open-weight cross-encoders such as the BGE reranker family that you can self-host on a modest GPU.
| Reranker style | How it scores | Relative cost | When it fits |
|---|---|---|---|
| Cross-encoder | Query and chunk in one forward pass, one score | Moderate, linear in candidates | The default for most RAG stacks |
| Late interaction (ColBERT) | Token-level vectors precomputed per chunk, max-sim at query time | Lower per query, much higher storage | Large corpora where cross-encoder latency is too high |
| LLM as reranker (pointwise or listwise) | Prompt a general model to grade or order candidates | Highest | Small candidate sets, complex relevance criteria, or no reranker in your stack |
A reranker also changes what you put in the model's context. Fewer, better chunks mean a smaller prompt, lower latency and less distraction, which is the core argument of context engineering over prompt engineering.
Covered above, but it is the single most common bug: 0.5 * bm25 + 0.5 * cosine silently lets BM25 dominate because its numbers are bigger. If you must fuse scores, normalise per query and validate against labelled queries.
BM25 is only as good as its analyser. A default English analyser may split ERR_TLS_CERT_ALTNAME_INVALID on underscores into common fragments like err, tls and cert, destroying the rare token that made lexical search valuable. Index identifier-heavy fields with a second analyser that keeps them whole, or add a keyword sub-field.
Postgres ts_rank is a term-frequency ranking without BM25's corpus-wide IDF and length saturation. It is fine for many workloads, and combining tsvector with pgvector in one query is a perfectly reasonable hybrid setup, but do not expect the same ranking behaviour as Elasticsearch or a dedicated BM25 extension.
Short queries starve BM25. Expanding a query with synonyms and inflections before the lexical leg helps recall; you can see what that does to a query with a query expansion tool. The dense-side equivalent is rewriting the query into a hypothetical answer before embedding it, the HyDE approach, which works best when user queries are much shorter than the documents they target.
The defaults (k = 60, top 50 per retriever, rerank to 8) are sensible starting points, not answers. Build 50 to 100 real queries with known good chunks, measure recall@k after fusion and after reranking separately, and change one knob at a time. If fused recall@50 is low, no reranker can fix it, because it can only reorder what it was given.
If your corpus is short conversational text with almost no identifiers (support chat transcripts, opinion pieces), the BM25 leg adds latency and little recall. If your queries are almost all exact lookups (ticket numbers, part numbers), a keyword index with a good analyser may beat everything else and an embedding model is the optional extra. And if the questions require connecting facts across documents, better retrieval of individual chunks will not get you there; that is where agentic and graph-based RAG earn their cost.
For everything in between, which is most documentation, codebases, knowledge bases and product catalogs, hybrid plus reranking is the strongest default available.
Run BM25 and vectors in parallel, fuse by rank with RRF rather than by score, and rerank the fused top 50 with a cross-encoder before anything reaches the model. Then measure recall at each stage separately, because the stage that is failing is rarely the one you would guess. If you want to see how far pure term overlap gets you before adding any of this, paste a query and a handful of chunks into a lexical chunk reranker and look at what it misses: those misses are exactly what the dense leg is for.
Free, in your browser, no sign-up.
One email when a new post goes up. No other mail; unsubscribe in one click.
We store your email only to send new posts. See the privacy policy.