Repository navigation
An ingested file's tables are typed datasets a writer can approve - #266
Merged
Merged
Conversation
Each table of a CSV or XLSX artifact becomes a typed dataset: a catalog row in loom.datasets and its rows in loom.dataset_rows (migration 083), a column's values in the typed slot its schema names. The ingest job writes them before the document row, which is the switch that serves them; older snapshots go by lightweight DELETE once it lands. knowledge.dataset_get reads a source's datasets, their schema, what needs an answer, the rows rejected and a sample; knowledge.dataset_approve approves a schema and retypes columns from the stored artifact under a new snapshot, checked under the source's claim. A metadata edit of an ingested document carries its datasets; deletes remove the datasets of the versions they retire. Erasure deletes both tables with the documents. Refs #157 Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
zlareb1
force-pushed
the
feat/datasets
branch
from
November 5, 2026 07:47
8aecf99 to
587196f
Compare
The public SDK surface snapshot gains client.knowledge.dataset_get and dataset_approve, and the delete tombstone test fakes the dataset cleanup the deletes now make, asserting each passes the version it read. 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]>
9 tasks done
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):
An ingested CSV or XLSX file's tables become typed datasets.
knowledge.dataset_getreturns each dataset's schema, what needs an answer, the rows rejected and its first rows, andknowledge.dataset_approveapproves a schema and retypes its columns.Why
The issue asks for spreadsheets to be queried as typed data, not only searched as passages. The extractor already returns each sheet as a table of typed values in the artifact. This PR stores those tables as typed snapshots with a schema a person can check and correct. A structured query over them (
knowledge.query) comes next and reads these tables. Parquet comes in its own change.Design
loom.datasetsis the catalog. It has one ReplacingMergeTree row per (source, dataset, document version), read withFINALand built bydataset_row, which carries every column. A row holds the schema (JSON: each column's name, type, inferred type and slot), the state (inferred,needs_clarification,approved), the clarifications, the rows stored and rejected (the first 20 with why),complete, the snapshot serving it and the identity tuple.loom.dataset_rowsholds the rows, in 72 typed slots: text and times ins1..s24, numbers and durations inn1..n24(Decimal128(9); the number columns past those inf1..f8,Float64), dates and date-times int1..t8, booleans inb1..b8. All of them areNullable, so a count or a null test is exact.(org, namespace, dataset_id, snapshot_id, row_id), and each row carries the identity tuple.past_capacity, naming the first such columns).mixedcolumn is held as text until a person types it.#DIV/0!in silence. That includes a number of 10^29 or more after rounding to nine places in annslot, one a double cannot hold in anfslot, and an instant outside 1900-2299 (whatDateTime64holds; a time zone is turned to UTC).completeonly when the extraction kept every value of its table: none of its rows, merges, values or cells failed, no shared string was lost, and the artifact lost none of the capabilities a value depends on (formula values, shared strings, number formats).<name> (2), and said (duplicate_name), since a column is addressed by its name; the artifact and its chunks are unaffected.knowledge.update_metadata) of an ingested source keeps its datasets: under the source's claim it writes each catalog row at the new version (the same snapshot) before the document row, and refuses with 409 when the source moved since it was read, 503 while another write holds the claim (both documented on the feature page; the op's budget now counts the claim and the carry). A carried snapshot's rows keep the version they were written at, so a delete keeps the rows of any snapshot a catalog row past its bound still serves, when the edit's carry landed before the delete read the catalog. A delete takes no claim: an edit whose carry lands between that read and the delete may revive the document over the delete (when its version is the later one), its chunks tombstoned and its datasets serving with their rows deleted: the race a claim-free delete already has with an edit, which a delete of the source settles. Making deletes take the claim would close both, at a claim per source for a bulk delete of up to 500; it is left for a change of its own. Build N-1's metadata edit carries nothing; rule 29 says its datasets stop being served until the file is ingested again.knowledge.dataset_approve(writer, audited, experimental) names the snapshot the caller reviewed, plus the types to change.ingest_run.claim_source) it checks that the document and the snapshot are unchanged, stamps the catalog row's version there (past the row it replaces, so an approval written while it typed cannot outrank it), writes it and deletes the replaced snapshot's rows.409 PRECONDITION_FAILED(read it again); a deleted source isfound: false. Another approval that kept the snapshot is overwritten by this one.actorandapproved_byname the approver and itssource_classisasserted; the rows stay the uploader's (user_idand their ownsource_class), as a user erasure finds them; a retype takes them from the live document row the ingest wrote (re-checked under the claim), since the catalog row may be an earlier approver's write.knowledge.dataset_get(viewer, experimental) reads the live document and its version's catalog rows in the artifact's order. Withsample_rows(up to 50) it reads the first rows of the first 20 datasets in one statement, each snapshot a range of the key (row_idunder the rows asked for plus the rejected rows below them: the catalog row names the first 20 rejected rows in row order, so the bound is exact unless it reaches past the last of them, and only then is every unnamed one counted), andloom.dataset_rowskeeps granules of 1,024 rows, so the read takes the granules holding them, not the tables (system.query_log): 3,672 rows read for 3 datasets of 100,000 rows each, against 215,960 for a plainLIMIT n BYread; 38,912 rows and 20 ms for 20 datasets of 1,000 rows. AUNION ALLbranch per snapshot read as little but cost about 3 ms of planning a branch. An integer past 2^53, or a fraction a double cannot hold, is returned as text.DELETE FROMwithlightweight_deletes_sync = 0. Nothing reads a snapshot once no catalog row serves it, so no request waits on a delete.knowledge.deleteandknowledge.bulk_deletedelete the datasets of the document versions they retire, up to each source's latest row as read before the delete, superseded or not. A delete takes no claim, so it can land between a first ingest's batches; an ingest running meanwhile writes a later version, which the delete leaves whole, so the dataset it serves holds every row it counts. A delete of a source already deleted still deletes what is left of its retired versions (an approval's snapshot landing as the first delete ran, or one build N-1 left).ALTERmutation.documents.tombstonewith the ingestion tables, by namespace and by user (the rows carry the uploader'suser_id), and both have census rows.docs/architecture/rolling-upgrades.md(rule 29) says to request those erasures again once N-1 stops serving.Alternatives considered:
Tests
tests/unit/test_knowledge_datasets.py):fslots and past capacity; each clarification; overrides; stable ids, a sheet holding two tables; approval carry-over; every failed unit and lost capability that makes a table incomplete;fvalue past a double, instants outside 1900-2299; batches; slot rows; a fraction returned as text;dataset_getanddataset_approveover faked stores: approval without a retype keeps the snapshot; a retype makes a new one from the stored artifact; the approver as the catalog row's actor and source class while a retype's rows keep the uploader's; an unknown column; a stale snapshot; an approval overtaken by another approval or by a new revision; a retype refused or cut off at the claim; an approval stamped before another that switched first; a catalog insert that may have landed; every sample in one read.tests/unit/test_knowledge_ingest.py): a CSV ingest writes its dataset before the document row with the job's identity; a new revision keeps an approval of the same columns and drops the old snapshot; a metadata edit keeps serving the datasets and their approval, waits for the claim, and is refused when another write landed while it waited; other columns are inferred again; a failed publish deletes its own datasets; a publish that fails between a table's batches deletes the rows it wrote; an erasure between batches stops the rest; a delete between a first ingest's batches leaves its rows whole; a delete of a deleted source clears a snapshot left behind; an approval landing mid-publish runs the job again, uncounted, and the next run carries it.tests/unit/test_knowledge_shared_blob.py):knowledge.deleteandknowledge.bulk_deletedelete the datasets of each source's retired version; a bulk delete of sources already deleted still deletes what is left of theirs.tests/integration/test_knowledge_ingest_live.py) against a real server, ClickHouse and extractor: ingest a CSV, read the stored rows back, refuse a stale approval, retype a column (one rejected row), read the new snapshot, delete, and see both tables' rows go; a bulk delete of two sources at different document versions removes both, and keeps the rows of a running ingest of one of them at a version between the two (a single bound for both would take them); a delete bounded before a metadata edit keeps the rows of the snapshot the edit carried; a two-sheet workbook with a cell error is sampled in one read, each sheet cut to the rows asked for and read past its rejected row. Eleven tests passed against a server running the head; the leakage suites passed (42 passed, 17 skipped).datasets.publishof 100,000 rows × 12 columns took 6.0 s with a 167 MB peak RSS (resource.getrusage); the sample read's rows read are fromsystem.query_logafterSYSTEM FLUSH LOGS.🤖 Generated with Claude Code