For large corpora, synchronous embedding calls can be slow and fragile over long sessions. The OpenAI Batch API allows you to submit work once, then collect results later.
In openalexVectorComp, this is implemented as three explicit steps:
batch_submit_openai()
batch_status_openai()
batch_collect_openai()
This design is operationally safer than waiting for one long blocking process.
OpenAI vs OpenAlex (important)
This vignette describes OpenAI Batch API behavior (submission, completion, retention). If you meant “how long results are on OpenAlex”, that is a different service and outside this workflow.
Lifecycle
%%{init: {'theme': 'forest'}}%%
flowchart TD
A[Prepare corpus + cleaner] --> B[Submit batches]
B --> C[State JSON + local manifests]
C --> D[Status polling]
D -->|completed| E[Collect outputs]
E --> F[Write canonical embeddings parquet]
D -->|pending| G[Exit and retry later]
F --> H[distance_reference_cosine / distance_ridge / scoring]
Prerequisites
OVC_API_TOKEN is set to a valid OpenAI API token.
Backend is configured with provider = "openai".
Corpus exists under project_dir/<corpus_name> with columns:
Check token in the render/session that runs submission:
Sys.getenv("OVC_API_TOKEN")
If you can call the embeddings endpoint manually but package calls fail, confirm no example code overwrites OVC_API_TOKEN during execution.
2) Single oversized records
Auto-splitting handles oversized jobs, not oversized single records. If one request line exceeds max_job_bytes, submission fails by design.
Action:
improve cleaner/truncation policy
or skip problematic rows intentionally
3) Duplicate submission risk
State + manifest tracking prevents re-submitting active rows, but avoid manually editing state JSON unless necessary.
4) Concurrent collectors
The implementation uses a lock file to protect state writes. If a process dies, a stale lock may need manual cleanup.
5) Confusing labels
Always keep labels explicit (corpus, reference, etc.) so output partitions remain interpretable and downstream functions read the right data.
Data retention and expiry (OpenAI)
Operationally relevant points from OpenAI docs:
Batch completion window is currently 24h.
Batch input files are JSONL and have size/request constraints.
Batch output/error files support expiration policy (output_expires_after).
Files with purpose=batch default to finite retention (OpenAI docs currently describe default expiry behavior; verify current details before production).
Because these details can change, monitor official docs and avoid hard-coding assumptions into long-lived pipelines.
Recommended operating pattern
Submit in controlled chunks (max_requests_per_job, max_job_bytes).
Poll status on a schedule.
Collect completed jobs repeatedly.
Archive local state + manifests for auditability.
Run distance/scoring only after collection catches up.