← All questions
RAGMedium· Few-shot Learning· Retrieval· Optimization

How do you choose the few-shot examples in a RAG prompt?

Simple similarity-based retrieval is often insufficient because it does not account for the generator’s specific performance. By using the generator to score candidates based on conditional entropy, you ensure the selected examples actually improve model performance. This process requires a prefill pass per candidate, which is a necessary cost for high-quality few-shot selection.

Code playground (Python)