What this is

No new concepts in this lesson. This is a checkpoint: a small, real script built entirely out of ideas from Lessons 1 through 8, combined into one thing, plus one small addition, a visible indicator of whether correction actually fired. If you can read lesson.py and understand why every piece is there, you've mastered the Beginner tier. If any piece feels unfamiliar, that's a sign to revisit the lesson it came from before continuing to Intermediate.

What it does

Loads all five fixture notes, embeds and stores them (Lesson 2), then answers three questions through corrective_ask(), printing whether retrieval needed correcting for each one, so you can watch the pipeline self-correct on the one question that needs it, and stay out of the way on the two that don't.

Where each piece came from

def corrective_ask(query: str, store: list[dict], k: int = 3) -> tuple[str, bool]:
retrieved = retrieve(query, store, k)
naive_top1_source = retrieved[0]["source"] if retrieved else None
...

Lesson 8's corrective_ask(), with one addition: before grading anything, it remembers what naive top-1 retrieval alone would have used. That's not part of the corrective pipeline itself, it's purely there so this lesson can report, honestly, whether correction changed anything.

used_sources = {chunk["source"] for chunk in relevant}
corrected = naive_top1_source is not None and naive_top1_source not in used_sources

The comparison: did the source that actually reached generation differ from what naive top-1 would have used? If naive retrieval was already right, corrected is False, correction didn't need to do anything, and didn't pretend to.

Try this yourself

Without looking anything up:

  • Ask a question where naive top-1 retrieval is already correct (like the pizza dough one). Confirm corrected prints False, and that the pipeline didn't spend an extra grading call pretending it needed to fix something that wasn't broken. (It still spends one grading call to confirm the top result is relevant, that's expected.)
  • Add a new .md file of your own to fixtures/notes/, does a question about it work correctly on the next run, with [no correction needed]?
  • Lower k from 3 to 1 in corrective_ask's default and re-run this course's running Aurora/bookshelf example. Does correction still fix it, and if not, which lesson explains why (hint: Lesson 4)?

If you can make these changes confidently, you're ready for the Intermediate tier, starting at Lesson 10.