chapter four
4 In-context learning, few-shot, and RAG
This chapter covers
- Building few-shot prompts that generalize across an input distribution
- Scaling to many-shot when long context windows make it cost-effective
- Validating prompts with held-out tests and run-to-run variability checks
- Building retrieval-augmented generation (RAG) for knowledge gaps, from a 50-line minimal pipeline to chunking, reranking, hybrid retrieval, and end-to-end evaluation
- Deciding when to graduate from prompting to parameter-efficient fine-tuning
Contoso's support team needs to route incoming tickets into twelve categories. Volume is climbing, and Maya, an engineer, opens the runbook for spinning up a fine-tuning job: data prep, GPU node, evaluation pipeline, deployment story. A colleague suggests trying few-shot first, on the same Qwen3-4B-Instruct-2507 model the team already runs. Eight hand-picked examples, weighted toward the highest-volume categories, run against a hundred labeled tickets pulled from last week. Top-1 accuracy: 82%. Two hours from idea to a number, no checkpoint to host, no training pipeline to maintain.