Module 5: Keyword vs Semantic Search
7. Capstone Exercise: Classifying 10 Queries
Exercise overview
This is the capstone exercise for Module 5. Here you're going to classify 10 queries as "keyword", "semantic" or "hybrid", justifying your decision. This consolidates your intuition about when to use each method.
The 10 queries
For each one, decide:
- Which method would you use? (keyword, semantic, hybrid)
- Why?
Query 1: "article 15 of the constitution"
See solution
Method: Keyword
Justification: You need an exact match on "article 15". Semantic could return articles 14 or 16 (similar numbers).
Query 2: "how to learn programming"
See solution
Method: Semantic
Justification: A conceptual query. Documents might use "coding", "development", "learning to code" → semantic finds all the variants.
Query 3: "error ABC-500 in production"
See solution
Method: Hybrid (keyword filter + semantic ranking)
Justification:
- "ABC-500" must appear exactly (keyword)
- "production" vs "development" is conceptual (semantic)
- Filter by the code, rank by the context
Query 4: "React best practices"
See solution
Method: Hybrid or pure Semantic
Justification:
- If you filter on "React" with keyword → you guarantee it's about React
- If you use pure semantic → it can find "ReactJS", "React.js", "Facebook's library"
Both are valid; it depends on whether you want to be strict about the word "React".
Query 5: "invoice #INV-2024-00123"
See solution
Method: Keyword
Justification: An exact invoice code. Semantic should NOT be used (it could return INV-2024-00122 or similar).
Query 6: "how OAuth authentication works"
See solution
Method: Semantic
Justification: A conceptual query. Documents might use "OAuth", "auth", "authentication", "third-party login" → semantic understands that these are related concepts.
Query 7: "documents about AI from the last 3 months"
See solution
Method: Hybrid (semantic + a time filter)
Justification:
- "AI" is conceptual (semantic can find "artificial intelligence", "machine learning")
- "the last 3 months" is an exact filter (metadata, not an embedding)
Run semantic + filter by date.
Query 8: "tutorial"
See solution
Method: Keyword or Semantic (it depends)
Justification:
- Keyword: It finds docs that contain exactly "tutorial"
- Semantic: It can find "guide", "how-to", "step by step"
If you want the variants → semantic. If you only want "tutorial" → keyword.
Query 9: "differences between SQL and NoSQL"
See solution
Method: Semantic
Justification: A conceptual query (a comparison). Documents might use "relational databases", "MongoDB", "PostgreSQL" without mentioning "SQL" verbatim → semantic understands the concept.
Query 10: "products with a code starting with XYZ"
See solution
Method: Keyword (with a regex or prefix match)
Justification: An exact structural search (a specific code). Semantic is NOT appropriate.
Exercise summary
What you did:
- ✅ You classified 10 queries by their optimal method
- ✅ You justified each decision
- ✅ You identified the edge cases (hybrid)
The intuition, consolidated:
"Keyword for exact and structural queries. Semantic for conceptual queries and intent. Hybrid when the queries are mixed or you want an automatic balance."
Module 5 conclusion
Congratulations on completing Module 5: Keyword vs Semantic Search. 🎉
What you achieved:
- ✅ You understand keyword search (TF-IDF, BM25)
- ✅ You understand semantic search (embeddings + cosine)
- ✅ You can compare the two (advantages, limitations)
- ✅ You can design hybrid search (fusion, filters)
- ✅ You can decide when to use each one (the decision matrix)
The module's key intuition:
Keyword and semantic aren't rivals; they're complementary. The best systems combine both: keyword for precision, semantic for coverage.
Next module: Module 6: Designing Search Systems — The complete architecture (indexing, query processing, ranking).