Production RAG, line by line
Running it
Uploads and questions both depend on the model clients, and some of the Worker's code runs when no visitor is there. The clients behind the Models interface call Claude, Workers AI and Vectorize. Once a day the scheduled handler rolls up the day's questions, checks them for drift and runs the canary. The same daily job enforces the data lifecycle: it purges documents after 10 idle days and deletes what was kept with consent after 25 months. A file the visitor removes is deleted at once, in the removal request itself. The routes share a few small helpers; the site creates a visitor's demo account through the Worker's internal routes (POST /internal/demos), and the page loads its session from GET /api/session when it opens.
1,109 of 1,109 lines explained (100%)
Stages, in the order they run
- The Models interface What the pipeline calls 68 of 68 lines explained (100%)
- Model clients Claude, Workers AI and Vectorize 167 of 167 lines explained (100%)
- Daily health Daily roll-up and drift check 227 of 227 lines explained (100%)
- The canary Six fixed questions a day 144 of 144 lines explained (100%)
- The scheduled handler The daily cron at 04:17 UTC 11 of 11 lines explained (100%)
- Removing a file DELETE /api/files 72 of 72 lines explained (100%)
- Idle purge and expiry Documents after 10 idle days, kept rows after 25 months 67 of 67 lines explained (100%)
- Consent and the archive What is kept, and who reads it 149 of 149 lines explained (100%)
- Shared helpers Responses, key hashing and sign-in 42 of 42 lines explained (100%)
- Demo accounts and sessions Creating a demo account and loading its session 162 of 162 lines explained (100%)
- 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.