Skip to content

The assistant cites document passages by source and section, and the qualification measures it - #260

Merged
zlareb1 merged 5 commits into
mainfrom
feat/i160-doc-ask
Nov 4, 2026
Merged

zlareb1 merged 5 commits into
mainfrom
feat/i160-doc-ask

Conversation

@zlareb1

@zlareb1 zlareb1 commented Nov 4, 2026 •

Copy link
Copy Markdown
Member

Related: #160

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):

On the assistant MCP toolset, the model is told to cite a document answer by source_uri and section breadcrumb, with the revision when knowledge.get returned one, and to say a fact is not in the documents when no knowledge.search hit states it. The LibreChat qualification harness now asks questions over documents and reports recall@k of the labeled section, citation validity and abstention.

Why

The assistant toolset already listed knowledge.search, knowledge.get and knowledge.list, but nothing measured whether a document answer was cited correctly or whether the model abstained when the documents did not hold the fact. Its instructions also asked for a document's doc_id or ingested_at rather than its revision. This change makes the citation contract explicit (source and section; a revision only when a tool returned one, which on main means a knowledge.get) and extends the existing qualification set with document questions, so the answers can be scored against labels.

Scope and risk

  • Assistant instructions (server/transport/mcp_primer.py, server/transport/mcp_descriptions.py): the assistant primer asks for a document's source_uri and section, and its revision only when loom_knowledge_get returned one (a search hit carries none on main). The assistant's knowledge.search description says a hit is the nearest passage, not an answer, and that the revision comes from loom_knowledge_get. knowledge.get asks for the revision in place of doc_id/ingested_at. Only text changed: no op, field or roster entry. The default listing is unchanged.
  • Roster: no new tool. The assistant reaches documents through knowledge.search/get/list (and knowledge.inspect), which it already lists. knowledge.outline would add about 230 listing tokens to every model call (the assistant listing is about 9,700). In the run, every cited section came from a hit, and outline does not return the revision, which is the part that was missing. knowledge.synthesize is left out because it is a paid LLM call. The assistant does no document parsing; it calls only knowledge.* ops.
  • Harness (integrations/librechat/qualification/): a third namespace, acme-library (org acme), with its own viewer person and five documents written through knowledge.upsert: a Markdown runbook with nested headings, a plain-text contract, a SQL table definition, a TOML file, and a policy written twice. All five reach the server as plain text: the harness sends no format, and no case runs through extraction. Seven labeled questions, each with its answer pattern and source section, plus two unanswerable questions. The agent instruction gives filled-in citation examples and says to name a revision only with a number a tool returned. Existing cases and fixture tenants are unchanged, and memory-case scoring is identical to main: the extra abstention phrases ("does not specify/state", "not in the documents") are read for document cases only. The general summary line leaves document rows out; they get their own lines.
  • Citation check (check_doc_citations): it parses [source_uri § A > B, revision N] (a heading may hold a comma; a source_uri must hold a /) and checks each citation against the seeded server with the scorer's viewer token and no model. The document must be live in the person's namespace. A named section must be one of its headings (knowledge.outline, parents included). A named revision must be the live one (knowledge.get). The cited text (the section with its subsections, or the whole document) must match one of the labeled values. Rate-limited scorer reads are retried; any other failure stops the run instead of marking the answer wrong.
  • recall@k is measured on the direct path, knowledge.search with the question and the case's top_k. The model's own search results stay in LibreChat and are not scored.
  • server/operations/reach_manifest.py is regenerated: the harness now calls knowledge.search and knowledge.outline from integrations/.

Compatibility, rollout and rollback

  • Wire: none. Only MCP tool descriptions and the assistant primer text change.
  • Operator steps: none.
  • Rollback: a revert restores the old text; no stored data.

Tests

  • Unit tests (tests/unit/test_librechat_integration.py):
    • The labeled section of every document case exists in the fixture document as the server's chunker splits it, and states the labeled value; the revised document's earlier revision states the value the case forbids.
    • No fixture source_uri reads as a memory key.
    • Citation parsing, including revision unknown, a heading with a comma, and [1] or a source_uri without / as no citation.
    • The citation check, run on a fake server: live document, missing document, missing section, stale revision, unsupported text, parent section, and a document with no headings.
    • Native scoring ranks the labeled section, and a knowledge hit is never an abstention.
    • The document lines of the report.
    • Document abstention phrases leave memory-case scoring unchanged, and document rows stay out of the memory-key summary line.
    • rescore --citations on a saved document row merges its memory and document citations; seed writes the revised document after every first write, so its second revision is live.
    • The scorer waits out each 429 body the server sends (detail.retry_after_s, a detail with no hint, a string detail, a plain-text body).
  • tests/unit/test_mcp_assistant_toolset.py checks that the primer's new revision field is served.
  • Ran test_librechat_integration.py, the MCP listing and toolset tests, test_package_contracts.py, test_op_reach_census.py, test_public_copy.py, test_doc_links.py, test_tunable_constants.py and test_agent_instructions.py. Also ran make format, make lint (exit 0) and make typecheck. The full unit suite passes.
  • Eval: a local Loom with auth on, text-embedding-3-large, LOOM_LLM_PROVIDER=fake and workers off, and LibreChat v0.8.8 from integrations/librechat/docker-compose.yml, with claude-haiku-4-5-20251001. Only the document cases ran (qualify.py run --only <doc case ids>), on a fresh seed and a fresh LibreChat.
Metric (document cases) n LibreChat (model) Direct path (knowledge.search, no model)
Answerable questions correct 7 7/7 7/7 (top hit holds the value)
recall@1 / recall@5 of the labeled section 7 - 7/7 / 7/7
Document citations valid 8 cited 8/8 -
Labeled section cited 7 7/7 7/7
Citations naming a revision 8 cited 0/8 -
Unanswerable questions abstained 2 2/2, no false abstention 0/2 (the op has no abstain signal)
Latency p50 / p95 9 4.9 s / 6.4 s 0.32 s / 0.48 s
Tool calls 9 21 (at most 3 each) 9
Cost 9 $0.294 (281,385 prompt + 2,518 completion tokens at list price); embeddings under $0.01 embeddings only

These are from the second run, after the revision wording changed. The first run used the template [source_uri § section, revision N] and a primer that always asked for the revision. There, 7 of 8 citations were valid; the invalid one was a made-up revision 0. 5 of 8 citations ended in revision N or revision unknown. Unanswerable questions took 5 calls each, with a p95 of 11.3 s, and the run cost $0.388. Total provider spend over both runs was about $0.68. The memory cases were not run again; their scoring is unchanged and their published numbers stand. The corpus has five documents, so 7/7 at rank 1 shows the breadcrumbs reach the hits; it says nothing about retrieval at scale.

Findings, for follow-ups:

  • On main a knowledge.search hit carries no revision. In the second run no citation named one (the model called knowledge.get only on the unanswerable questions), so this PR delivers source and section citations, not revision citations. A per-hit revision and locator is the follow-up; the citation check already verifies a named revision against the live one.
  • knowledge.search has no abstain signal, so abstention comes only from the model.
  • On the text path, a TOML # comment line is a Markdown heading, so the TOML file's sections are its comments. A SQL or TOML file added as text gets no line or key locator.
  • The ingested-format case was not run. knowledge.ingest needs the extractor service, blob storage and the ingestion worker, and on main its hits carry the same breadcrumb as the text path.

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. The eval was run against a local server and LibreChat, and each citation the checker marked invalid was checked by hand against the saved answers.

  • 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).
  • A new migration is additive and numbered after the latest on main; no merged migration is edited.
  • A behaviour change to any file a plugin ships (hooks/, lib/, bin/, skills/, .mcp.json, the Codex plugin-defaults.json) bumps both plugin manifests' version, and no other open PR uses that version.
  • The frontend builds (npm --prefix frontend run build) and its tests pass, if frontend/ changed.
  • 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 and others added 2 commits November 4, 2026 10:17
…, and the LibreChat qualification measures it

The assistant primer and the knowledge.search and knowledge.get descriptions on the
assistant toolset name the citation a document answer carries (source_uri, the hit's
section breadcrumb, the revision knowledge.get returns) and tell the model that a hit is
the nearest passage, not an answer, since knowledge.search has no abstain signal.

The qualification harness gains a namespace of documents written through the text path
(Markdown, plain text, SQL, TOML, and a document with two revisions), labeled document
questions and two unanswerable ones. It measures the rank of the labeled section among
the direct path's knowledge.search hits, checks each document citation an answer writes
against the seeded server with no model (live document, existing section, live revision,
cited text states the labeled value), and reports abstention. The existing cases and
their scoring are unchanged; rescore --citations checks a saved run's citations again.

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

The assistant primer and the harness's agent instruction ask for a document's revision
only when a tool returned it, since a knowledge.search hit carries none; the instruction
gives filled-in examples instead of a template. The document abstention phrases apply to
document cases only, so the memory cases score as on main, and the summary line for memory
keys leaves the document rows out. The fixture documents carry no format field the
server never received. The citation parser accepts a heading with a comma, and a test
pins that a source_uri without a slash is no citation.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
@zlareb1 zlareb1 changed the title The assistant cites document passages by source, section and revision, and the qualification measures it The assistant cites document passages by source and section, and the qualification measures it Nov 4, 2026
zlareb1 and others added 3 commits November 4, 2026 10:48
Drops the sentences about a future locator field, says what the document abstention
phrases and the scorer token are read by, calls is_document_case where the op was
compared again, puts the memory summary loop under a plain if, pins only that a section
citation is read through knowledge.outline, and says the document cases need a server
on text-embedding-3-large seeded afresh.

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

retry_after reads `detail.retry_after_s` when the detail is an object (the rate limiter's
and the admission slots' body) and waits one second for any other 429 body: a detail
string, a plain-text answer, or a hint that is no number. The README gives the document
cases their own seed, setup and run on a text-embedding-3-large server, written to a
results file of their own that git ignores. Tests cover rescore --citations on a saved
document row and the order seed writes a document's revisions in.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
@zlareb1
zlareb1 merged commit 74fd0cc into main Nov 4, 2026
21 of 22 checks passed
@zlareb1
zlareb1 deleted the feat/i160-doc-ask branch November 4, 2026 11:24
@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