Retrieval Strategies
Fetching the right chunks, first
Retrieval connects the question to the right chunks: embedding search, keyword search, hybrid fusion, and reranking. The retriever determines what the LLM can even use.
What you will learn
- Run embedding-only, keyword, and hybrid retrieval
- Set top-k and rerank thresholds intelligently
- Diagnose 'right doc, wrong chunk'
What is this?
Retrieval takes an embedded question and returns candidate chunks via vector similarity, BM25-style keyword match, or both fused. A reranker then re-sorts candidates by finer-grained matching. The retriever is the funnel: garbage in means garbage prompts, so top-k, hybrid mix and reranking decide most of a RAG system's quality.
Why do you need it?
- The LLM can't use what never made the top-k — retrieval bounds the ceiling.
- Hybrid fusion catches exact-string needs that embeddings miss.
- Reranking fixes 'embeddings are good enough' by re-scoring semantically.
- Top-k control is your latency + quality slider.
Mental model
Searching a library by category cards vs flipping to the right shelf
Retrieval
First you skim category shelves to shortlist (ANN top-N). A reference librarian (reranker) then checks a few shortlisted books closely for the exact passage. Wide net first, precise pick second.
How it works
- Embed the query with the SAME model → vector search top-k.
- Optional: keyword (BM25) pass over the same corpus.
- Fuse lists (RRF/weighted) when both run.
- Rerank the fused candidates with a stronger scoring model or cross-encoder.
- Trim to the final top-k and pass to the prompt.
Retrieval stages.
In production
- Policy engines hybrid-retrieve then cross-encoder-rerank for high-precision scope.
- Code assistants use BM25 for symbol names plus vector for concept queries.
- Simple support tickets ship embedding-only + fixed thresholds to start.
Best practices
- Retrieve a wider top-N (e.g. 20) then rerank down to 4-8 for better precision.
- Benchmark retriever variants on your labeled query set before tuning the prompt.
- Return chunk scores and source ids — they power citations and not-found UX.
- Cache embeddings for repeated queries.
Common mistakes
- Skipping rerank 'because embeddings are fine' on a noisy corpus.
- Putting 20 giant chunks in the prompt and overflowing the context.
- Using a different embedding model at query time than at ingest.
- Hard-coding top-k with no notion of threshold.
Common issues
High-similarity irrelevant hitsCoarse embeddings or need for rerank
Add rerank, increase top-N before rerank, shrink k.
Exact SKUs not retrievedNo lexical leg
Add BM25/lexical or hybrid fusion.
Debugging tips
- Right topic, wrong details → chunks are coarse; add rerank and tune top-k.
- Missing exact identifiers → add a keyword/hybrid leg.
- Retrieval infallible on demo, failing in prod → demo used canned queries; build a labeled set.
Interview checkpoint
Hands-on lab
- Build two retrievers (vector + vector+lexical)
- Score hit-rate@k on a labeled set
- Pick the retriever by evidence
A/B Two Retrievers on Your Labels
35 min · intermediate
Quick quiz
The role of reranking is to…
Retrieval quality caps the ceiling of RAG answers.