Recipe: paste, retrieve or fine-tune?
The window size and tokens per page are example values; use your model's and your documents'.
Two recipes to start any RAG project with: a decision function that says whether to paste, retrieve or fine-tune, and a baseline harness that measures how often your retriever finds the right passage. Plus where a real embedding call plugs in.
Change the code and press Run (Ctrl+Enter). Predict what will happen first, then break it on purpose and read what changes. Your edits are saved and match the lesson page.
Ready for more? This phase has 5 hands-on exercises with automatic checks.
Practice questions
Write the code in the editor, run it, then open the model answer to compare.
Write hit_rate(results, expected, k) where results is a list of ranked id lists and expected a list of ids. Print the hit rate at 1 and at 2 for three made-up questions.
Extend recommend with a parameter access_controlled that adds the reason "documents have per-user permissions" and therefore recommends RAG. Print the decision for a 4-page document with permissions.
Explain it without notes
What does the baseline harness measure, and why is it written before improving retrieval?
What is the difference between hit rate at 1 and hit rate at k, and which matters more for RAG?
Why should recommend return reasons as well as a decision?
Expected output
One 4-page policy, stable
-> paste the documents into the prompt (small, stable, and no sources needed)
The 60-page handbook, edited weekly, sources required
-> use RAG (the documents change often; answers must point to their source)
A 2000-page help centre
-> use RAG (the corpus is about 1000000 tokens, more than half the context window)
Replies are correct but too formal
-> improve the prompt, then consider fine-tuning (the problem is how the model answers, not what it knows)