+91 99301 12627
RAG & AI Applications

Hybrid Search for RAG: Combining Keyword and Vector Search

By Mehul Prajapati

Magnifying glass representing hybrid keyword and vector search in RAG
On this page

Short answer: Hybrid search combines keyword search (such as BM25), which is great at exact terms like product codes, names and acronyms, with vector (semantic) search, which understands meaning and paraphrases. In a RAG system, you run both searches, merge the results (commonly with reciprocal rank fusion), optionally re-rank the top candidates, and pass the best chunks to the LLM. Hybrid search usually retrieves more relevant context than either method alone.

Key takeaways

  • Vector search finds meaning; keyword search finds exact matches.
  • Hybrid search covers the weaknesses of each.
  • Reciprocal rank fusion (RRF) is a simple, robust way to merge results.
  • Always measure retrieval on your own questions.

Why vector search alone isn’t enough

Query Vector search Keyword search
“How do I change my login details?” Finds “reset password” content May miss it (different words)
“Error code E-4021” May return similar-looking errors Finds the exact code
“Policy HR-17 leave rules” Finds general leave policies Finds document HR-17

Background: What are embeddings?

How hybrid search works

  1. Keyword retrieval: BM25 ranks chunks by term frequency and rarity
  2. Vector retrieval: embed the query and find the nearest chunk embeddings
  3. Fusion: merge the two ranked lists
  4. Re-ranking (optional): a cross-encoder scores query–chunk pairs for final ordering
  5. Generation: pass the top chunks to the LLM with instructions to cite them

Reciprocal rank fusion (RRF)

RRF scores each document by its rank in each list: score = Σ 1 / (k + rank), where k is a constant (60 is a common default). Documents ranked highly by either method rise to the top, and you don’t need to normalise different score scales.

def rrf(result_lists, k=60):
    scores = {}
    for results in result_lists:
        for rank, doc_id in enumerate(results, start=1):
            scores[doc_id] = scores.get(doc_id, 0) + 1 / (k + rank)
    return sorted(scores, key=scores.get, reverse=True)

keyword_hits = ['d3', 'd1', 'd7']
vector_hits  = ['d1', 'd5', 'd3']
print(rrf([keyword_hits, vector_hits]))   # d1 and d3 rise to the top

Weighted score fusion (alternative)

Some systems normalise both scores and combine them with a weight, e.g. 0.5 × keyword + 0.5 × vector. Tune the weight on a test set: more keyword weight for technical IDs, more vector weight for natural-language questions.

Where hybrid search is available

Many vector databases and search engines offer built-in hybrid search (combining sparse keyword and dense vector retrieval), and frameworks such as LangChain provide ensemble retrievers. See vector databases for RAG.

Add re-ranking for precision

Retrieve a wider candidate set (say top 20–50 from hybrid search), then use a re-ranker model to choose the best 3–8 chunks for the LLM. This often improves answer quality noticeably, at some extra latency.

How to evaluate

  • Create 30–50 real questions with known correct source chunks
  • Compare keyword-only, vector-only and hybrid using hit rate and recall@k
  • Check answer faithfulness, not just retrieval
  • Re-test whenever you change chunking or embedding models

Frequently asked questions

Is hybrid search always better than vector search?

Often, especially with codes, names and jargon, but not guaranteed. Measure on your data.

What is BM25?

A classic keyword ranking algorithm that scores documents by how often query terms appear, adjusted for term rarity and document length.

Does hybrid search slow down RAG?

It adds a second retrieval step, but keyword search is fast; re-ranking adds more latency than fusion.

Is this asked in GenAI interviews?

Yes. See RAG interview questions.

Conclusion

Hybrid search for RAG gives you the best of both worlds: exact keyword matching and semantic understanding. Combine BM25 and vector results with RRF, add re-ranking where precision matters, and evaluate on real questions to build a retrieval layer you can trust.

Build production RAG systems in our Generative AI App Developer course.

Learn with Mehul Prajapati in Borivali West

At Mehul Prajapati’s institute, you get 100% practical, hands-on training by industry experts with a minimum of 5+ years of experience, plus job-oriented programmes with placement support. Weekday and weekend batches are available, with multiple 2-hour slots between 8 am and 6 pm.

Address: 12th Floor, 1214, Gold Crest Business Centre, LT Rd, Above Westside Showroom, Borivali West, Mumbai, Maharashtra 400092
Call: +91 99301 12627 / +91 96645 45072

Visit the centre or call us to choose the right course and batch and to know the current fee structure.