Few-Shot Examples with Retrieved Context
What You'll Learn
You'll learn how to use few-shot examples in your prompts to show the LLM exactly how to work with retrieved context in RAG systems.
The Core Idea
Few-shot learning means showing the model examples of correct behavior before asking it to perform a task. In RAG, this means demonstrating how to properly use retrieved documents—not just telling the model to use them.
Think of it like showing a new chef three completed dishes before asking them to cook: they see the plating, portion sizes, and garnish patterns. Similarly, you show the LLM 2-3 examples of questions answered correctly using retrieved context.
Why This Matters for RAG
Retrieved context alone isn't always enough. The model might:
- Ignore retrieved documents and hallucinate
- Quote excessively without synthesizing
- Miss key information buried in the context
- Fail to cite sources properly
Few-shot examples establish the pattern you want: "Here's a question, here's context, here's the right way to answer."
Structure of Few-Shot RAG Prompts
Example 1:
Context: [sample retrieved chunk]
Question: [sample question]
Answer: [ideal response with citations]
Example 2:
Context: [another chunk]
Question: [another question]
Answer: [another ideal response]
---
Now answer this:
Context: [actual retrieved documents]
Question: [user's real question]
Answer:
The examples teach the model your expectations: citation style, synthesis depth, when to say "not found in context," and confidence expression.
Key Considerations
Choose examples that demonstrate edge cases: partial information, conflicting sources, or when context doesn't fully answer the question. Make sure examples match your domain and desired output format.
Key Takeaway: Few-shot examples with retrieved context teach the LLM by demonstration how to properly synthesize, cite, and respond using RAG documents—turning vague instructions into concrete patterns.