Dense Retrieval vs Sparse Retrieval
What you'll learn: How semantic vector search differs from traditional keyword-based methods for retrieving relevant documents in RAG systems.
Two Approaches to Finding Relevant Documents
When your RAG system needs to find relevant context for a user's query, it can search in two fundamentally different ways:
Sparse Retrieval (like BM25) works like Ctrl+F on steroids. It looks for exact keyword matches and term frequencies, counting how often query words appear in documents. It's "sparse" because documents are represented as high-dimensional vectors where most values are zero—only positions corresponding to words that actually appear have non-zero values.
Dense Retrieval uses embedding models to convert both queries and documents into compact semantic vectors (typically 384-1024 dimensions). These vectors capture meaning, not just words. Documents about "car" and "automobile" become similar vectors even though they share no keywords.
Key Differences
Sparse retrieval excels at:
- Exact term matching (product codes, names, technical terms)
- Transparent scoring (you can see which keywords matched)
- No model training required
Dense retrieval excels at:
- Semantic similarity ("best budget laptop" finds "affordable computers")
- Handling paraphrasing and synonyms
- Cross-lingual search (when multilingual embeddings are used)
Think of sparse retrieval as a librarian matching catalog cards by exact titles, while dense retrieval is like a librarian who understands what you mean and recommends books on the same topic even if they use different words.
Hybrid Approaches
Modern RAG systems often combine both: sparse retrieval for precise keyword matches plus dense retrieval for semantic understanding, then merge and re-rank results.
Key Takeaway: Sparse retrieval (BM25) matches exact keywords efficiently but misses semantics; dense retrieval uses embeddings to find meaning-based similarity, capturing what keywords cannot—most production RAG systems benefit from combining both approaches.