Semantic Search vs Keyword Search
Dense vector similarity vs sparse term matching for retrieval
Use semantic search when users phrase things their own way; keep keyword search when exact terms like codes and IDs must match. Most production systems run both.
Semantic (Embedding) Search
Glossary →Semantic search encodes queries and documents into dense embedding vectors, then finds matches via cosine similarity or dot product. Captures meaning beyond exact words, 'car' matches 'automobile'.
Best for: Natural-language queries and synonyms.
Keyword (BM25) Search
Glossary →Keyword search (BM25, TF-IDF) matches documents by exact or stemmed term overlap. Fast, interpretable, and requires no ML infrastructure. Still the backbone of most search engines.
Best for: Exact term and identifier matching.
At a glance
| Dimension | Semantic (Embedding) Search | Keyword (BM25) Search |
|---|---|---|
| Query understanding | Semantic (meaning-based) | Lexical (token-based) |
| Synonym handling | Automatic | Requires manual expansion |
| Infrastructure | Vector DB + embedding model | Inverted index (Lucene, Postgres FTS) |
| Latency | Higher (ANN search + embedding) | Lower (inverted index lookup) |
| Explainability | Low (black-box similarity) | High (term frequency scores) |
| Best for | Natural language, Q&A, recommendations | Exact match, filters, structured queries |
Key differences
- 1Semantic search understands meaning; keyword search matches tokens
- 2Embeddings require a trained model and vector DB; BM25 runs on inverted indices
- 3Keyword search is deterministic and explainable; embedding similarity is opaque
- 4Semantic search handles synonyms and paraphrases naturally; keyword search needs manual synonym expansion
- 5BM25 is better for exact matches (product IDs, error codes); embeddings are better for natural language queries
In the interview
- Saying semantic always beats keyword
- Treating vector DBs as replacements for search engines rather than complements
- Ignoring that BM25 crushes semantic on exact IDs, SKUs, and error codes
- Skipping the reranker in a hybrid setup
How to choose
Meaning → semantic. Exact match → keyword. Production → hybrid with a reranker.
Common misconceptions
Myth: Semantic search always beats keyword search.
Reality: BM25 outperforms embeddings on exact-token queries like SKUs, error codes, and product IDs. That's why hybrid retrieval wins in production.
Myth: Vector databases replace traditional search engines.
Reality: They complement them. Elasticsearch, Vespa, and Postgres FTS still power the keyword half of most hybrid stacks.
Memory aid
Keyword is Ctrl-F; semantic is 'you know what I mean.' Hybrid does both, then a reranker picks the winner.
Can you combine them?
Yes, hybrid retrieval is the production standard. Run BM25 and vector search in parallel, then merge results with Reciprocal Rank Fusion (RRF) or a learned reranker. This captures both exact matches and semantic relevance.
Quiz yourself
Related topics
Related comparisons
Bi-encoder vs Cross-encoder
Two ways embeddings power retrieval and reranking
Chunking strategies: fixed vs semantic vs recursive
Three ways to slice documents before they hit the vector store
Hallucination Mitigation vs Context Window Management
Two critical challenges in production LLM systems
Long context vs RAG
Show the model everything, or choose what it should see
RAG vs Fine-tuning
Two approaches to giving LLMs domain specific knowledge
Reranker vs Retriever
The two stages of production RAG, and why you need both