RAG & Agents Engineering

M28 lab, grading and query rewriting

A retry loop needs a bound.

The lesson 28.3 graph on five Larkspur Cloud golden questions: a topic check, top-2 retrieval, a grade for each chunk, and a rewrite when every chunk fails. Set how many rewrites the router allows, and read what each question costs.

Golden question
Topic check before retrieval
Path taken
LLM calls
Retrievals
Rewrites used

What the graph did

TF-IDF cosine, top 2

StepQuery or chunkScoreGrade

The golden set at this setting

Golden questionPathRetrievalsLLM calls

This is the log the M28 lab brief asks for: how often each path fires on the golden set, and what it costs.

What is real here

Retrieval is real: TF-IDF with scikit-learn’s defaults over the twelve M10 handbook chunks, top 2 as in notebook 03a. The routing and the call counts follow 03a: one call for the topic check, one grader call per chunk, one per rewrite, one to generate; the handlers are fixed text. Three parts are stand-ins. The grader passes a chunk only if the golden set lists it as the answer, the topic check reads the golden label, and the rewrites are hand-written in the style the 03a optimiser prompt asks for. A real LLM grader and rewriter make mistakes these do not.