Skip to content

The ingest CLI and the Python SDK upload files for the server's extractor to parse - #280

Merged
zlareb1 merged 11 commits into
mainfrom
feat/ingest-uploads-sdk
Nov 6, 2026
Merged

zlareb1 merged 11 commits into
mainfrom
feat/ingest-uploads-sdk

Conversation

@zlareb1

@zlareb1 zlareb1 commented Nov 6, 2026 •

Copy link
Copy Markdown
Member

Related: #157

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

dev/loom_ingest.py uploads a file's bytes and ingests them with knowledge.ingest, so the server's extractor parses every format and the CLI waits for the job and prints the revision it published; its --upsert flag is removed (every ingest publishes the source's next revision). loom demo ingests its file the same way. The Python SDK gains knowledge.upload, ingest, ingest_status, ingest_cancel, wait_for_ingest and ingest_file.

Why

The issue's plan moves every client onto the upload and ingest path: originals are uploaded as they are, "extraction runs in a separate sandboxed service", and client-side extraction is removed. The ingest CLI still parsed PDFs with pypdf and HTML with trafilatura on the operator's machine and posted the text through knowledge.add, so a file it ingested had no original, no revision from an extraction, no locators and none of the extractor's coverage or warnings. loom demo loaded that script to reuse its parse step and posted the text to knowledge.upsert. The Python SDK had no way to send a file: a caller wrote the two HTTP steps by hand.

Design

  • SDK (sdk/python/loom/knowledge.py):
    • upload(data, filename, content_type=) posts the raw bytes to /v1/knowledge.upload with their sha256.
    • ingest(upload_id, source_uri=, ...) takes knowledge.ingest's fields.
    • ingest_status and ingest_cancel wrap the two ops.
    • wait_for_ingest(ingestion_id, timeout_s=600, poll_s=1) polls until the job is ready, partial, failed or cancelled. Past the timeout it raises TimeoutError, naming the state the job is still in.
    • ingest_file(path, wait=True, ...) runs all three for a local file. It reads the file off the event loop, and names the document as the CLI does: file://<absolute path>, titled by the file's name less its extension.
    • Transport.request gains a content argument, sent as application/octet-stream. The upload route is outside the op registry. A request there is still not retried, but a 429 (which the server answers before doing anything: an upload it refuses stores nothing) is now resent after the server's Retry-After within ratelimit_max_wait_s, as an op is. The old CLI path had that pacing through knowledge.add, so a run over an S3 prefix keeps it. The wait is one helper (_rate_limit_wait) the op path and request share.
    • The sync agent wraps the new methods as it wraps the rest.
  • CLI (dev/loom_ingest.py):
    • What is fetched: a local path, an S3 object or every object under a prefix, or a URL, as before. It is fetched as bytes and uploaded under its file name, which names the format. A URL is named by its path's last segment, unescaped (index for none, never the host), and for a name with no extension the response's media type names the format.
    • Waiting: the CLI then ingests and waits, printing the revision, chunks, format and the extractor's warnings, or the job's error_code and message.
    • New flags: --no-wait, --timeout, --format (the ingest option) and --allow-partial.
    • Failures: a failed or cancelled job, a refused call, or an object that cannot be fetched is counted, and the rest still ingest (exit 1). An S3 object is read with get_object, so an object with no extension (listed under a prefix: a key with no extension is one) is named by its stored media type, as a URL is.
    • --dry-run prints the file's size, its sha256 and the ingest fields.
    • Removed: the PDF, HTML and text extraction, and --upsert.
  • loom demo (server/cli/demo.py): it uploads AGENTS.md (or --file) through a new raw-body seam (server/cli/_client.py::post_bytes), ingests it with the same fields the CLI sends (ingested_from included), and polls knowledge.ingest_status for up to two minutes (it stops at once for a job the server cannot find). It prints the revision, chunks and format, or why the job failed: a format_unavailable failure points at loom up and its reference extractor, and a job still pending names the worker that runs it. It no longer loads dev/loom_ingest.py, so it needs only AGENTS.md. --root now names where that file is (the cwd, then the package's checkout, by default).
  • Dependencies: the ingest extra keeps only boto3 (the S3 fetch). pypdf and trafilatura leave it, and uv.lock loses trafilatura and the packages only it needed (removals only: the lock keeps main's revision, and uv lock --check passes with the uv CI pins); the extractor service still declares its own parsers.
  • Docs:
    • The quickstart says loom demo uploads and ingests its file. The ingest CLI section of docs/features/knowledge.md now says the CLI uploads what it is given and parses nothing. A paragraph on the SDK helpers follows the ingest steps.
    • The overview's "when not to use Loom" row on in-server parsing is removed, since it no longer holds.
    • The ingest extra's row in the local-development page is updated.
  • The reach manifest names the SDK as a caller of the three ingest ops.

Alternatives considered:

  • Keeping client-side extraction as a fallback when no extractor is configured. That is two extraction paths with different chunking, locators and coverage, which the issue rules out.
  • An ingest command on the shipped loom CLI. That is a new command surface; the dev script is what make ingest and the docs already name.

Scope and risk

  • Clients only (the dev CLI, loom demo and the Python SDK): no op, table, migration or setting changes.
  • A format no extractor serves now fails. On a deployment with no extractor configured, every file the CLI or loom demo sends fails format_unavailable, where the old path posted the text it parsed; both print the code. A text file posted with knowledge.add still works without one. loom demo also needs the ingest worker running, which the stock stack runs.
  • Operator-visible change: --upsert is gone, and the operator sees an argparse error if they pass it. Every ingest publishes the next revision of the source, which is what --upsert did.

Compatibility, rollout and rollback

  • Server versions: the SDK helpers call /v1/knowledge.upload and the ingest ops, which a server must serve. Against an older server they get a 404, which the SDK raises as NotFoundError.
  • Wire: none changes.
  • Operator steps: none; pip install '.[ingest]' still brings boto3 for S3 sources.
  • Rollback: reverting restores the client-side parse.

Tests

  • Unit, tests/unit/test_sdk_knowledge_ingest.py (9 tests):
    • the upload sends the bytes unchanged, with their sha256, the octet-stream type and the bearer;
    • an upload a 429 refused is sent again after its hint, and past the pacing budget it raises RateLimited;
    • wait_for_ingest returns at once for a job the server cannot find;
    • ingest sends every field;
    • wait_for_ingest polls until the job ends and times out with the state the job is still in;
    • ingest_file names the document by its path, or by source_uri, titles it by the file's stem, and waits or not;
    • the sync agent ingests a file and cancels.
  • Unit, tests/unit/test_loom_ingest.py, rewritten (28 tests):
    • a local file is uploaded as its bytes and ingested with its tags, title and metadata;
    • --source-uri, --title, --format and --allow-partial reach the ingest;
    • --no-wait polls nothing;
    • a failed job is reported with its code and fails the run, a job still running past --timeout fails it, a job the server cannot find is reported as not found, and a partial one counts as ingested;
    • an S3 object, every object under a prefix, an empty prefix and a bucket with no key (a dot in its name included);
    • the single-document flags are refused for a prefix;
    • a refused ingest, or an object that cannot be fetched, is counted and the rest still ingest;
    • a URL is uploaded with its media type and path name, an escaped name is uploaded unescaped, a URL with no path is named index, and an oversize URL is refused;
    • --dry-run sends nothing;
    • the identity comes from the token's claims.
  • Unit, tests/unit/test_cli_demo.py, rewritten for the new path (20 tests, the ingest body's ingested_from checked):
    • the demo uploads the file's bytes, ingests it and polls the job until it ends, then searches it;
    • a failed job names its code and the extractor, and a job the server cannot find stops at once;
    • a job that never ends names the worker;
    • a refused upload ingests nothing;
    • a missing AGENTS.md under --root is reported, and a relative --file is named by its absolute path, as the CLI names it;
    • the raw-body seam turns every answer into a status and an object.
  • Unit, updated: the SDK public-API snapshot; the CLI help and argument-tree snapshots (the --root and --file help).
  • Integration, tests/integration/test_ingest_clients_live.py: run against a server, its ClickHouse and the reference extractor, with the worker pass in the test process.
    • ingest_file publishes a Markdown file. wait_for_ingest returns it ready at revision 1, and knowledge.get serves that revision with its tags.
    • The CLI waits and prints revision 1, then revision 2 on a second run.
    • --no-wait prints the job.
    • The document keeps the title the CLI gave it, and the CLI records where its bytes came from (ingested_from).
    • loom demo uploads its file, waits for the job and finds the passage it asked about.
    • The structural-search integration tests pass alongside (6 in all).
  • Full unit suite: run on the rebased head before the merge.

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. Checked: the SDK, the CLI and loom demo end to end against a real server, ClickHouse and extractor; the failure paths in the unit tests above; and a review at every push.

  • 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 11 commits November 6, 2026 01:03
…ctor to parse

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

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…ords where its bytes came from

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

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

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]>
…e the demo resolves

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]>
@zlareb1
zlareb1 merged commit 513fc87 into main Nov 6, 2026
22 of 24 checks passed
@zlareb1
zlareb1 deleted the feat/ingest-uploads-sdk branch November 6, 2026 02:57
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