Dense Retrieval vs Keyword Search
A comparison of two search approaches: neural network-based semantic retrieval (Dense Retrieval) and traditional keyword matching (Sparse / BM25). It explains why vector search may fail in product item searches and how hybrid search operates.
1. Concept Overview & Systemic Problem
When vector databases emerged in 2023, many enthusiasts proclaimed: “Traditional text search is dead! Now everything will be searched through neural vectors!”
However, when companies began implementing pure vector search in real e-commerce sites or warehouses, problems arose:
- A customer inputs the exact part code:
A211-540-00-44➔ vector search returns similar parts with different digits! - A lawyer searches for case number
№ 752/1234/25➔ vector search shows entirely different court rulings with similar words.
It turned out that each method has its strengths and blind spots:
- Dense (Vector Search): unmatched for understanding ideas, abstract queries, and synonyms.
- Sparse / Keyword (BM25): indispensable for searching exact items, codes, passport numbers, and rare surnames.
2. Architectural Taxonomy & Mental Model
┌─────────────────────────────────────────────────────────────┐
│ WHO WILL FIND THE ANSWER BETTER? │
├──────────────────────────────┬──────────────────────────────┤
│ 🔍 User Query: │ 🏆 Who Wins and Why: │
├──────────────────────────────┼──────────────────────────────┤
│ “Affordable family car” │ 🟢 DENSE (Vector Search): │
│ │ Understands the meaning and │
│ │ finds SUVs and minivans │
├──────────────────────────────┼──────────────────────────────┤
│ “Oil filter OC-90” │ 🔵 BM25 (Keyword Search): │
│ │ Instantly finds the exact index│
│ │ without guessing neighboring parts│
├──────────────────────────────┼──────────────────────────────┤
│ “How to reduce fever at night”│ 🟢 DENSE (Vector Search): │
│ │ Finds paracetamol and │
│ │ antipyretic medications │
├──────────────────────────────┼──────────────────────────────┤
│ “Article 115 part 2 of the Criminal Code”│ 🔵 BM25 (Keyword Search): │
│ │ Finds exactly this article, not │
│ │ general considerations about crime│
└──────────────────────────────┴──────────────────────────────┘
3. Technical Pipeline & Internal Mechanics
Today, no professional architect chooses just one method. The industry standard has become the hybrid approach:
┌────────────────────────┐
│ User Query │
└───────────┬────────────┘
│
┌───────────────┴───────────────┐
▼ ▼
[Vector Dense] [Traditional BM25]
(Meaning-Based Search) (Item-Based Search)
│ │
└───────────────┬───────────────┘
▼
┌─────────────────────────────┐
│ Merging Lists (RRF) │
│ Best Common Findings │
└─────────────────────────────┘
4. Production Engineering Scenarios
If you are building a search for an e-commerce site or documentation catalog:
- Do not discard traditional keyword search!
- Use databases that natively support hybrid search (e.g., Qdrant or PostgreSQL with a combination of
pgvectorandtsvector). This ensures that your users can find products both by description like “nice red dress” and by exact item codeSKU-881!
01. E-Commerce Product Search
Implement a hybrid search to allow users to find products by both general descriptions and specific SKUs, enhancing user experience and conversion rates.
02. Legal Document Retrieval
Utilize BM25 for precise legal queries while employing dense retrieval for broader context searches, ensuring comprehensive results for legal professionals.
03. Medical Information Lookup
Combine dense retrieval for symptom-related queries with keyword search for exact medication names, providing accurate and relevant medical information to users.
5. Pitfalls, Common Mistakes & Security
- Over-reliance on Vector Search: Avoid assuming that vector search will always yield relevant results; it may misinterpret specific queries.
- Ignoring User Intent: Failing to understand the user's intent can lead to poor search results; always consider the context of the query.
- Security Vulnerabilities: Ensure that both search methods are secured against injection attacks and data leaks, particularly when handling sensitive information.
FAQ: Dense Retrieval vs Keyword Search
Related terms
Semantic Search: Why Meaning-Based Search Outperforms Traditional Ctrl+F
A technology for information retrieval based on the conceptual content of a query rather than exact letter matches or keywords. It understands synonyms, paraphrasing, spelling errors, and abstract natural language questions.
Vector Databases (Vector DBs & ANN Search)
Specialized DBMS and extensions (Qdrant, pgvector, Milvus, Chroma, Turso) optimized for storing millions of high-dimensional vectors and ultra-fast Approximate Nearest Neighbors (ANN) search.
Embeddings Simplified (How Text Becomes Numbers)
A fundamental technology that transforms words, sentences, or images into multi-dimensional lists of numbers (vectors). It enables computers to mathematically measure semantic proximity between different thoughts and concepts.