Adaptive Retrieval: When to Retrieve
What you'll learn: How to build RAG systems that intelligently decide whether to retrieve documents at all, saving resources and reducing irrelevant context.
The Core Problem
Not every user query actually needs retrieval. Simple questions like "What's 2+2?" or "Hi, how are you?" don't require searching through document stores. Retrieving context for every query wastes compute, adds latency, and can inject noise that confuses the LLM.
Adaptive retrieval means making a smart decision: "Should I retrieve for this query, or can the LLM answer directly?"
How It Works
Think of adaptive retrieval as a triage nurse deciding which patients need a specialist. Before sending every question to your expensive retrieval pipeline, you assess:
1. Confidence-Based Routing
If the LLM can answer with high confidence from its training, skip retrieval. For ambiguous or knowledge-intensive queries, trigger retrieval.
2. Question Type Classification
Route queries based on intent:
- Factual questions about specific documents → retrieve
- General knowledge or greetings → direct LLM response
- Math or reasoning → no retrieval needed
3. Simple Pattern Matching
Keywords like "in our documentation" or "according to..." signal retrieval necessity, while "hello" or "explain the concept of" may not.
The Decision Flow
User Query → Classifier → High confidence? → Direct LLM
↓
Low confidence / Knowledge query? → Retrieve → RAG pipeline
This pattern combines concepts you've learned: query classification (lesson 375), confidence scoring (424), and self-evaluation techniques like Self-RAG (436) to gate retrieval intelligently.
Key Takeaway: Adaptive retrieval optimizes RAG by only fetching documents when necessary, based on query confidence, type, and complexity—reducing cost and latency while maintaining answer quality.