A team moves its docs assistant from keyword search to a vector database, expecting a pure upgrade. Questions like "how do I stop being billed?" improve right away. Then the tickets change: customers paste error codes, config keys and version numbers, and the assistant answers with general advice about errors. A query for "Error E1047 after upgrading to 4.2" returns the troubleshooting overview and the upgrade guide, but not the one page that explains E1047. The team starts arguing about rolling back. Both camps are half right.
The common misconception
"Embedding search always beats keyword search, so a vector database is all retrieval needs." There's real evidence behind it:
Embeddings match meaning across different words: "cancel my plan" finds "end your subscription", which keyword search can't.
On the benchmarks models are trained for, neural retrievers win clearly. On MS MARCO, BM25 trailed neural approaches by 7 to 18 points in the BEIR study.
BM25, the standard keyword ranking function, is a hand-designed formula, which looks obsolete next to a neural network.
Demos use natural-language questions, exactly where vectors shine.
The half-truth: embeddings are better at paraphrase. But "better on average, on familiar data" isn't "better on every query in your corpus", and the queries where they lose are often the ones users care most about.
What actually happens
Two retrievers, two kinds of evidence
scores a passage by the query words it contains, weighting rare words more. Anthropic's Contextual Retrieval post describes it as building on TF-IDF, with adjustments for document length and a saturation function so repeated common words don't dominate. A rare token like E1047 is the strongest signal BM25 has.
An embedding model compresses the whole passage into one vector, and search returns the nearest vectors. That vector captures what a passage is about; as the Understanding LLMs path showed, it can blur a single exact token that decides relevance. So the two fail on different queries. Paraphrases favor vectors; identifiers, product names and rare jargon favor keywords.
Benchmark wins don't transfer to your corpus
BEIR, from Thakur and colleagues in 2021, tested ten retrieval systems on 18 datasets they weren't trained on. BM25, far behind in-domain, turned out to be a robust baseline. Dense retrievers did well on some datasets but significantly worse than BM25 on many others, especially with a domain shift such as biomedical questions or a task shift such as argument retrieval. The authors' first lesson: in-domain performance is not a good indicator of how a model generalizes.
Even the original RAG paper saw this. On FEVER, a fact-checking dataset, plain BM25 beat its learned dense retriever; the authors suggest it's because the claims are heavily entity-centric.
Embedding models have improved a lot since 2021, and BEIR's authors flag a lexical bias: many datasets were labeled from candidates that keyword systems found, which disfavors dense methods. The durable lesson remains: your corpus is out of domain for every off-the-shelf model, so neither method is safe to assume.
Fuse ranks, not scores
Running both retrievers gives you two lists with incompatible scores: BM25 has no upper limit, while cosine similarity sits in a fixed range. Adding them lets one method drown out the other. (RRF) ignores the scores and uses positions: each list adds 1 / (k + rank) to a document, and documents are sorted by the sum. Cormack, Clarke and Büttcher fixed k = 60 in a pilot study in 2009 and found that RRF consistently beat every individual system it combined, and the standard Condorcet fusion method. A page ranked high by both lists rises to the top; a page that only one method finds still makes the pool.
Rerank the short list with a model that reads both
Both retrievers judge the query and the passage separately. A , usually a cross-encoder, reads them together, so it can tell whether the passage actually answers the question. Nogueira and Cho showed the size of the effect in 2019: a BERT model reranking BM25's top 1,000 passages on MS MARCO raised MRR@10, a measure of how high the first relevant passage ranks, from 16.7 to 36.5 on the development set. In BEIR, BM25 followed by a cross-encoder over its top 100 hits was the best system overall and beat BM25 alone on 16 of the 18 datasets, at a high computational cost.
That cost shapes the design: a reranker runs once per candidate, so you rerank a pool, not the corpus. Anthropic's setup retrieved the top 150 chunks, reranked them and kept 20. Its summary of many test combinations: embeddings plus BM25 beat embeddings alone, and reranking improved retrieval further, with some added latency.
The same query, two pipelines
The first version returns nearest neighbors. The second fuses vector and keyword rankings with RRF and reranks a wide pool.
Python · retrieval.py
def retrieve(query, k=20): # Nearest neighbors only: generic pages about errors and upgrades # outrank the one page that mentions E1047. return vector_search(query, k=k)print(retrieve("Error E1047 after upgrading to 4.2")[:3])
Python · retrieval.py
from collections import defaultdictdef rrf(*rankings, k=60): """Reciprocal Rank Fusion: each list adds 1 / (k + rank).""" scores = defaultdict(float) for ranking in rankings: for rank, doc_id in enumerate(ranking, start=1): scores[doc_id] += 1 / (k + rank) return sorted(scores, key=scores.get, reverse=True)def retrieve(query, k=20, pool=150): fused = rrf(vector_search(query, k=pool), keyword_search(query, k=pool)) # A cross-encoder reads the query and each candidate together return rerank(query, fused[:pool])[:k]print(retrieve("Error E1047 after upgrading to 4.2")[:3])
In the first version, the E1047 page exists in the index but never reaches the prompt. In the second, keyword search puts it at the top of its list, fusion keeps it in the pool, and the reranker confirms it answers the question. Many search engines and vector databases offer hybrid queries with built-in rank fusion; the logic is the same.
Vector search
Keyword search (BM25)
Hybrid + rerank
Paraphrases and synonyms
Strong
Weak
Strong
Exact codes, names, versions
Often weak
Strong
Strong
Unfamiliar domain
Varies by dataset
Robust baseline in BEIR
Reranked BM25 was best in BEIR
Cost per query
One nearest-neighbor lookup
One index lookup
Both, plus a reranker pass per candidate
How to apply it in your project
Keep a keyword index next to the vector indexIndex the same chunks for BM25, either in your search engine or through your vector database's hybrid support.
Fuse with RRF before tuning weightsStart with plain RRF and k = 60. Add per-method weights only if your evaluation shows one side consistently helps more.
Rerank a wide pool, pass a short listRetrieve on the order of 100 to 150 candidates, rerank them, and send the best 10 to 20 to the model. Then trade pool size against latency.
Filter with metadata firstApply product version, language and permission filters inside both searches, so fusion and reranking only see eligible passages.
Test by query typeLabel real queries as identifiers, paraphrases and long questions, and measure each retriever on each group before deciding what to keep.
Key takeaways
Embeddings win on paraphrase; keyword search wins on exact identifiers and is a robust baseline on unfamiliar data.
In BEIR, dense retrievers that led in-domain often fell behind BM25 on new domains.
Fuse rankings with RRF instead of adding scores that live on different scales.
A cross-encoder reranker reading query and passage together gave the largest gains, so apply it to a short list.
Retrieval quality is capped by the candidate pool: no later stage recovers a passage both searches missed.
التعليقات (0)