Repository navigation
namespace.tune drafts the chunk size and stride and an extractor route per format from a namespace's documents - #258
Merged
Merged
Conversation
zlareb1
force-pushed
the
feat/i160-doc-tune
branch
from
November 4, 2026 08:30
6ce8859 to
3c5b3af
Compare
…e per format from a namespace's documents A chunking draft rests on a bounded sample of the live documents cut again in process, by the chunker each one's write path uses, at the current values and at the proposed ones; an extractor route is drafted only for a format whose jobs failed format_unavailable or whose extractions lost structure, and only when another configured extractor declares it. Decision extraction takes no instructions, which `skipped` says. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…the sample in all A chunk size of 0 (one chunk per document) drafts no size, and says so, instead of dividing by zero; the document drafts are guarded like every other section, so a failure lands in `skipped`. The sample loads at most 8 MiB of text and artifact in all (`load_cap`), the SQL leaving out text past it; a document is cut from its artifact whenever it has one, in the SQL and the loader alike; the extractors' capabilities are read at once; the stride is clamped to the size once. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…oes to, media type included A failed source's service is read with its media type, so a media-type route is the service judged: sources it sends to a service that does not declare the format get a route for the format itself, which wins over a media-type route, and the limits say so. A chunk size of 0 or less is named as it is, with what it cuts; each candidate size is tried once, and a size already at the smallest says so; the population read is `documents.population`, apart from the section's own guard. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…nd routes it without moving a working source A format whose failed sources work now is still judged on its incomplete extractions. A route drafted for failed sources goes to a service some of them work on, else one the format's media-type routes reach, preferring one that did not make the incomplete extractions; when it is that service, `skipped` says the route answers the failures alone. The over-limit line names the chunk size in force, and a stride of 0 or less drafts nothing, as a size of 0 or less does. The analyzer case passes the module's caps. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…ces a format already works on The per-format coverage keeps the media types behind incomplete extractions apart from those behind complete ones, so a service that extracts a format whole counts as one its sources work on, not as one that lost structure. Failed sources and incomplete extractions share one ranking: a declaring service the format's sources work on, else one its media-type routes reach, else any, a service that did not make the incomplete extractions first. The route records the URL it picked. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
… for a format A failed source with no default URL and no route reads "no extractor is configured for it", and no service stands in the sources a route moves. The route keeps no URL field its output never reads; the tests cover the moved-sources sentence through the public output. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…rt from those routed When a format's failed sources split between a service that does not declare it and no service at all, the rationale names the service for its own sources and counts the rest as having no extractor configured. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
… names Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
zlareb1
force-pushed
the
feat/i160-doc-tune
branch
from
November 4, 2026 09:29
08a76f6 to
97f5600
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: #160
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):
namespace.tunenow drafts document settings: a chunk size and stride, checked by cutting a sample of the namespace's documents again at the current and proposed values, and an extractor route for each format whose ingests failed or lost structure. As with the other drafts, nothing is applied; each draft names the setting, the evidence and the platform-admin write that would apply it.Why
namespace.tunedrafted only the settings that create memories. A namespace's documents are cut byknowledge_chunk_size/knowledge_chunk_strideand extracted by the serviceLOOM_DOCUMENT_EXTRACTORS_JSONroutes each format to. Until now, finding out whether those values suited a namespace meant readingknowledge.inspectby hand and guessing. Tune now turns that evidence into a draft with a real target and the same approval contract.namespace_tune_document_samplelive documents (default 50, picked bycityHash64(source_uri), so the sample is spread out and repeatable) are cut again in process. Each document goes through the chunker its write path uses: a text document's text throughchunk_document, an ingested document's stored artifact throughchunk_artifact. Which one applies is decided by whether the row has a stored artifact (artifact_sha256), in both the SQL and the loader. The sample is cut at the current values and at each candidate. No model is called, nothing is written and no text is returned.chunkingreports chunk count, sizes (min, median, p90, max), sections,sections_cut, the largest embedding input in tokens and how many inputs are over the embedder's limit. A section counts as cut when the size splits it into more chunks than its structure alone makes, measured by cutting it again at an unbounded size, so a SQL statement that is its own chunk is not counted. There are two rules (version 1):knowledge_chunk_size0 or less, the chunkers cut no window: a text document is one chunk and an ingested one is a chunk per block. No size is drafted; the sample is still reported andskippednames the value. Aknowledge_chunk_strideof 0 or less is treated the same way. The chunkers handle it without looping (a section or block longer than the size is one chunk), but scaling it would draft a stride of 1.knowledge_chunk_sizeis at or below 200 and inputs are over the limit,skippednames the value in force.previewholds the before and after.applyissettings.set(POST /v1/admin/settings.set, platform admin) withexpected, andapply_alsosets the stride.format_unavailable, with the format read byformat_offrom the job's filename, media type andformatoption, and from incomplete extractions per format. The service a source goes to now is read withendpoint_for(format, media type), so a media-type route (application/pdf) is the service judged. Failed sources whose service declares the format now are told to ingest again. The rest get a route for the format itself, which wins over a media-type route, when a configured service declares the format inGET /v1/capabilities. One ranking picks the service for both kinds of evidence. Of the services that declare the format (for incomplete extractions alone, those that did not make them), it prefers one the format's sources already work on, meaning extracted whole or failed sources whose service declares it now; else one its media-type routes reach; else any. Within each tier, a service that did not make the incomplete extractions comes first. A route can still move sources that extract whole on another service, and its rationale names them. A route that does not answer the incomplete extractions says so inskipped. The draft names that service by the setting that holds its URL and never shows the URL, which can carry a credential, soargs_completeis false. The change takes effect at restart (via: environment). If no configured service declares the format,skippedsays so (extractor.<format>) and no route is drafted.loom decisions extractand the source sync's mining build their prompt from fixed text (dx.system_prompt). No request, namespace or org setting carries instructions for them, so there is no real target. Adding one would be a new extraction input on the memory write path, which belongs in its own change.skippedsays this whenever the namespace has documents.knowledge.inspectalready reports them with their remedy.Scope and risk
(org, namespace), the prefix of each table's sort key.loom.documentsandloom.knowledge_ingestionsare read withFINAL(both are ReplacingMergeTree). Parameters are bound. Each new section is guarded intoskipped.namespace_tune_document_sampledocuments.unread.load_cap), in sample order. The SQL leaves out text past that total with a running sum, and the loader counts artifacts against the same total. A document past it counts asunread.asyncio.gather), 5 s in all, and only when some format failed or lost structure.document_draftsis guarded like every other section: a failure goes toskippedasdocuments: <error>, never a 500. Its own population read is nameddocuments.population.scopesays so, and itslimitssay the evidence is this namespace's alone.knowledge.inspectjob read gains three columns per job (filename,content_type, theformatoption) to read the format from. Its output is unchanged.TuneApplynames a setting by its environment name,LOOM_KNOWLEDGE_CHUNK_SIZE, and derives thesettings.setfield from it (LOOM_<FIELD>). A bare field-name string would read totest_live_settings.pyas a read of a LIVE field that the test cannot follow. The values are read once per call and passed down, soexpectedis the value the draft was judged on.Compatibility, rollout and rollback
TuneTargetgainssettings.knowledge_chunkingandsettings.document_extractors_json.TuneApply.viais new (defaultop).TuneProposalgainsapply_alsoandpreview.TuneEvidencegainsdocuments.NamespaceTuneOutputgainschunking, with itsload_cap.ChunkStats,ChunkingPreview,ChunkingSample.namespace.tunep99 budget goes from 5000 to 8000 ms (comment updated).namespace_tune_document_sample(default 50, 1 to 1000), is available.Tests
tests/unit/test_namespace_tune_documents.py:unread.skippedand nothing is invented; a format the routed service declares now is not drafted.skippedwhen none does.knowledge_chunk_size0 (five artifact documents, two paragraphs per section) and at -5, nothing is drafted, the sample is still reported andskippednames the value. A size of 100, below the smallest drafted size, still drafts 400 and tries 200, 300 and 400 once each. Inputs over the limit at 200 and at 150 name the size in force. A stride of 0 and of -3 drafts nothing.skippedsays the route answers the failures alone. A route keeps the service the format's media-type route reaches.application/pdfsource is routed through a newpdfkey, and the source the default service takes is told to ingest again.tests/unit/test_namespace_tune.py: failing document drafts land inskipped, and the memory drafts stand.tests/unit/test_namespace_tune_documents_sql.py(clickhouse-local) covers each new statement:FINALand reads no artifact document's text. A row with aningestion_idand no artifact is read for its text, and the text read stops at the total.format_unavailablesources: replaced or later-published jobs are excluded, and each source carries its filename, media type and declared format.tests/integration/test_namespace_tune_documents.py, against a private server and ClickHouse:skippedsays why.Existing suites:
test_namespace_tune.pyand the integrationtest_namespace_tune.pypass.Gates:
make format,make lint(exit 0, also withLOOM_ENV_FILE=) andmake typecheckpass.-p randomly: settings, live settings, tunable constants, package contracts, op reach census, public copy, doc links, MCP listing budget, SDK surface, op budgets, knowledge inspect, extractors and embedding.pytest tests/analyzerpasses against a migrated private ClickHouse (0 rejected), andshapes.txtis regenerated.npm --prefix sdk/typescript run checkpasses.Cost on a 2,000-document namespace (26 MB of text, 1 to 6 sections each, plus 200 failed PDF jobs), with the fake embedder:
The largest single statement is the sample read (3,600 rows, 16.3 MiB, 18 ms). The 50 picked documents are spread across most granules, so their text is read from most of them.
Cutting the sample (667 chunks, token counting included) takes 8 ms at the current values and 15 ms for the four larger candidates.
The 50 sampled documents had 204 sections, all cut at 1500. With a known 8,191-token limit, the rule would draft 6000 (0 cut, largest input 1,500 tokens).
Worst case near the caps, in process, with a known 8,191-token limit so the whole ladder runs:
The extra RSS is on top of the loaded text. Without the total, the same samples load up to 100 M characters or 400 MiB.
To reproduce: seed
loom.documentswithnumbers(2000)rows, callPOST /v1/namespace.tune, and readsystem.query_logfor that call'slog_comment.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 checked the rules against the measured sample and the statements against clickhouse-local and a migrated server.
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 (format, lint, typecheck, the affected unit suites and the integration tests ran; the full unit suite is still to run); the integration suite passes if server behaviour changed.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).main; no merged migration is edited.hooks/,lib/,bin/,skills/,.mcp.json, the Codexplugin-defaults.json) bumps both plugin manifests' version, and no other open PR uses that version.npm --prefix frontend run build) and its tests pass, iffrontend/changed.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