RAGAI Systems10 min readUpdated

Hybrid Search for RAG: Combining Keyword and Vector Retrieval

By Mudassir Khan — Agentic AI Consultant & AI Systems Architect, Islamabad, Pakistan

Cover illustration for: Hybrid Search for RAG: Combining Keyword and Vector Retrieval

Section 01 · Definition

What is hybrid search in RAG?

Most RAG systems start with vector only retrieval. That works well until users search for something specific — and then exact term lookups start failing in ways that are hard to debug.

Quick answer

What is hybrid search in RAG? Hybrid search in RAG combines BM25 keyword retrieval with dense vector search. BM25 excels at exact term matching — model names, error codes, abbreviations. Vector search excels at semantic similarity. Reciprocal Rank Fusion merges their ranked lists to give better retrieval than either method alone.

Hybrid search combines BM25 keyword retrieval with dense vector search to increase the share of relevant chunks your pipeline surfaces before generation. BM25 excels at exact term matching — model names, error codes, abbreviations, proper nouns. Dense vector search excels at semantic similarity, capturing meaning even when the user's phrasing differs from the document's. Reciprocal Rank Fusion (RRF) merges their ranked lists into a single ordering that outperforms either method alone without the need to retrain your embeddings.

Most RAG systems start with vector only retrieval. That works well until users search for something specific. An engineer who types “CUDA_ERROR_OUT_OF_MEMORY” needs the chunk that contains that exact string. A vector model trained on general text will spread its attention across semantically adjacent chunks that never mention the error code at all. Hybrid search closes that gap.

Section 02 · The problem

The two failure modes hybrid search solves

Every RAG retrieval system makes a trade-off when it chooses a single retrieval method. Understanding which mode your pipeline fails in tells you exactly how much hybrid search will help.

Failure mode 1: vector only misses exact tokens. Dense embeddings represent meaning statistically. When two model names share most of their training context — say, two versions of the same base model — their embeddings land close in the vector space. A query for the specific version may surface the wrong document. The same applies to numeric identifiers, error codes, product SKUs, and rare acronyms that the embedding model saw infrequently during pretraining.

Failure mode 2: keyword only misses conceptual queries. BM25 requires token overlap. A user who asks “how do I prevent my agent from repeating tool calls” will not match a chunk that discusses “idempotency in agentic workflows” if they share no words. Pure keyword systems penalise paraphrase, synonyms, and the natural variation in how different writers describe the same concept.

How to know which failure mode you have

Run a retrieval evaluation on 50 representative queries. Tag each query as 'exact lookup' (searches for a specific entity name, code, or identifier) versus 'conceptual' (searches for a technique, pattern, or concept). If more than 20% are exact lookups and your precision at top 5 is below 0.6 on those queries, hybrid search will produce a measurable lift.

Section 03 · Keyword retrieval

How BM25 keyword retrieval works

BM25 stands for Best Match 25. It is a ranking function that scores each document against a query based on term frequency and rarity across the corpus, with a saturation adjustment so repetition stops helping.

The core intuition: a term is valuable when it appears in this chunk (term frequency) and appears rarely across the whole corpus (inverse document frequency). A chunk that contains the query term “CUDA_ERROR_OUT_OF_MEMORY” and is one of only three chunks in your corpus that ever mention it scores very high. A chunk that contains “the” is not rewarded at all because “the” is in every document.

For RAG purposes, you build a BM25 index over your chunks at ingest time. At query time you run the same query string against that index and receive a list of (chunk, score) pairs ranked by relevance. This is what Elasticsearch, OpenSearch, and lightweight libraries like BM25S and Tantivy do behind the scenes.

BM25 is not a neural model. It has no understanding of synonyms or paraphrase. But that is also why it is so reliable for exact lookups: there is no ambiguity in how it scores a match. Either the token is there or it is not.

Section 04 · The fusion step

Reciprocal Rank Fusion: combining the two lists

RRF fuses two ranked lists into one by assigning each document a score based on its position in each list, then summing the scores. The result rewards documents that rank well in both retrievers.

The formula for each document:

RRF(d) = ∑ ( 1 / (k + rank_i(d)) )

Where k is a constant (typically 60) and rank_i(d) is the position of document d in retriever i, counting from 1. If a document does not appear in a retriever's results, its contribution for that retriever is zero.

Reciprocal Rank Fusion worked example: vector search ranks A, B, C while BM25 ranks C, F, A. RRF merges them so A and C tie at the top of the fused list.
RRF worked example. Chunk A appears in both lists (vector rank 1, BM25 rank 3) and floats to the top. Chunk F, which only BM25 found, outranks Chunk D, which only vector search found.

The k=60 constant matters. It dampens the impact of extreme rank differences. A document ranked 1st by one retriever and 60th by the other scores similarly to a document ranked 5th by both. This makes the fusion robust to a single retriever being very confident and the other being uncertain.

The key property is that documents appearing in both lists get a score from both terms in the sum. Documents appearing in only one list get a score from a single term. This naturally surfaces chunks that both retrievers agree on, which tends to mean they are genuinely relevant.

Section 05 · Building it

Implementing the two-index pattern

The canonical hybrid search implementation requires two parallel indexes and a fusion step. The wall clock cost is dominated by your embedding call, not the retrieval phase.

At ingest time: chunk your documents as you normally would, embed each chunk and upsert into your vector store, then index the same chunks as text documents in a BM25 capable store. Both indexes receive the same chunks — the content is identical, only the index structure differs.

At query time: run the user query through your embedding model, then issue the vector search and keyword search in parallel. Collect the top k results from each (20 to 50 per retriever is typical before fusion), apply RRF across both result lists, then take your final top k from the fused list and pass to the LLM.

Many vector databases now include native hybrid search so you do not need a separate keyword index. Weaviate, Qdrant, Meilisearch, and MongoDB Atlas all support BM25 plus vector search in a single query. If you are already on one of those stacks, enabling hybrid mode is a configuration change rather than an infrastructure addition.

For teams on pure vector stores like Pinecone or FAISS, adding Elasticsearch as the keyword index is the common path. The extra operational cost is real — you now maintain two indexes and a fusion layer — but for corpora with heterogeneous content the retrieval quality gain is substantial enough to justify it. The vector database comparison guide covers which stores have native hybrid support and which require a separate keyword index.

Section 06 · Decision guide

When hybrid search is worth the complexity

Hybrid search is not universally better. The decision depends on your query distribution and corpus characteristics.

Use hybrid search when

Your corpus contains proper nouns, version numbers, error codes, product names, or domain-specific abbreviations. Your users search with specific terminology rather than natural language. You are seeing consistent retrieval failures on exact-match queries in production. Your content spans multiple domains with different vocabulary ranges.

Stick with vector only when

Your corpus is homogeneous and users query in natural language that closely mirrors document phrasing. Latency budgets are tight and you cannot afford the second index. Your corpus is small enough that even imperfect retrieval produces acceptable results. You have already added a reranker and are seeing good results — the reranker may compensate for some of what hybrid would add.

For teams that are unsure, the retrieval evaluation test described earlier (50 representative queries, tag each as exact lookup vs conceptual, measure precision at top 5) will give you a data-driven answer within an afternoon. The full retrieval stack design — including how hybrid search fits with chunking and reranking strategies — is covered in the production RAG guide.

Section 07 · Cost and complexity

Cost and complexity tradeoffs

The main costs of hybrid search are operational rather than computational. Understanding them up front prevents the most common deployment mistakes.

Two indexes to maintain. Every ingest pipeline must write to two systems. Deletes and updates must propagate to both. Schema changes in one index may not automatically apply to the other. You need monitoring on both paths.

Tuning the k constant. k=60 works well as a default but some domains benefit from different values. Teams with very large corpora sometimes lower k to 20 to surface niche results more aggressively. Track the effect empirically before deploying a non-default value.

Fusion is not reranking. RRF combines positional signals. It does not understand whether a chunk is actually relevant to the query — it only knows that both retrievers ranked it highly. If you want deeper relevance scoring, add a cross encoder reranker after the fusion step.

RRF vs alpha weighting

Some implementations use a weighted combination of scores (alpha times vector score plus (1 minus alpha) times BM25 score) instead of RRF. This requires normalising the two score distributions, which can be unstable across queries, and tuning alpha on your specific corpus. RRF avoids both problems by using rank positions rather than raw scores, which is why it has become the default approach in production systems.

Ready to audit your RAG retrieval stack?

If your pipeline is falling short on specific term lookups, hybrid search is the highest leverage change you can make without retraining your embeddings. For full retrieval stack design — including hybrid search, reranking, and evaluation rig setup — the AI Systems Architecture service covers end to end production RAG architecture.

FAQ

Frequently asked questions

Common questions about hybrid search and Reciprocal Rank Fusion in production RAG systems.

What is hybrid search in RAG?

Hybrid search in RAG combines BM25 keyword retrieval with dense vector search. BM25 finds exact term matches; vector search finds semantically similar content. Reciprocal Rank Fusion merges their ranked lists into a single ordering that retrieves more relevant chunks than either method can alone.

What is the difference between BM25 and vector search?

BM25 scores documents based on term frequency and how rare each term is across the corpus. Vector search embeds the query and documents as numeric vectors, then retrieves documents with the highest cosine similarity. BM25 wins on exact matches; vector search wins on paraphrased or conceptual queries.

What is Reciprocal Rank Fusion?

RRF is a rank aggregation method. It scores each document by summing 1 divided by (k plus rank) for each retriever that returned that document, where rank is the document's position in that retriever's result list and k is a damping constant (typically 60). Documents that rank well in multiple retrievers float to the top of the merged list.

When should I use hybrid search for RAG?

Add hybrid search when your RAG pipeline fails on exact-match queries — specific model names, error codes, product identifiers, or rare domain terms. If an evaluation of 50 representative queries shows more than 20% are exact lookups with precision at top 5 below 0.6, hybrid search will produce a clear retrieval lift.

Does hybrid search increase latency?

Minimally, when both indexes are queried in parallel. The vector search and BM25 search run concurrently, and the RRF fusion step is fast — linear in candidate count. Wall clock latency is dominated by your embedding call, not the retrieval phase. Teams running both indexes in parallel typically see under 30 ms of added latency versus vector only retrieval.

Written by Mudassir Khan

Agentic AI consultant and AI systems architect based in Islamabad, Pakistan. CEO of Cube A Cloud. 38+ agentic AI launches delivered for global founders and CTOs.

View AI Systems Architecture serviceSee NebulaDesk Agentic Workspace case study

Related service

AI Systems Architecture

See scope & pricing →

Related case study

NebulaDesk Agentic Workspace

Read case study →

More on this topic

Need an AI systems architect?

Book a 30-minute architecture call. I will sketch the high-level design for your use case and give you an honest view of the trade-offs.

Book a strategy call →