The lever I finally pulled: raggio's ingest, 2.3x faster and still durable

Table of Contents
The first post ended its ingest section with a line I was rather proud of: “batching those syncs is a known lever I haven’t pulled, because durability was the point.” This part is about pulling it without giving up the point, and about everything the agents found in the ingest path before they even got to the lever.
Forty milliseconds to change one word
The first post explained how ingest stays durable: you POST documents, raggio writes the payload to its SQLite journal before answering 202 Accepted, and a worker per collection picks the jobs up and indexes them. The journal stored each payload as JSON, and a job of 250 vectors with 1,024 dimensions is a 2.7 MB string. On my desktop, encoding it took 74 to 124 ms, and decoding it 41 to 68 ms, on the event loop. Claiming a job, which flips its status from pending to processing, rewrote the whole 2.7 MB row: SQLite stores a row that big across a chain of overflow pages, and since the two words have different lengths, the row changes size and gets written again. 40 to 66 ms to change one word. Then the rows were upserted one by one.
On the DGX, during an ingest the event loop stalled for 5.5 to 8.3 seconds per probe run. And since the event loop serves every collection, searches on a different collection stalled with it: a p99 of 307 ms while another collection was ingesting, against 10.5 ms when it was quiet. Same disease as part 2, heavy work on the only thread that answers requests, in another organ.
Off the loop
The first half of plan D moved the payload into its own table as binary, so claiming a job flips a tiny row. Encoding and decoding moved to a worker thread, the upserts became set-based, and the vacuum that hands free pages back now waits until the queue is idle. The event loop stopped stalling: zero on flat, at most 0.19 seconds on IVF. Ingest on flat went from 2,342 to 4,982 vectors per second in the probe, and the full reingest of 2.55 million vectors from 28 minutes to 14. Searches on the other collection went from a p99 of 307 ms to 121.
And then the IVF gate failed.
Every run won, and the gate still failed
The six runs are the IVF probe of D1’s A/B on the DGX (nlist 256, vectors per second). The rule was fixed before the run: the gain between the medians has to be wider than the band, the larger of the two arms’ ranges. Drag the slider to change the fastest candidate run and watch the verdict. The real run was 710.4.
The rule for a performance claim was written before any data, on purpose: take the median of each arm, and the gain counts only if it’s wider than the noise band, the larger of the two arms’ ranges (max minus min). On the IVF probe, the old code ran 505.0, 533.5 and 535.2 vectors per second, and the new code 611.7, 612.0 and 710.4. Gain at the medians: 78.5. But that third run was unusually fast, so the new code’s range, and with it the band, was 98.7. Gain inside the band: FAIL.
Except that the slowest new run beat the fastest old run by 76.5. If the two arms really were the same, the chance of all three new runs landing above all three old runs is 1 in 20. The rule can’t tell a lucky run from noise, and here a faster run is literally what sank the claim. Play with the slider: any third run above 690 vectors per second fails the gate.
The plan forbade both easy ways out: loosening the gate after seeing the data, and rerunning until it passes. The agents did neither, and the result came to me as a FAIL. I overrode it the next day. The decision record keeps the FAIL line, with the override written under it and the reason, and a test fails if anyone turns that FAIL into a PASS or deletes the override.
Was the rule dumb in this case? Yes. But a dumb rule I override in public beats a smart rule I can bend in private.
The lever I didn’t pull
The sync is the moment the index file gets written to disk, and raggio did it after every job, before marking the job done. On IVF that means writing every shard the job touched, and 250 random rows land in about 160 of the 256 shards, so every job rewrote most of the index.
The second half of plan D pulled the lever without giving up the point. One sync now covers a batch of up to 8 jobs, or whatever arrived within a second. The durability contract stays: a job stays processing until the sync that covers it returns, and only then becomes done. If the container dies before that, every job in the batch is still in the journal and gets replayed on boot, and since every record is upserted by id, replaying twice still leaves one copy. Along the way the plan also fixed a real bug: a sync that failed used to mark its job as error, a final state that never replays, with the job’s rows committed to SQLite and missing from the index file. Now a failed sync is retried, with backoff.
Eight jobs in schematic time: a job’s work is one unit and an IVF sync about two and a half, which is the measured ratio. Switch the sync rule, then pull the plug: a job becomes done only after the sync that covers it, so whatever the crash interrupts is still in the journal and replays on boot.
The batch size and the time limit were tuned on one random seed and published on another, as part 1’s rules say. On the IVF probe, ingest went from 852 to 2,235 vectors per second, 2.6x. On flat it moved 7%, inside the band, because after the first half a sync was only about 15% of a flat job. Across the whole program, IVF ingest in that probe went from 534 to 2,235 vectors per second, 4.2x.
Testing the tests
The second half’s pre-flight went one step further than reading the plan: it tested the tests. The plan listed what a reviewer had to check, so the pre-flight broke the code on purpose, one claim at a time, and ran the tests against each broken copy. Three broken copies passed every test: a >= where the plan says >, a retry that swallowed cancellations, and a failed sync that reset a counter it should have kept. Each one got a test that fails on it.
Then the final review on Opus suggested a fix for one of those tests, which hung instead of failing: wrap the shutdown in a 15-second timeout. The agent coordinating the work tried the suggestion against the broken code first, and the test still hung, because the broken retry swallowed the timeout’s cancellation too. That’s where part 1’s rule comes from: a reviewer’s suggested fix to a test is a claim like any other, and it gets the same mutation run before it lands.
Part 4 in numbers
From the final A/B, the original code against the final one, 2.55 million vectors in a 4 GiB container, plus the ingest probe:
| Metric | Before | After |
|---|---|---|
| Reingest of 2.55M vectors | 31 min (1,362 vec/s) | 13 min (3,174 vec/s) |
| IVF ingest, probe | 534 vec/s | 2,235 vec/s |
| Event-loop stall per probe run | 5.5 to 8.3 s | at most 0.19 s |
| Search p99 on another collection during an ingest | 307 ms | 121 ms |
Next Monday
Part 5, November 9: hybrid search. One underscore behind the p99 tail, a BM25 scorer in Rust that got 19x faster and changed nothing, and the mutex inside SQLite that explains why.