Dense retrieval vs sparse retrieval — what's the difference?
Dense retrieval and sparse retrieval are two different ways to find relevant information in a RAG system.
The simplest difference is:
Dense retrieval → searches by meaning Sparse retrieval → searches by matching terms
Dense retrieval
Dense retrieval converts the query and document chunks into embeddings.
Example:
Query: "How can I get my money back?"
Document: "Customers may request a refund within 30 days."
The wording is different, but the meanings are similar.
A dense retriever can still match them because the query and document vectors are close in embedding space.
Dense retrieval is strong for:
- Paraphrases
- Synonyms
- Conceptual similarity
- Natural-language questions
Its weakness is that it can sometimes miss exact identifiers, rare names, codes, or numbers.
Sparse retrieval
Sparse retrieval represents text using terms or token weights instead of dense semantic vectors.
BM25 is the classic example.
Suppose the query is:
"ERR_AUTH_401"
A sparse retriever is very good at finding documents containing that exact error code.
Sparse retrieval is strong for:
- Exact keywords
- Product names
- Error codes
- IDs
- Rare technical terms
- Numbers and exact phrases
But it is weaker when the query uses very different wording from the document.
Example
Query:
"How do I terminate my subscription?"
Document A: "You can cancel your plan from account settings."
Document B: "Subscription termination policy"
Dense retrieval may strongly prefer Document A because the meaning matches.
Sparse retrieval may prefer Document B because the exact term "subscription" appears.
Why are the vectors called dense and sparse?
Dense embeddings usually contain many non-zero numerical values, for example:
[0.12, -0.34, 0.78, 0.05, ...]
Sparse representations have a very large vocabulary-sized space, but only a small number of terms have non-zero weights.
Conceptually:
refund → 1.8 policy → 0.9 customer → 0.4
Most other vocabulary terms have a weight of zero.
Which one should you use?
Use dense retrieval when semantic meaning matters most.
Use sparse retrieval when exact wording, identifiers, or rare terms matter.
In many production RAG systems, the best answer is not choosing one.
It is combining both.
Dense search can find meaning-based matches, while sparse search catches exact lexical matches.
That combination is called hybrid retrieval.
Interview takeaway
Dense retrieval uses embeddings to find semantically similar content even when the wording differs. Sparse retrieval uses lexical signals such as BM25 to find documents that share important words or terms with the query. Dense is strong for meaning; sparse is strong for exact matches. Production RAG systems often combine both.
Learning Sequence
Retrieval-Augmented Generation Curriculum
Explore Related Questions
Deepen your understanding across related Retrieval-Augmented Generation topics.