Semantic vs Keyword Search: When to Use Each and Hybrid Approaches
Semantic vs Keyword Search
Semantic search excels at understanding intent but struggles with exact matches. A search for "error code 404" might return general articles about web errors because the embedding captures "error concepts" rather than the specific code. Keyword search finds that exact string immediately. The reverse happens with conceptual queries: "why is my website broken" finds nothing with keywords but works perfectly with semantic search.
Most production systems use hybrid search: semantic results merged with keyword results via reciprocal rank fusion or re-ranking. The hybrid approach captures both exact matches and conceptual relevance.
Cost vs Quality
Better embedding models cost more. At scale, embedding costs can exceed storage and compute costs. Start with the best model, measure quality on your data, then test cheaper alternatives. If quality drops less than 10% while cost drops 80%, the cheaper model wins.
Latency vs Recall
ANN parameter tuning controls latency-recall. HNSW's ef_search determines candidates to explore: higher values find more neighbors but take longer. A system at 10ms might achieve 90% recall; 50ms might push to 98%. Decide based on result criticality - 90% recall means 1 in 10 relevant articles is missed.
When NOT to Use
Semantic search adds complexity. For structured queries (filter by date, category), traditional indices are faster. For exact lookups (SKU, order ID), keyword search is superior. Use semantic when users express intent in natural language.