ADVANCED RAG · LESSON 150 OF 278

BM25, Sparse Search, and Hybrid Retrieval

Combine lexical matching with dense embeddings when exact terms and semantic meaning both matter.

What you will learn

Combine lexical matching with dense embeddings when exact terms and semantic meaning both matter.

In simple words

Dense retrieval is good at paraphrases and meaning; sparse methods such as BM25 are strong for exact terms, identifiers, and rare keywords. Hybrid search combines both signals before reranking.

Visual explanation: BM25, Sparse Search, and Hybrid Retrieval

Trace how Query becomes Better candidates through sparse + dense.

WATCH THE IDEA

BM25, Sparse Search, and Hybrid Retrieval

Playing
QuerySparse + denseBetter candidates
  1. 1Observe: Query
  2. 2Transformation: Sparse + dense
  3. 3Outcome: Better candidates

Observe: Query. Trace how Query becomes Better candidates through sparse + dense.

The diagram highlights Query, Sparse + dense, Better candidates. Use the labels to trace the main relationship from left to right.

Real-world example: Operational AI decision

A team applies bm25, sparse search, and hybrid retrieval to a real business workflow.

What the team decides: Good retrieval uses the signals that match the task rather than assuming one method wins everywhere.

Risk to avoid: A strong technical concept still needs measurement, safeguards, and ownership in production.

Technical explanation

Dense retrieval is good at paraphrases and meaning; sparse methods such as BM25 are strong for exact terms, identifiers, and rare keywords. Hybrid search combines both signals before reranking.

Python and implementation examples

Use these examples to connect the concept to working code. Package-based examples assume the named library is installed in your own environment.

Combine normalized dense and sparse scores

python
def hybrid_score(
    dense_score: float,
    sparse_score: float,
    dense_weight: float = 0.6,
) -> float:
    sparse_weight = 1.0 - dense_weight
    return dense_weight * dense_score + sparse_weight * sparse_score

candidates = [
    {"id": "A", "dense": 0.91, "sparse": 0.40},
    {"id": "B", "dense": 0.72, "sparse": 0.95},
]

ranked = sorted(
    candidates,
    key=lambda item: hybrid_score(item["dense"], item["sparse"]),
    reverse=True,
)
print(ranked)

Real hybrid search needs calibrated scores or rank-fusion methods, but the example shows why two retrieval signals can be combined.

Common misconception

This concept is not a guarantee of a correct outcome by itself. Its value depends on suitable evidence, careful implementation, and evaluation against the real task.

QUICK QUIZ

Why can hybrid retrieval outperform dense-only search?

Practical application

Good retrieval uses the signals that match the task rather than assuming one method wins everywhere.

Key takeaway

Good retrieval uses the signals that match the task rather than assuming one method wins everywhere.

Next concept

Continue with Query Rewriting and Multi-Query Retrieval.

Engineering view

Good retrieval uses the signals that match the task rather than assuming one method wins everywhere.

Internals view

Combine lexical matching with dense embeddings when exact terms and semantic meaning both matter. Dense retrieval is good at paraphrases and meaning; sparse methods such as BM25 are strong for exact terms, identifiers, and rare keywords. Hybrid search combines both signals before reranking.

Architecture view

Consider the Query → Sparse + dense → Better candidates flow, and make the system's inputs, checks, and outcomes explicit.

Was this lesson helpful?

Lesson discussion

Comments are reviewed before publication. Keep discussion focused on learning and do not post private information.

Loading discussion…

Your quiz answer and current lesson are saved on this device. Sign in to explore account-backed learning features.

Content version 1 · Last reviewed 2026-10-16