After retrieval, a demo account whose documents fit in 12 chunks or fewer (ANSWER_CHUNKS) is read whole: every chunk joins the candidate pool (the chunks handed on to the rerank), retrieved chunks first. For a larger account the pool is the retrieved candidates alone.
demo/src/app.ts23 / 23 lines on this page explainedlines 45-48,686-704 of 1124; the rest are on other stage pages
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
The two "couldn't find that" lines, one for each amount read.
/** The fallback when the documents were read whole and none of them holds the answer. */exportconstNOT_FOUND = "I couldn't find that in your documents."/** Said instead of NOT_FOUND when the answer was written from only part of the documents. */exportconstNOT_IN_PASSAGES = "I couldn't find that in the passages I read for this question, which are only part of your documents. Asking about it more specifically may find it."
The two fallback lines Module load
WhatNOT_FOUND is the fallback when every chunk was given to the answer model. NOT_IN_PASSAGES is the fallback when only retrieved passages were given; it says they are only part of the documents and suggests asking more specifically.
WhyWhen only retrieved passages were read, the answer may be in a chunk retrieval missed, so saying it is not in the documents would be false. Both constants are exported. The empty-pool fallback event, and the one after the check at ASK 6–7, carry one of them as answer.
NOT_FOUND = "I couldn't find that in your documents."
A fallback for a question the sample PDF does not answer. No sentence reached the page, so the page shows the NOT_IN_PASSAGES line and no sources. The line tells the visitor that only the passages read for this question were searched. 2026-11-29, the live demo at joelstevick.com/demo in Chrome. The live page is newer than the pinned commit, so its file selector, trash icons and indexing note are not in the code shown here.
// Documents that fit the answer whole are read whole, retrieved chunks first: then, and only// then, "not in your documents" is true.const whole = all.length <= ANSWER_CHUNKS
Do the documents fit whole? Query time
Whatwhole is true when the demo account has at most ANSWER_CHUNKS (12) chunks in all, including when it has none.
WhyThe reranker passes at most 12 chunks to the answer model, so an account of 12 chunks or fewer can be given to it entirely. A question the answer model cannot answer from all of them is then one the documents do not answer. whole also turns widening off at ASK 5, because every neighbour is already in the pool.
// `includes` here is by object identity, not text: `fuseKeywordAndVector` returns the very Chunk objects// `all` holds, so the filter appends every chunk not already among the retrieved.const pool = whole ? [...retrieved, ...all.filter((chunk) => !retrieved.includes(chunk))] : retrieved
The pool: retrieved first, then the rest Query time
WhatFor a whole read, the chunks retrieval did not return are appended after the retrieved ones. The includes test compares objects by identity.
WhyThe retrieved chunks keep their fused order at the front, and the reranker's fallback, which returns the pool in order, relies on that order. Identity works because fuseKeywordAndVector returns the same Chunk objects that all holds, so two chunks with the same text are still two chunks. includes inside filter is quadratic, which costs nothing noticeable over at most 12 chunks.
// The fallback line says only what is true for how much was read.const missing = whole ? NOT_FOUND : NOT_IN_PASSAGES// No candidate at all (no chunks, or none matched): the fallback is recorded as not_found, and the question still counts.
Choose the fallback line Query time
Whatmissing is NOT_FOUND when the documents were read whole, and NOT_IN_PASSAGES otherwise.
WhyThe line is chosen once, before the empty-pool check, because the empty-pool fallback and the fallback after the answer check (ASK 6–7) both use it, and both must say only what is true for how much was read.
if (pool.length === 0) {const ok = awaitrecord({ answer: null, fallback: 'not_found' })yield { type: 'fallback', answer: missing, found: false, left }yield { type: 'recorded', ok }return }
Empty pool: end with the fallback Query time
WhatWith no candidate, record() writes the question's row with no answer and fallback 'not_found'. The generator then yields the fallback event and the recorded sentinel, and returns without calling the reranker or the answer model.
WhyThe pool is empty in two cases. Either the account has no chunks, so whole is true and the line is NOT_FOUND. Or the account has more than 12 chunks, BM25 matched no word of the question, and vector search returned nothing usable (it was unavailable, or every id was stale). The reservation from ASK 2 stays, because the ask ran and its answer was the fallback. This fallback event has no refused field, which is how a consumer tells it apart from a fallback after the check.