Batch API lab
Define the lab goal and success criteria
Batch API lab is production work only when one frozen failure can be reproduced, one measurable gate can stop a release, and one operator can safely reverse it.
1Try it yourself
Playground
Batch API lab
Sync for interactive latency — batch jobs for large offline embed/index builds.
Embed 1 query at request time
Before you start
Why this matters
Read this incident aloud: a provider partially completes a batch, retries callbacks, and returns results out of input order. In two minutes, write the earliest deterministic check that should fail, the telemetry signal you would inspect, and the action that must not happen automatically. Compare your answer with this chapter's boundary: batch payloads exclude restricted documents; signed result URLs expire and workers have write access only to the staging index.
2Learn the idea
Read
Explain the system and define success
Start by drawing the boundary around an idempotent nightly embedding batch pipeline for 50,000 document chunks. The unit under control is not “the model”; it is one repeatable transaction from BatchItem with custom_id, document_id, chunk_hash, text, model, and index_version to BatchRecord with job_id, state, completed, failed, cost_usd, manifest_hash, and result_uri. In this lab, a provider partially completes a batch, retries callbacks, and returns results out of input order. That makes the learning target observable: we can replay the transaction, record the same fields, and decide whether a release is safer than its baseline. The primary decision metric is successful unique chunks per dollar. The release rule is at least 99.5% completion, zero duplicate vectors, and reconciliation within 30 minutes. Those values are deliberately paired: a single average cannot hide a critical subgroup or a security escape.
Write the failure before writing implementation code. Our named reproduction is: a retried completion webhook inserts the same chunk twice and silently increases index size. A useful reproduction contains a frozen input, an expected decision, the release identifier, and enough deterministic dependencies to rerun locally. It must not depend on a live customer, changing clock, or unrestricted provider account. The fixture below is synthetic but shaped like production. Keep it in version control and add a case whenever an incident exposes a missing behavior.
Success has three levels. A request-level assertion explains one example. An aggregate metric catches drift over many examples. An operational rule says who acts and how quickly. Here, embedding_batch_completion_ratio records the aggregate, while the request artifact carries a correlation ID. The owner should be able to move from an alert to the exact failing fixture without searching raw prompts. The security boundary is equally explicit: batch payloads exclude restricted documents; signed result URLs expire and workers have write access only to the staging index.
The deliverable is a one-page acceptance contract plus the first red test. Do not tune a model yet; uncertainty about the contract is the bug to remove on this page.
Read
Focused implementation artifact
{"custom_id":"doc42:chunk7:sha256-ab12","document_id":"doc42","chunk_hash":"sha256-ab12","text":"Returns require a receipt.","model":"embed-v3","index_version":"staging-44"}
Read
Turn the incident into a lab contract
Use the fixture above as the first row of an acceptance table. Add columns for expected decision, prohibited side effect, severity, policy version, and evidence to retain. The failure statement—a retried completion webhook inserts the same chunk twice and silently increases index size—must be falsifiable: a teammate should know exactly which assertion turns red. Write the baseline result before trying a candidate so improvement is comparative rather than anecdotal.
Now calculate successful unique chunks per dollar by hand for a three-case toy set: one pass, one ordinary failure, and one critical failure. Apply the published gate, at least 99.5% completion, zero duplicate vectors, and reconciliation within 30 minutes, without rounding. This exposes whether weighting, critical-case overrides, and empty slices behave as intended. Emit embedding_batch_completion_ratio once for the toy run and verify that its labels contain a bounded release and outcome, never fixture text.
The lab is ready only when its fixture is synthetic, its dangerous actions are replaced by recording fakes, and its evidence can be retained safely. The expected incident response is to reconcile by custom_id, retry only failed items, verify the staging index, then atomically swap its alias. Assign that decision to a role, not “the team,” and state which artifact proves recovery.
Continue learning · glossary & guides
-
Is the failure falsifiable from one frozen fixture?
-
Does the gate combine a population metric with critical-case handling?
-
Are owner, evidence, and forbidden action explicit?
-
Local references: Glossary: embedding batch · Glossary: batching · Snippet: batch embed pattern