Skip to content

knowledge.synthesize keeps only the citations of chunks it read, and abstains on an empty answer - #225

Merged
zlareb1 merged 20 commits into
mainfrom
feat/knowledge-synthesize-grounding
Nov 3, 2026
Merged

zlareb1 merged 20 commits into
mainfrom
feat/knowledge-synthesize-grounding

Conversation

@zlareb1

@zlareb1 zlareb1 commented Nov 3, 2026 •

Copy link
Copy Markdown
Member

Changelog category (leave one):

  • Improvement

Changelog entry (one or two sentences a user of Loom can read without the diff; the release pull request collects these into the release notes):

knowledge.synthesize removes from its answer any citation of a chunk it did not read and lists it in unsupported_citations; an answer with no letter or digit, as written or once those citations are removed, abstains with abstain_reason="empty_answer".

Why

knowledge.synthesize returned every [source#idx] tag the model wrote as citations, unchecked. A model can cite a part it was never shown: a chunk past max_windows (the answer then reads as if the truncated part was covered), an index that does not exist, or a document that was not named. A caller that follows such a citation reads text the answer did not come from. And an answer the passes returned empty came back with abstain: false.

Design

  • A citation is a bracket holding one or more source#idx / source#a-b items separated by , or ; (Window.cite names a window spanning documents as a comma list); a source holds no blank, comma, semicolon or bracket (of nested brackets the innermost is read). A bracket with anything else in it is prose and stays as written ([PR #42], [see doc#1]); a bracket shaped like a citation ([issue#42]) counts as one wherever it came from. The cost of the narrow shape is that a citation of a source with a blank, comma or semicolon is prose and left unchecked; one with a comma or semicolon ([doc://a?x=1,2#3]) is no longer listed in citations, and one with a blank never was. cites_what_was_read(tag, read) needs every item read (a tag that is not a list of items names nothing read): source#idx names a chunk in the set of (source, idx) pairs the windows showed, source#a-b needs a <= b and both ends read. The read set is built from the windows actually sent, after the max_windows cut. Indexes are ASCII digits 0-9; one longer than nine digits names no chunk and is removed without being parsed. The answer is grounded by one pattern in a pass over its citations, repeated until a pass removes nothing, since a removal can close an outer bracket into a new citation (at most eight passes); citations(), which only the handler called, is gone.
  • ground_citations(answer, read) returns the answer with the unsupported tags removed, the kept tags and the removed ones. The answer keeps its prose; only the bracketed tag goes.
  • Output: citations (kept, in the order found), new unsupported_citations (removed). An answer with no letter or digit, as written or once the unsupported tags are removed ("[doc#9]." leaves only .), abstains (empty_answer). A list is listed once whatever the blanks around its separators.
  • Pure functions in server/memory/domain/corpus_synthesis.py, next to the window and prompt helpers; the handler builds the read set and grounds the answer before the max_answer_chars cut, so removed citations take no room; when the cut halves a kept citation, citations is read again from the returned text, so it lists only what the answer holds.

Scope and risk

knowledge.synthesize only. memory.ask routes a summary-shaped question to it and reads its answer; that answer now carries no tag for an unread chunk. No storage, no prompt change.

Compatibility, rollout and rollback

  • Wire: additive. KnowledgeSynthesizeOutput.unsupported_citations (default []); abstain_reason gains the value empty_answer. citations drops unread citations (now in unsupported_citations) and brackets naming a source with a comma or semicolon, which are now prose (a source with a blank never matched), and an index written in non-ASCII digits ([doc#١]), which the old \d matched; it now also lists a read citation padded with blanks ([ doc#1]) or a list with blanks around its separators ([doc#0, doc#1]), which the old pattern did not match.
  • Operator steps: none.
  • Rollback: revert; nothing is stored.

Tests

  • tests/unit/test_corpus_synthesis.py: which tags count as read (an index, a range, a range past what was read, a backwards range, another document, a two-document list); the answer with unread tags removed; bracketed prose (and a non-ASCII index) kept as prose; a ; list checked part by part; a source holding #; a window spanning two documents keeping its citation; an answer of only unread tags abstaining; unread citations removed before the max_answer_chars cut; the handler with max_windows cutting the read set (a tag to a cut chunk and to a missing chunk both removed) and an empty answer abstaining. With test_ask_synthesize_route, the decision-extract tests that share the module, test_public_copy and test_doc_links. The grammar cases are one parametrized test, one case per id.
  • make format lint typecheck; SDK op tables and the operations reference regenerated.

AI assistance in the code (leave one; writing this description with AI is fine):

  • AI-generated (an agent wrote most of the diff): Claude Code.

  • I can explain every line of this diff and how it interacts with the rest of Loom.

Checklist

  • make format-check, make lint, make typecheck and make test-unit pass; the integration suite passes if server behaviour changed.
  • Generated files are regenerated in this PR, not by hand: the SDK op tables, docs/reference/configuration.md and the docs/reference/ tables (python scripts/codegen/docs_reference.py), the reach manifest, schemas/schema.sql (make schema-dump) and the Codex plugin copies (python3 scripts/codegen/agent_plugin_sync.py).
  • Docs under docs/ describe the system as it now is, and this description names any operator steps and wire changes.
  • Repository text has no dates, people, host names, internal namespaces, ticket or decision numbers; the history goes in this description (tests/unit/test_public_copy.py).
  • Commits are signed off (git commit -s), as CONTRIBUTING.md asks.

🤖 Generated with Claude Code

@zlareb1
zlareb1 force-pushed the feat/knowledge-synthesize-grounding branch 3 times, most recently from 8da6328 to e6060d2 Compare November 3, 2026 19:04
zlareb1 and others added 20 commits November 3, 2026 19:32
…abstains on an empty answer

A [source#idx] tag the model wrote for a chunk the passes were not shown (past
max_windows, a missing index, another document) is removed from the answer and
listed in unsupported_citations; citations lists only the tags of chunks read.
An answer the passes left empty abstains with abstain_reason=empty_answer.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…e, is checked like any other

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…upported rather than an error

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…ays as prose

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
… and a blank run scanned once

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…ir innermost

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…wer written empty

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…e too; one item grammar

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…ome in the order found

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
… must be read

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…ted once

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…alue means

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
@zlareb1
zlareb1 force-pushed the feat/knowledge-synthesize-grounding branch from e6060d2 to 3f56157 Compare November 3, 2026 19:35
@zlareb1
zlareb1 merged commit 267c535 into main Nov 3, 2026
2 checks passed
@zlareb1
zlareb1 deleted the feat/knowledge-synthesize-grounding branch November 3, 2026 19:35
@pufit pufit mentioned this pull request Nov 4, 2026
9 tasks done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant