Hybrid Search
Keyword search is precise but misses synonyms. Vector search understands meaning but sometimes misses exact terms. Hybrid search combines both — and it is what production RAG systems actually use. This lesson teaches you when each approach wins, how to implement hybrid search, and how to tune the balance between them.
The Problem with Pure Approaches
Pure keyword search fails on synonyms. A user searches for "joyful" but the document says "happy." Zero results. The user searches for "fixing broken CI/CD" but the document says "troubleshooting deployment failures." Zero results. Keywords match characters, not meaning.
Pure vector search fails on exact terms. A user searches for "error code 404" and vector search returns generic pages about web errors — because semantically, all error pages are similar. But the user wanted the specific page about 404 errors. Vector search also struggles with proper nouns, product IDs, and technical identifiers that have no semantic content.
Hybrid search combines both: keyword matching for precision when exact terms matter, vector similarity for understanding when meaning matters. Real user queries are a mix of both — "how to fix error 404 in React" needs keyword matching for "404" and "React" plus semantic understanding of "how to fix." Hybrid search handles this naturally.
When Each Approach Wins
Error codes, product IDs, exact names, legal statute numbers, API endpoints, version numbers. When the exact string IS the meaning.
Conceptual questions, synonym-heavy queries, "how to" questions, comparative queries, finding related content across different phrasings.
Real-world queries that mix specific terms with concepts: "how to fix error 404 in React." Most actual user queries fall into this category.
BM25 — The Keyword Side
BM25 (Best Match 25) is the standard keyword relevance algorithm. It scores documents based on two factors: how often the search terms appear in a document (term frequency) and how rare those terms are across all documents (inverse document frequency). A word that appears in every document (like "the") gets almost zero weight. A word that appears in only one document (like a specific product ID) gets high weight.
BM25 is what powers traditional search engines. It is fast, well-understood, and excellent at finding exact matches. Its weakness is that it cannot handle synonyms or conceptual similarity — it only matches strings.
The Alpha Parameter
Hybrid search combines keyword (BM25) and semantic (vector) scores using an alpha weight:
alpha = 0.0 → Pure keyword search (BM25 only)
alpha = 0.5 → Equal weighting (good starting point)
alpha = 1.0 → Pure vector search (embeddings only)
Most production systems use alpha = 0.4-0.7 (slightly favoring semantic). Tune based on your query patterns.
This lesson is for Pro members
Unlock all 520+ lessons across 52 courses with Academy Pro.
Already a member? Sign in to access your lessons.