Skip to content

fix(embeddings): defer operations when OpenAI embeddings run out of credits - #5746

Merged
nicoloboschi merged 4 commits into
mainfrom
fix/embeddings-quota-defer
Oct 19, 2026
Merged

nicoloboschi merged 4 commits into
mainfrom
fix/embeddings-quota-defer

Conversation

@nicoloboschi

Copy link
Copy Markdown
Collaborator

Fixes #5588.

Problem

  • An OpenAI embeddings 429 insufficient_quota was retried 3 × 60s, then the operation was marked failed for good. Nothing picked it up again once credits came back.
  • generate_embeddings_batch re-wrapped every error in a plain Exception without from e, so the original error was lost.
  • The OpenAI embeddings client had no timeout. The SDK default is 600s per attempt, so one stalled request could hold a retain for ~40 minutes.
  • The factory never passed HINDSIGHT_API_EMBEDDINGS_MAX_RETRIES to the OpenAI-family providers, so that setting did nothing there.

Fix

  • OpenAIEmbeddings._embed_batch turns a 429 insufficient_quota into ProviderRateLimitResetError, retrying in 15 minutes. The worker already turns that error into a DeferOperation, the same path the LLM providers use, so the retry count is not used up. Other 429s behave as before.
  • generate_embeddings_batch lets that error through unchanged and keeps the cause (from e) on all other errors.
  • The OpenAI client now has a 60s request timeout, the same as the other remote embedding providers.
  • openai, openai-codex, openrouter and requesty now get max_retries from HINDSIGHT_API_EMBEDDINGS_MAX_RETRIES.

I kept the 15-minute wait as a fixed value, not a new env var like the reference branch has. A new setting can be added if someone needs to tune it.

Tests

tests/test_embeddings_openai_quota.py: an insufficient_quota error defers through generate_embeddings_batch; an ordinary 429 still fails and keeps its cause; the client built by the factory has the timeout and the configured retry count.

Thanks to @choi138 for the detailed report and reference branch.

…client a timeout and the configured retries

Closes #5588
…he model in the factory test

- configuration.mdx (+ regenerated docs skill): HINDSIGHT_API_EMBEDDINGS_MAX_RETRIES
  no longer says the openai family ignores it; it names the four providers that
  take it and the insufficient_quota 15-minute defer.
- test_client_carries_timeout_and_configured_retries: set the OpenAI embeddings
  model and clear the base URL, so a developer env with a different model
  can't make initialize() probe the real API.
@nicoloboschi
nicoloboschi merged commit 7f18b6f into main Oct 19, 2026
232 of 234 checks passed
@nicoloboschi
nicoloboschi deleted the fix/embeddings-quota-defer branch October 19, 2026 18:20
audichuang added a commit to audichuang/hindsight that referenced this pull request Oct 20, 2026
fix(embeddings): backport vectorize-io#5746 — OpenAI-family embeddings honour EMBEDDINGS_MAX_RETRIES, get a timeout, defer on insufficient_quota
@nicoloboschi nicoloboschi mentioned this pull request Nov 3, 2026
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.

Embeddings quota exhaustion (OpenAI 429 insufficient_quota) is retried briefly then marked failed; no request timeout on OpenAI embeddings client

1 participant