Where we left off

Lesson 4 graded three retrieved chunks and found exactly one relevant: bookshelf.md, ranked below the top-scoring but wrongly-relevant weather-station.md. This lesson does the obvious next thing with that information: drop what's graded not-relevant, keep what isn't, and only hand the survivors to generation. This is the first lesson where correction actually changes the final answer, not just a printed grade.

The code, piece by piece

def filter_relevant(graded_chunks: list[dict]) -> list[dict]:
return [chunk for chunk in graded_chunks if chunk["grade"] == "relevant"]

One line. Everything before this was setup, retrieval, grading, this is the actual corrective act: a chunk's rank or score no longer matters once it's graded not-relevant, it simply never reaches the prompt.

print("Naive answer (top-1, no grading):")
print(f" {generate_answer(QUESTION, top_k[:1])}\n")
...
print(f"Corrected answer (graded, filtered):")
print(f" {generate_answer(QUESTION, filtered)}")

Both answers are generated and printed side by side specifically so you can see the actual, textual difference correction makes, not just a grade changing color in a printout. This is the answer-quality comparison Lesson 17 will later turn into a repeatable score.

Checkpoint

  • Filtering by grade, not by score, is the corrective act, everything in Lessons 1-4 was building the information this lesson finally acts on.
  • This lesson's specific example resolves without ever needing a query rewrite (Lessons 6-7), because the correct chunk was already inside the over-fetched k=3, just outranked. Rewriting exists for a different situation: when every retrieved chunk grades not-relevant, which Lesson 6 demonstrates next.

If anything here still feels unclear, ask before moving to Lesson 6.