Repository navigation
OSS-162: send several files in one ingest request (20 files / 10 MiB per request) - #61
adityamishra-hydradb wants to merge 2 commits into
Conversation
hydradb ingest <files> sent one request per file. It now groups files into requests of at most 20 files and 10 MiB (the free plan's per-request byte cap; the API takes 50 MiB per file and 1000 items per request) and maps the API's per-file results back to each row by id. A 4xx on a batch resends its files one at a time to find the refused one; a 5xx fails the batch's files without a resend. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: adityamishra-hydradb <[email protected]>
|
@hydra-mira-review review |
|
/devin review |
Mira score 5/5 · 🟢 Good to merge
File ingestion sends multiple files per request to reduce upload time while preserving separate results for each file. Requests hold up to 20 files and 10 MiB, with oversized files sent alone. Eligible client errors trigger individual retries; server errors fail the batch without retries, while authentication, rate limit, and network errors stop ingestion. Before this ships · 2 to confirm, 1 in place
How this PR works · 5 changes, 1 high risk, 3 medium risk, 1 low riskUploading many small files currently waits for one request per file. This PR groups files into requests containing at most 20 files and 10 MiB, while sending larger files alone. It preserves per-file results and separates safe retries after request rejection from unknown outcomes after server errors. 1. Accept multiple files in one ingest call · 🟠 medium risk ·
|
- The content-type probe runs inside the per-file read handler, so a read error skips that file only. - Files of a multi-file batch are read before the request (bounded by the 10 MiB batch cap); a file sent alone is still streamed. - Each API result is used once: by id first, then the leftover results by position only when as many are left as files. A file with no result fails. An answer with no results list reads as queued, as before. - The e2e simulator answers a file upload with one result per file. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: adityamishra-hydradb <[email protected]>
|
@hydra-mira-review review |
|
/devin review |
For humans
hydradb ingest <files>sent one request per file and waited for each answer before it sent the next file. 30 small files took about 16 s. One request with the same 30 files takes about 1.5 s.This PR sends several files in one request:
resultsto the files by id.Why 20 files and 10 MiB:
DefaultMultipartFileSizeLimitBytesmaxMultipartRequestBytesingestion_itemsknowledge_bytes10 MiB fits every plan. 20 files keeps a request short, so the progress line moves and a refused request is quick to resend one file at a time.
Fixes OSS-162.
For agents
src/hydradb_cli/commands/_impl.py_upload_batches(planned): groups planned files in order; new batch when 20 files or adding the file would pass 10 MiB (size fromstat)._upload_batch(...): reads each file of a multi-file batch into memory (bounded by 10 MiB) and probes its content type inside the per-fileOSErrorhandler, so a read error skips that file only; a file sent alone is streamed. Sends onecontext.ingestwithdocuments=[(label, content, ctype), ...]and adocument_metadataarray in the same order._match_results(...): each API result is used once, byidfirst (the CLI sends the id), then the leftover results by position only when as many results as files are left. A file with no result fails ("the API's answer has no result for this file"). An answer with noresultslist reads as queued, as a one-file upload did before.handle_api_error(unchanged); other 4xx on a batch of more than one file -> resend each file alone (recursive, batch of one); 5xx -> every file of the batchfailed, no resend.do_ingest_knowledge_files: loops over batches;action(new/updated) is set after all batches.src/hydradb_cli/hydra/client.py:context.ingest(documents=)takes one file or a list; docstring updated. The SDK'sdocumentsisList[File]on 2.1.7 and 2.1.8.tests/test_cli_commands.py::TestFileIngest(batching, byte cap, results by id, one result per file, fewer results than files, 5xx, 4xx resend, read error and content-type probe error at send time);tests/e2e/sim/test_simulated.py::test_file_ingest_sends_accepted_keysnow checks one multipart request with both files through the real SDK. The e2e simulator (tests/e2e/sim/simulator.py) answers a file upload with one result per file, as the API does.Proof
A = base
main@5a5842d· B = this PR @398e2d7. Both installed from wheels built at those commits, in clean venvs (Python 3.12,hydradb-sdk2.1.7). Run 2026-12-04 22:49-22:53 UTC. Raw output:~/hydradb/dogfood/sdk/proof/oss-162/(timing.txt+timing/*.json,edge.txt+edge/*.json,mock_requests.txt,mock_bytecap_*.txt,tests.txt).1. A/B on the real repro: 30 small files, prod
Own database
dogfood-fix-oss-162in our test org (deleted after). Command:time hydradb -o json ingest n*.txt(30 files, about 45 bytes each), a new collection per run. Runs alternate A, B.queuedqueuedfile,id,status,action,error)B is about 6x faster. B's time includes the "already stored?" lookup (one
/context/listrequest), which A also makes.2. Requests sent (local mock server,
repro/mock.py)POST /context/ingestPOST /context/ingest3. Regression
Full suite,
pytest -q:B adds 10 tests and changes 4 (the file ingest fakes now take a list of files; two tests that counted one request per file now count batches).
ruff check .andruff format --check .pass. CI on B is green (test (3.10-3.13),lint,live,dco-check).Unchanged behavior, prod, same mixed set on A and B (
edge.txt): 21 Markdown files, a random binaryblob.bin, an empty file, a missing file,Dockerfile(no extension), anddocs/e01.mdlisted twice.blob.bin(API refuses it inresults)Dockerfile(sent astext/plain)updatede01updated,e02new (*)--no-upsert(*) B ran the second command about 1 s after the first, and A about 15 s after. The new/updated label comes from the
/context/listlookup, which had not listede02yet. Run again at 22:51:40Z, B reports bothupdated(edge/edge-B-2b.json). The label logic is unchanged by this PR.4. Smoke
Section 1 (B column) and section 3 are the smoke runs on prod: plain files, Markdown in a folder, an extensionless file, re-ingest with upsert, and
--no-upsert.5. Stress: the byte cap (local mock, bounded)
Files: three of 4 MiB, one of 12 MiB, two tiny. Request body sizes sent to
POST /context/ingest:B never puts more than 10 MiB of files in one request; the 12 MiB file goes alone. No load test on prod: the only prod runs are the bounded ones above (30 files per run).
6. Edge cases the change targets (unit tests, B)
test_files_are_sent_in_batches_of_at_most_20test_a_batch_stays_under_the_byte_captest_results_are_matched_by_id_not_positiontest_a_result_is_used_once_and_an_unmatched_file_failstest_fewer_results_than_files_fails_the_files_without_oneresultslist: queued, as beforetest_an_answer_without_results_reads_as_queuedtest_a_4xx_batch_is_resent_one_file_at_a_time,test_an_api_error_on_one_file_does_not_stop_the_batchtest_a_5xx_fails_its_batch_without_a_resend_and_the_next_batch_goes_ontest_an_auth_error_stops_the_batchtest_a_read_error_at_send_time_skips_only_that_filetest_a_content_type_probe_error_skips_only_that_filetest_file_ingest_sends_accepted_keys(e2e sim)Not run on prod: a whole-request 4xx (it needs a request the API refuses as a whole, such as a file over the plan's byte cap). That path is covered by the unit tests above.
🤖 Generated with Claude Code