Interview's MateAI Engineering
Interview's Mate

AI Engineering

LLMs, RAG, agents & evals

Visualizer

DSA Visualizer
All 32 lessons
Custom Playground
Try your own examples

Learning

System Design
31 architecture topics
SQL Learning
160 foundations → production topics
AI Engineering
160 LLM → backend topics
Data Science
160 Python → MLOps topics
Data Engineer
160 SQL → streaming topics
Docker
160 Docker learning topics
Kubernetes
160 K8s fundamentals → cloud
Java LearnSoon
Coming soon
Python Learn
Interview Q&A & internals
JavaScript Learn
Closures, async & DOM Q&A
Tech Learn
Search, practise & track Q&A
AI DSA Practice
Solve coding problems
Theme
Home
AI Engineering topics
Lesson 29/ 160
02. RAG

Hybrid Search

Combine dense and sparse retrieval with fusion so neither synonyms nor exact IDs are missed.

IntermediateDense+Sparse · RRF3 quiz questions
Practice Generative AI Q&A
In plain wordsDiagramTheoryStep by stepWhen to use itInterview cluesMistakes to avoidHands-onQuiz (3)Practice

In plain words

Search twice, once by exact words and once by meaning, then combine the two lists so the best of both appear at the top.

Think of it like…

Asking two different experts to shortlist candidates: one knows exactly what's written in the files (keyword), the other understands what you meant (semantic). Candidates both experts like go to the top; each expert also gets to nominate people the other missed.

Where you’ve seen it

A telecom support assistant evaluates 400 real questions: dense-only recall@10 is 81 percent, BM25-only 74 percent, and RRF over both reaches 92 percent. Failures that dense missed were plan names and error codes; failures BM25 missed were paraphrased questions ("phone keeps dropping calls"). They retrieve 50 from each, fuse with RRF, rerank the top 30 with a cross-encoder, and send 6 chunks to the LLM.

Words you’ll hear

Dense retrieval
Nearest-neighbour search over embedding vectors; captures meaning.
Sparse retrieval
Term-based search such as BM25 or SPLADE; captures exact tokens.
RRF (Reciprocal Rank Fusion)
score(d) = Σ 1/(k + rank_i(d)) across retrievers; k is usually 60.
Weighted score fusion
Combine normalised scores with weights, e.g. 0.6·dense + 0.4·BM25.

Visual diagram

Loading interactive diagram

Theory & deep dive

Fusion methods

Dense similarity scores (cosine 0.2 to 0.9) and BM25 scores (unbounded, query-dependent) live on different scales, so adding them directly is meaningless. RRF sidesteps this by using only ranks: a document ranked 1st in one list and 10th in another scores 1/61 + 1/70, and a document appearing in only one list still scores. It's robust, parameter-light (k = 60 is a sound default) and the default in Elasticsearch, OpenSearch, Weaviate, Qdrant and others.

Weighted score fusion normalises each retriever's scores (min-max or z-score per query) and combines them with weights, allowing you to favour one side (for example for code-heavy corpora), but it's sensitive to normalisation and score distribution shifts. Some engines offer native hybrid queries combining vector and BM25 clauses in one request, while others need you to run two queries and fuse in application code. A third family is learned sparse retrieval (SPLADE), which expands queries and documents with related terms inside an inverted index, narrowing the gap with dense models.

RRF by hand

Doc A: rank 1 dense, rank 4 BM25 → 1/61 + 1/64 ≈ 0.0320. Doc B: rank 2 dense only → 1/62 ≈ 0.0161. Doc C: rank 1 BM25 only → 1/61 ≈ 0.0164. Order: A, C, B.

Key takeaway: RRF fuses ranks without normalising scores; weighted fusion needs careful normalisation.

Making hybrid work in practice

Retrieve generously from each side (50 to 100), fuse, then rerank the top 20 to 50 with a cross-encoder to restore precision before sending 5 to 10 chunks to the LLM. Apply the same metadata and permission filters to both retrievers, and use the same chunks, since mixing different chunking between indexes complicates fusion. Query-time options include boosting BM25 weight when the query contains rare tokens (codes, quotes) and dense weight for natural-language questions, which a small query classifier can decide.

Evaluate on a labelled query set that includes both query styles, and measure each retriever alone, hybrid and hybrid plus reranking, on recall@k and nDCG, plus latency and cost: hybrid doubles retrieval calls but both are cheap relative to the LLM. Look at failures by type (identifier queries, paraphrases, multi-hop) to see which side is missing what. Keep both indexes updated together; stale sparse and dense indexes cause confusing mismatches.

An ablation table

Dense only 81% · BM25 only 74% · RRF hybrid 92% · hybrid + reranker 95% recall@10 (answer accuracy 78% → 87%). The table shows where each stage earns its latency.

Key takeaway: Fuse deep lists, rerank, filter both sides, and prove each stage with an ablation.

How it works, step by step

Step 1 of 4
Ingestion

1. Index for both retrievers

Create a vector index and a keyword (BM25) index over the same chunks with matching metadata.

same chunk ids in both indexes
Key numbers at this step
Keep in sync
always

When to use it & trade-offs

What it is

Hybrid search runs a dense retriever (embeddings, good at meaning and paraphrase) and a sparse retriever (BM25 or learned sparse vectors, good at exact terms and identifiers) in parallel, then fuses the two ranked lists into one. The most popular fusion method is Reciprocal Rank Fusion (RRF): each document scores the sum of 1 / (k + rank) over the lists it appears in, with k ≈ 60, which needs no score normalisation. The fused top candidates then usually go to a reranker.

Why it matters: Neither retriever wins everywhere. Dense search misses "ERR_4012", part numbers and rare names; BM25 misses "my laptop won't boot" when the page says "notebook fails to start". Production queries are a mix of both, and hybrid search is consistently one of the cheapest ways to raise recall in RAG without changing models.

When to reach for it

  • RAG over documentation with codes, names and prose
  • Enterprise search with mixed query styles
  • Any system where dense-only recall plateaus

When to avoid or be careful

  • Adding raw BM25 and cosine scores
  • Different filters on the two retrievers
  • Fusing only 5 results from each list

Fusion approaches

Reciprocal Rank Fusion
Best for: A robust default

Strengths: No normalisation; few parameters; stable.

Watch out: Ignores score magnitudes and confidence.

Weighted score fusion
Best for: Tuned domains where one retriever should dominate

Strengths: Adjustable emphasis.

Watch out: Requires normalisation; brittle to distribution shifts.

Single-model learned sparse + dense
Best for: Teams wanting one index with semantic expansion

Strengths: Fewer moving parts at serve time.

Watch out: Heavier indexing; less common tooling.

Interview signals & numbers to know

When this topic comes up

  • “Dense search misses exact product names”
  • “What is RRF?”
  • “Improve recall without changing the model”
  • Hybrid in Elasticsearch/Weaviate/Qdrant
  • Query-type analysis

Benchmarks & rules of thumb

k = 60 -
standard RRF constant
50 – 100 -
candidates per retriever before fusing
81% → 92% -
recall@10 gain from hybrid in the example

Common mistakes & follow-ups

Common interview mistakes

  • Summing cosine similarity and BM25 scores directly, letting BM25's larger scale dominate.
  • Applying the tenant filter to vectors but forgetting it on the keyword query.
  • Reporting hybrid gains without an ablation against each retriever alone.

Likely interviewer follow-ups

  • How does Reciprocal Rank Fusion work?
  • Why does hybrid search improve recall?
  • How would you decide the weights between dense and sparse?
Interview tip: Work an RRF example with two documents. It proves you understand rank-based fusion rather than just naming it.
Loading hands-on exercise

Knowledge check

Loading quiz

Put it into practice

Practice related interview Q&A

Apply Hybrid Search with generative AI interview Q&A and hands-on practice.

Open Generative AI Q&A →Tech Learn Q&A
Previous topic
BM25 Keyword Search
Next topic
Reranking