Module 5: Keyword vs Semantic Search
6. When to Use Each Search Method
Overview
This is the most practical capsule in the module: a clear decision guide for choosing between keyword, semantic, or hybrid based on your use case.
Decision matrix
| Use case | Recommended method | Justification |
|---|---|---|
| Searching for codes/IDs | Keyword | You need an exact match |
| Conceptual search | Semantic | Intent > exact words |
| Technical documentation | Hybrid | Exact technical terms + concepts |
| E-commerce | Hybrid | An exact product name + a description |
| Support/tickets | Hybrid | Exact IDs + similar descriptions |
| Academic research | Semantic | Concepts, not necessarily keywords |
| Legal/compliance | Keyword | Precision is critical |
| General chat/RAG | Semantic | The user's intent |
Decision flow
┌─ Do you need EXACT matches?
│ └─ YES → Keyword
│ └─ NO → Next question
│
├─ Is the query conceptual/a question?
│ └─ YES → Semantic
│ └─ NO → Next question
│
├─ Are the queries mixed (some exact, others conceptual)?
│ └─ YES → Hybrid
│ └─ NO → Semantic (more coverage)
│
└─ Is the budget very limited?
└─ YES → Keyword (cheaper)
└─ NO → Semantic or hybrid
Concrete examples
Case 1: A personal blog search engine
Context: 500 articles about technology
Typical queries:
- "React tutorial"
- "how to learn Python"
- "testing best practices"
Decision: Semantic search
Justification:
- Conceptual queries (intent)
- A small dataset (cheap embeddings)
- Users expect relevant results, not exact ones
Case 2: A technical support system
Context: 100K historical tickets
Typical queries:
- "Ticket #12345" (exact)
- "problem with login" (conceptual)
- "card payment error" (conceptual)
Decision: Hybrid (keyword filter + semantic ranking)
Justification:
- Mixed queries (exact IDs + descriptions)
- Keyword for the IDs → it guarantees exactness
- Semantic for the descriptions → it finds similar tickets
Case 3: An e-commerce site with 1M products
Context: A large catalog
Typical queries:
- "iPhone 15 Pro" (an exact name)
- "phone with a good camera" (descriptive)
- "gaming laptop" (a category)
Decision: Hybrid (rank fusion)
Justification:
- Mixed queries
- Exact names → keyword
- Descriptions → semantic
- Fusion → an automatic balance
Case 4: A legal knowledge base
Context: Legal documents
Typical queries:
- "article 42 of law X"
- "cases about medical negligence"
Decision: Keyword for the exact ones, semantic for the conceptual ones
Justification:
- Precision is critical for specific articles
- Semantic is useful for finding related cases
- Separate by query type
Signs that you need to change
Sign 1: Users reformulate their queries several times
Symptom: A user searches for "car", finds nothing, searches for "auto", finds nothing, searches for "automobile"
Solution: Migrate to semantic search (it understands synonyms)
Sign 2: Irrelevant results in semantic
Symptom: The query "Python 3.11" returns docs about "python snakes"
Solution: Add a keyword filter ("Python" must appear)
Sign 3: You can't find things by an exact word
Symptom: You search for "error E404" but semantic returns general errors
Solution: Use keyword for exact codes/IDs
Summary
Key points:
- Keyword: Precision for exact matches
- Semantic: Coverage for conceptual queries
- Hybrid: A balance for mixed queries
- The decision: Based on the query types and the requirements
Next capsule: 07-capstone-exercise-5.md — 10 queries → decide the method.