Hybrid Search
Learn how hybrid search combines keyword-based retrieval with semantic vector search to find both exact matches and meaning-based matches.
By the end of this lesson, you will be able to:
- Explain hybrid search.
- Understand why keyword and semantic search complement each other.
- Compare lexical, vector, and hybrid retrieval.
- Understand score combination and result fusion.
- Build a simple Python hybrid-ranking example.
- Use metadata filtering with hybrid retrieval.
- Evaluate hybrid search for RAG.
What Is Hybrid Search?
Hybrid search combines lexical search, which looks for matching words or terms, with semantic search, which uses embeddings to find related meaning.
A search for SKU-XJ42 should strongly favor a document containing that exact product code.
“How can I get my money back?” can retrieve a document about the “refund process” even when the words differ.
Why Combine Two Search Methods?
- Strong for exact words
- Good for IDs and names
- Can miss related wording
- Strong for meaning
- Handles paraphrases
- Can be weaker on exact identifiers
Hybrid search keeps useful signals from both retrieval approaches.
How Hybrid Search Works
The final results can then be filtered, reranked, or limited with Top-K.
Lexical Search
Exact terms
Excellent for product codes, names, error messages, and distinctive phrases.
Rare terms
Unusual words can strongly identify a document.
Paraphrases
Different wording may fail to produce a strong lexical match.
Meaning
Word matching alone does not fully capture semantic relationships.
Common lexical approaches include inverted indexes and relevance algorithms such as BM25.
Semantic Vector Search
Semantic retrieval converts queries and chunks into embeddings and searches for vectors that are close under a selected metric.
Words
“cancel subscription” favors matching terms.
Meaning
“stop my membership” can retrieve the same concept.
Combining Search Scores
One simple approach is to normalize comparable signals and combine them with weights.
keyword_score = 0.80
semantic_score = 0.70
keyword_weight = 0.45
semantic_weight = 0.55
hybrid_score = (
keyword_weight * keyword_score
+ semantic_weight * semantic_score
)
print(round(hybrid_score, 3))This is a teaching example. Production systems must account for the different score scales and meanings of their retrievers.
Why Score Normalization Matters
Lexical and vector systems may produce scores with different ranges. Adding raw scores directly can make one signal dominate.
Add unrelated score scales without checking their distributions.
Use normalization or a ranking-fusion method and validate it on real queries.
Rank Fusion with RRF
Reciprocal Rank Fusion (RRF) combines ranked lists without requiring raw scores to use the same scale.
def rrf_score(rank, k=60):
return 1 / (k + rank)
keyword_rank = 2
semantic_rank = 4
score = rrf_score(keyword_rank) + rrf_score(semantic_rank)
print(round(score, 5))A document appearing high in both lists receives contributions from both rankings.
Hybrid Search + Top-K
Hybrid retrieval can merge candidates, rank them, and keep the final Top-K results.
Hybrid Search + Metadata Filtering
region = USA support system can restrict results to the correct product and region while using both retrieval signals.
Simple Python Candidate Fusion
keyword_results = ["A", "B", "C"]
semantic_results = ["C", "A", "D"]
combined = []
for item in keyword_results + semantic_results:
if item not in combined:
combined.append(item)
print(combined)A production implementation should use a formal fusion method and preserve ranks or scores for evaluation.
Hybrid Search in RAG
Hybrid retrieval is useful for enterprise content where questions mix natural language with exact terms, codes, names, or identifiers.
When Hybrid Search Works Well
Users may search with SKUs and descriptions.
Error codes and API names benefit from lexical matching.
Employees mix exact internal terms with natural-language questions.
Exact clause terms and broader meaning can both matter.
Ticket IDs and product names coexist with conversational questions.
Combining signals can improve coverage for mixed query types.
When Hybrid Search May Not Be Necessary
- Queries are mostly natural language
- Exact identifiers are uncommon
- Evaluation shows strong retrieval
- Exact terms matter
- Paraphrases are common
- One retriever misses useful evidence
Hybrid retrieval adds complexity, so justify it with measured improvement.
Common Hybrid Search Mistakes
Different scales can make one retriever dominate.
Evaluate before adding complexity.
The same chunk can appear in both lists.
Analyzers and field choices affect lexical quality.
Hybrid retrieval still needs correct constraints.
Measure whether combined retrieval improves useful evidence.
Evaluate Hybrid Search
Practice: Build a Hybrid Ranking
Create two ranked lists of document IDs. Give each document a lexical rank and a semantic rank, then use RRF to produce a combined ranking.
Compare the two retrievers
Find documents appearing in both lists and see how their combined rank changes.
Quick Quiz
1. What is hybrid search?
It combines lexical retrieval and semantic vector retrieval.
2. Why is keyword search useful?
It is strong for exact terms such as product codes, names, and identifiers.
3. Why should raw scores be handled carefully?
The two retrievers may use different score scales and meanings.
4. What is RRF?
Reciprocal Rank Fusion combines ranked lists without requiring their raw scores to share a scale.
30-Second Recap
Find exact words and identifiers.
Find related meaning using vectors.
Combine retrieval signals or ranked lists.
Measure quality, latency, and cost.
Key Takeaways
- Hybrid search combines lexical and semantic retrieval.
- Lexical search is strong for exact terms; semantic search is strong for meaning and paraphrases.
- Score fusion requires compatible signals, normalization, or rank fusion.
- RRF is one practical ranking-fusion method.
- Metadata filtering can work alongside hybrid retrieval.
- Hybrid search adds complexity, so evaluate it against simpler baselines.
- Compare lexical-only, semantic-only, and hybrid retrieval on the same test set.