Step by Step
S
Sparse retrieval — keyword matching
Sparse retrieval methods like BM25 and TF-IDF match based on exact keywords, offering fast, interpretable results that handle exact terms like names and codes especially well.
Example: BM25 quickly finding documents containing the exact product code or person's name a user searched for.
D
Dense retrieval — semantic embedding similarity
Dense retrieval uses semantic embedding similarity to find relevant documents even when the exact keywords differ, capturing meaning-based relevance rather than literal word matches.
Example: dense retrieval finding a relevant document about "automobiles" even when the user's search query used the word "cars" instead.
H
Hybrid / two-stage — combining both for best results
A common two-stage approach uses fast sparse retrieval (like BM25) to quickly narrow down a large set of candidates, then uses more accurate (but slower) dense retrieval to re-rank those narrowed candidates for final relevance ordering.
Example: using BM25 to quickly narrow a million documents down to the top 100 candidates, then using dense semantic re-ranking to determine the final top 10 most relevant results.
R
RAG pipeline — retrieval grounding LLM answers
The RAG (Retrieval-Augmented Generation) pipeline embeds documents, stores them in a vector database, retrieves the top-K most relevant chunks for a given query, and injects those chunks into the LLM's prompt to ground its answer in real, retrieved facts.
Example: a customer support chatbot retrieving the top 5 most relevant knowledge base chunks and including them directly in the prompt before generating its answer to a specific customer question.
Applied Walkthrough
1
A search system needs to find relevant documents for a query containing a specific, exact product code, but also needs to handle queries phrased with different words than what's in the documents.
2
Ask: which single retrieval method would handle both requirements well? Neither alone — sparse retrieval handles exact terms like product codes well, while dense retrieval handles semantic/meaning-based queries better.
3
A hybrid, two-stage approach combining both would be the ideal solution: sparse retrieval (like BM25) quickly narrows down candidates including exact-match results, while dense retrieval re-ranks for semantic relevance.
4
This combined retrieval approach also forms the foundation of a RAG pipeline, where the retrieved top-K chunks get injected directly into an LLM's prompt to ground its final generated answer in real, retrieved facts.
Exam Application
Exams test whether you can distinguish sparse retrieval (keyword-based, fast, good for exact terms) from dense retrieval (semantic, better for meaning-based queries) and whether you understand the two-stage hybrid approach and how retrieval connects directly to the RAG pipeline.
⚠ Common Trap
The most common trap is assuming dense (semantic) retrieval is always strictly better than sparse (keyword) retrieval. Sparse retrieval specifically excels at exact-match terms like names, codes, and technical identifiers that dense embeddings might not represent as precisely — this is exactly why hybrid, two-stage approaches combining both are often preferred.
✓ Quick Self-Check
1. What does sparse retrieval (like BM25 or TF-IDF) match based on?
Exact keywords.
Tap to reveal / hide
2. What does dense retrieval match based on?
Semantic embedding similarity, finding relevant documents even when exact keywords differ.
Tap to reveal / hide
3. What is the two-stage hybrid retrieval approach?
Sparse retrieval quickly narrows down candidates, then dense retrieval re-ranks those candidates for more accurate final relevance.
Tap to reveal / hide
4. What does the RAG pipeline do with retrieved document chunks?
Injects the top-K most relevant chunks directly into the LLM's prompt to ground its generated answer in real, retrieved facts.
Tap to reveal / hide
5. Why might sparse retrieval outperform dense retrieval for certain queries?
For exact terms like names, codes, or technical identifiers, sparse keyword matching can be more precise than semantic embedding similarity.
Tap to reveal / hide