Repository navigation
knowledge.search cites each hit's revision and locator, filters by format and block type, and finds exact keys - #252
Merged
Conversation
zlareb1
force-pushed
the
feat/knowledge-structural-search
branch
8 times, most recently
from
November 4, 2026 12:22
5626f11 to
425322f
Compare
…by format and block type, and finds exact keys Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
… only for identifier-shaped terms Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…ch write binds its revision once Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…le; a cold corpus test Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…on tests skip without an extractor 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]>
…unk lookup in synthesize 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]>
…hunk's depth comes with its section path Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…n one scale Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…es its revision 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]>
Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…nd a revision of 0 is cited as none Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
… description's sentence Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…unk records Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
zlareb1
force-pushed
the
feat/knowledge-structural-search
branch
from
November 4, 2026 13:26
63b9a90 to
9bf8f1f
Compare
8 of 9 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Related: #157
Changelog category (leave one):
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.searchhits name the document revision and format they came from and, for an ingested file, the block type and locator (lines, key path) of the passage. Newformatsandblock_typesfilters narrow a search, and an exact-key leg finds the chunk that defines or reads an identifier (events,server.port).knowledge.synthesizelists each cited chunk with its revision and locator.Why
Ingestion (#229) publishes extracted files as revisions whose chunks carry a locator, a block type and the exact names their blocks define or read (
keys), but search did not read any of it: a hit could not say which revision it cited or where in the file it sits, a caller could not ask for SQL statements only, and an identifier such asorders_dailyread to BM25 likedaily_orders(the same tokens). This makes search use what extraction records.Scope and risk
What a chunk records (
server/knowledge/store/chunks.py): every chunk row'schunk_metadatanow also holds the document revision it is written as and the document's format, so a hit names the revision its own text belongs to, not whichever revision is live when it is read (during a publish the new version's chunks are live before its document row). Text writes record their revision (bound once per write, for the document row and every chunk row) and""; an ingest decides its revision before it inserts the chunks (ingest_run._publish), and under the source's claim refuses the publish (revision_conflict, the chunks retired) when the source has changed since (_check_unchanged: any other write moves its latest version) or its latest row would outrank this one. One reader parses the metadata for search, synthesis and the outline (server/knowledge/domain/chunk_metadata.py).Hits (
server/knowledge/app/search.py,knowledge_search.py): each leg reads the chunk's section path, revision, format, block type and locator. No document row is read.Filters:
formatsandblock_typesareJSONExtractString(chunk_metadata, ...) IN ...on every leg, inside the sort-key prefix the leg already reads. Text a caller extracted has no block type, so anyblock_typesentry leaves it out; its format is"", whichformatscan name.Exact-key leg (
keys_search, hybrid mode only): the query's identifier-shaped terms (server/knowledge/domain/exact_keys.py) againsthasAny(keys, ...)with thekeysbloom-filter index; the chunks matching the most keys first, then by distance. Its ranks join reciprocal-rank fusion as a third term (fuse_rrf(..., keyed=)), and a hit from it reportskeys_matched. A term counts when it cannot be a plain word (an underscore, a dot, a$or a digit, or a capital after a lowercase letter, souserIdcounts and the acronymsIDandTTLdo not), or when it is the whole query; a dash joins the segments of a dotted path (pool.max-size, a TOML bare key) and nothing else. Keys are stored as their source spells them and each term is looked up as written and lowercased, soEventsalso findseventsbut not the reverse. Why plain words are out: SQL chunk keys include column names, and with every word a candidate a prose question'sstatusornamepulled the SQL statements above the document that answers (measured below). A hybrid query with no BM25 token (id,db.ts) still runs the leg, fused with the vector leg. A hybrid search now returns fused scores whenever the lexical or exact-key leg ran, even when it found nothing: the passes of a private-first fan-out are sorted together, and a pass of raw similarities (about 0.1-0.3) beside a fused pass (about 0.016-0.05) used to put every public vector hit above a private exact-key hit. Semantic and lexical modes are unchanged.Synthesize:
cited_chunkslists each chunk the kept citations name (a range expands over the chunks read), with the revision and locator its chunk recorded when it was read. Citation grounding is unchanged.Outline: it reads the section path each chunk records (which the structural chunker writes) through the same reader now, with its depth and the text-only fields (
section_idx,char_start), so the outline, search and synthesis agree on a chunk's section; an empty heading is no path segment in any of them.No new table, column, setting or migration.
Architecture page:
docs/architecture/document-extraction.mdsays each chunk records its revision and format, and gives the publish order as it now is.Agent-facing wording: the assistant toolset's
knowledge.searchdescription, the assistant primer,docs/reference/mcp.mdand the LibreChat integration page now say a hit carries therevisionits passage was written as (and an ingested file's hit itslocator), and that a citation names it, citing none for a revision of 0 (a chunk written before revisions were recorded); they said the revision came fromknowledge.get, which returns the live one. The core toolset'sknowledge.searchdescription names the exact-key leg, the new hit fields and the two filters.Compatibility, rollout and rollback
knowledge.searchgains input fieldsformatsandblock_types(both default empty) and output fieldsrevision,format,block_type,locator,keys_matchedper hit;knowledge.synthesizegainscited_chunks. No field is removed or changed.revisionandformatkeys. A chunk written before (or by build N-1 during a rollout) records neither and reads revision 0 and format""(so aformatsfilter namingsqlleaves it out) until its document is written again; nothing is backfilled.Tests
Unit
tests/unit/test_knowledge_structural_search.py(13): the query's candidate keys (identifiers kept, plain words and acronyms dropped unless the whole query, a dashed TOML path kept whole and prose dashes not); the exact-key leg's statement and the structure it reads; a keyed hit's fusion term and keys; the two filters on all three legs; the handler fusing the keys leg, a semantic search running none, a query with no BM25 token still running it, and a cold corpus (no lexical hit) fusing the vector and exact-key legs; a private-first fan-out whose private pass has a keyed hit and whose public pass has vector hits only, for a query with no BM25 token and one with tokens, the keyed hit level with the public pass's first hit rather than under all of them; the metadata reader (with the outline's text fields); cited chunks expanding ranges; synthesize listing each cited chunk's revision and locator.tests/unit/test_knowledge_chunk_rows.py:add,upsertandbulk_addeach record on every chunk the revision their document row takes (5 over a source at 4) and format"".tests/unit/test_knowledge_ingest.py: each published chunk records its revision and format; a write between the revision decision and the claim fails the publish and retires its chunks. The lexical tests stub the new leg where they stub the others.Integration
tests/integration/test_knowledge_structural_search.py(3), against a server built from this branch, a migrated ClickHouse and the reference extractor run as a service: a SQL file and a TOML file ingested;sessionsandserver.porteach find the defining chunk first, with its keys, locator, block type, format and revision 1;formats=["sql"],formats=[""]andblock_types=["sql_statement"]keep only those chunks. A prose question over a SQL file whose columns are common words and a document that answers it finds the document first, with no keys matched (the regression the comparison below found, pinned).test_knowledge_ingest_live.pypasses with the new chunk metadata.pytest tests/unit -k "knowledge or mcp or search or sdk or docs_reference or reach or synth or corpus or package_contracts or alias or tunable or inventory or public_copy or doc_links"andpytest tests/integration -k "knowledge or document or ingest or search or synth": 4,474 passed, and 149 passed, 58 skipped (settings this server does not set).Retrieval comparison over the store functions (the fake n-gram embedder; the current fusion is vector + BM25):
orders_daily/daily_orders, ...)status,name,value), every word a key candidateThe leg puts the defining statement first where an identifier's words are shared, and changes nothing for prose once plain words are not candidates. The harness is a local script over the store functions (it fuses with and without the leg, which no shipped path does), so it is not committed; the corpora are as described, and the prose case is pinned by the integration test above.
The exact-key leg's cost, from
system.query_logon a local ClickHouse: one namespace of 20,000 SQL statement chunks (3072-dim vectors), every one keyedstatus, among 200,000 chunks in 20 other namespaces of the org;top_k10, three runs each.status(all 20,000 match)t123(one match)The worst case (a key every chunk of the namespace holds) stays inside the namespace's primary-key range and costs about what the vector leg already does; a selective key reads a tenth of it, since the
keysbloom index skips the granules without it.make format,make lint(generators current),make typecheck: pass.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 typecheckandmake test-unitpass; the integration suite passes if server behaviour changed. (The full unit suite passed locally at 63b9a90, before the last doc-only commit: 26,844 passed, 18 skipped, 1 xfailed; the knowledge integration tests pass.)docs/reference/configuration.mdand thedocs/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/describe the system as it now is, and this description names any operator steps and wire changes.tests/unit/test_public_copy.py).git commit -s), as CONTRIBUTING.md asks.🤖 Generated with Claude Code