answering(): ASK 8
segment · lines 837–855View on GitHubBuilds the sources, records the answer and yields done.
Calls asText() answering(): the generator's contract, timer and record() Worker router
// ASK 8 · the answer with its sources, in order of first citation // The passage is the stored text it was given, read by its id: never the model's words.The stage, and its rule Never runs
WhatThe comment names ASK 8, its order (first citation) and its rule. A source's passage is the text of the chunk object that the check matched by id at ASK 6–7, never the model's words. The comment's "read by its id" is loose wording, since nothing is read at this point; chunk.text is already on the matched object.
WhyA citation shows the visitor what the answer rests on. If the passage were the model's own quotation, it could be paraphrased or invented. It is the text the model was given, built from stored chunks (several joined, for a widened passage), under an id the check matched to a given chunk. The check also found every figure in the sentence in its cited passages or in the question.
const cited = [...new Set(shown.flatMap((unit) => unit.cited))]Unique cited chunks, in order Query time
WhatflatMap concatenates each shown unit's cited chunks in release order, and a Set removes repeats, keeping each chunk's first position.
WhyA Set keeps insertion order, so the first source is the first chunk the first released unit cited. Deduplication is by object identity. Every cited chunk is an object from the given passages, because checkUnits matches ids against them, so a chunk cited by three sentences is one object and one source. A held unit released together with the next unit shares that unit's cited chunks.
const sources = cited.map((chunk) => ({ id: chunk.id, file: chunk.file, page: chunk.page, ...(chunk.lastPage !== undefined && chunk.lastPage > chunk.page ? { last_page: chunk.lastPage } : {}), passage: chunk.text, }))One source per cited passage Query time
WhatEach source carries the chunk's id, file and page, its text as passage, and last_page when the passage ends on a later page.
WhyWhen widening (ASK 5) joined a chunk with its neighbours, the given passage is one object with the joined text and the page span. The source therefore shows the whole passage the model read, with its page range. last_page is left out when the passage lies on one page. The demo page groups the sources by file and page, and links each to the PDF at that page when the file is open in the visitor's browser.
// `items` goes to the page only when the answer is a list, so a prose answer's body is as before. // The recorded answer is one text either way (`asText`), since /admin and the golden-set // export read the `questions.answer` column as text. const prose = shown.filter((unit) => unit.kind !== 'item').map((unit) => unit.text).join(' ') const items = shown.filter((unit) => unit.kind === 'item').map((unit) => unit.text)Prose and items Query time
Whatprose joins the text of every lead-in and sentence unit with a space. items is the text of every item unit, in order.
WhyA list answer is a lead-in plus items, and the demo page draws the items as bullets. A prose answer has no items, so its body has the same shape it had before lists existed.
const ok = await record({ answer: asText(prose, items), sources, checked: true, fallback: failed === null ? null : 'stopped', first_ms: firstMs })Record the answer Query time
Whatrecord() inserts the question's row with the answer as one text (asText), the sources as JSON with their passages, checked = 1, fallback 'stopped' when a later unit failed and null otherwise, ms (the time so far), first_ms, keep (1 when the request carries consent) and via.
WhyOnly checked rows come back as history when the demo page reloads. They bring these stored passages with them, so "Show the passage" never needs the chunks again. A row kept with consent (keep = 1) survives the idle purge, which deletes only questions asked without consent (keep = 0). A stopped answer counts as checked, because every sentence shown in it passed.
// The ask ends with the whole answer, then whether its row was written. yield { type: 'done', answer: prose, ...(items.length > 0 ? { items } : {}), sources, found: true, left, first_ms: firstMs, ms: Date.now() - started } yield { type: 'recorded', ok }}done, then recorded Query time
WhatYields done, with items only when the answer is a list and ms as the total time, then the recorded sentinel.
Whydone is the last AskEvent of an answer that was shown. On the demo page it draws the sources and the number of questions left. In the JSON rendering it becomes the response body. The insert runs before done is yielded, so when a consumer sees done the row has been written or the write has failed, and recorded reports which.
