1:1 mentoring with Big Tech AI engineers
RAG & MCP

Retrieval & Reranking

Advanced retrieval and reranking for RAG: BM25, dense retrieval, cross-encoder reranking, and hybrid search strategies.

Last updated

4. Retrieval — Hybrid Search, Reranking & Query Understanding

4. Retrieval — Hybrid Search, Reranking & Query Understanding

Why Hybrid Search (Vector + Keyword)

Vector search captures semantic similarity ("car" matches "automobile"). Keyword search (BM25) captures exact terms ("error code E-4502" won't match semantically but BM25 finds it instantly). Production systems need both.

Search TypeWins WhenFails When
Dense (vector)Semantic queries, paraphrases, conceptual searchExact term matching (product codes, error codes, names)
Sparse (BM25)Exact keywords, rare terms, technical identifiersParaphrased queries, conceptual similarity
Hybrid (fusion)Most real-world queries (mix of concept + specific terms)Simple queries where one method suffices (adds latency)

BM25 in One Minute

BM25 (“Best Matching 25”) is the lexical scorer behind Lucene, Elasticsearch, and OpenSearch. No model, no training, no GPU — it scores a chunk by summing a weight for every query term it contains, using three ideas:

Related

More in RAG & MCP

Get full access to all 74+ sections with code examples, diagrams, and interactive animations.

Unlock Premium