Production RAG, line by line
Eval harness
The eval harness measures the pipeline. Its golden set is a list of cases, each a question with the facts a right answer states and the passages that hold them. A run gives each corpus of PDFs its own demo account (a row in the demos table, the same kind a visitor gets at sign-up) and asks every case through the demo app's real routes and real models on a local Worker, which traces the Claude calls. The run then scores each case and writes a report.
623 of 623 lines explained (100%)
The golden set
How run.mjs reads the golden set, evals/cases.jsonl: one JSON case per line, each naming the corpus (the set of PDFs) whose demo account it is asked through.
10 of 10 lines explained (100%)
- Reading the cases cases.jsonl and the corpora 10 of 10 lines explained (100%)
Eval runner
evals/run.mjs from its start to the scored report: the spend caps and the ledger, a fresh local D1 and the harness Worker, one demo account per corpus (a row in the demos table, as a visitor gets) with its PDFs uploaded through the real route, each case asked, traced and scored, and the report.
339 of 339 lines explained (100%)
- Caps, arguments and the Worker Before any case 100 of 100 lines explained (100%)
- One demo account per corpus The PDFs uploaded 70 of 70 lines explained (100%)
- Asking each case Ask, trace, score, spend 54 of 54 lines explained (100%)
- Scoring a case Facts, sources, status 63 of 63 lines explained (100%)
- Writing the report results.json and results.md 52 of 52 lines explained (100%)
The harness Worker
The Worker that the harness runs locally with wrangler dev: the demo app's own code with the real models, a fetch wrapper that records every Claude call, and five routes that run.mjs calls to read that record, reset the question limit, delete the run's vectors, read stored chunks back and check indexing.
209 of 209 lines explained (100%)
- Traced demo app and /eval routes evals/worker.ts 209 of 209 lines explained (100%)
Stream usage reader
How the harness reads the token usage of a streamed answer from the Messages API's server-sent events, so that a run can price every case.
65 of 65 lines explained (100%)
- Reading a streamed reply's usage evals/trace.ts 65 of 65 lines explained (100%)
Reading a run
Each run writes a folder under evals/runs/, named by its start time and label. The folder holds results.json and results.md. results.json has every case's status, the facts met, how far each expected passage got (the pool, the context, the citations) and the cost, plus metadata naming the commit, the hashes of the cases and the corpus, and the models. results.md has a tally, medians, a table row per case and every answer of a case that ran. evals/runs/ledger.json holds every run's spend against the $7.50 cap on all runs. evals/JOURNAL.md is the narrative: each round's hypothesis, the runs that tested it and what was kept.
Tuning journal
evals/JOURNAL.md is the hand-written record of the first day the harness was used to tune the pipeline, 2026-10-21: the failure that started it, how the harness was built, and each tuning round with the change it tried, the score and cost of its run, and what was kept. Nothing in the repository reads it.
- In the browser
- runs in the visitor's browser, on the demo page
- Ingestion
- runs when a PDF's text is uploaded
- Query time
- runs when the Worker answers a question or a search_documents call from the MCP server, and in the request handling every route shares, in the Worker and in the site's functions, which uploads and removals pass through too
- MCP request
- runs on a request to the MCP server or its OAuth endpoints
- Site request
- runs on a site request that is not a question, an upload, an MCP call or the cron: a page load, a session read, the demo page's /api/grants calls, an admin read, a file's removal
- Scheduled
- runs in the Worker's daily cron job
- Eval run
- runs when the eval harness runs on a developer's machine
- MCP host
- runs in an MCP host outside the Worker: the search loop example, on a developer's machine (npm run search) or in its test
- Module load
- runs once, when the module is loaded
- Type only
- erased by the TypeScript compiler; never runs
- Never runs
- a comment, a licence or markup with no behaviour of its own
Pinned to joelstevick-demo-rag-pipeline at 6a9c6c7.