memorix icon indicating copy to clipboard operation
memorix copied to clipboard

Embedding 402 is retried via batch shrink; doctor still reports ready

Open RaviTharuma opened this issue 3 months ago • 2 comments

Description

When the embedding API returns HTTP 402 (or other non-retryable billing/quota errors), Memorix:

  1. Treats it as “temporarily unavailable”
  2. Shrinks the batch (12 → 6 → 3 → 2 → 1) and retries each size
  3. Eventually falls back to fulltext (search survives)
  4. memorix doctor still reports Embedding Status: ready / hybrid search

This burns many sequential HTTP calls per store/search and can add tens of seconds (or worse if the upstream is slow). Combined with memorix_store + active formation it contributes to host-visible stalls.

Steps to Reproduce

  1. Point [embedding] at an OpenAI-compatible URL that returns 402 for /v1/embeddings (e.g. unpaid Mistral subscription behind a proxy).
  2. Call memorix_search or memorix_store.
  3. Watch background.log.

Expected Behavior

  • 402 / 401 / invalid_api_key should fail once, mark the provider unavailable, and fall back to fulltext immediately.
  • Do not shrink-and-retry a batch that the provider rejected for billing.
  • memorix doctor should show degraded / 402, not ready.

Actual Behavior

[memorix] API embedding 12/12 texts (cache hit: 0.0%)
[memorix] Embedding batch too large for provider, retrying in chunks of 6
[memorix] Embedding batch too large for provider, retrying in chunks of 3
[memorix] Embedding batch too large for provider, retrying in chunks of 2
[memorix] Embedding batch too large for provider, retrying in chunks of 1
[memorix] Embedding provider temporarily unavailable at runtime: Embedding API error (402): {"error":{"message":"Check your subscription ..."}}
[memorix] Embedding failed or timed out, falling back to fulltext search

Doctor:

[OK] Mode: api
[OK] Provider: api-mistral-mistral-embed (1024d)
[OK] Status: ready
    Search: hybrid (BM25 + vector)

Environment

  • Memorix 1.4.3
  • Embedding: provider = "api", model mistral/mistral-embed via OpenAI-compatible proxy
  • Search still works (fulltext)

Additional Context

isRetryableEmbeddingError in 1.4.3 matches embedding api error (402|429|5xx). 402 is not retryable. Batch-size fallback is the wrong diagnosis for a 402.

RaviTharuma avatar Aug 14 '26 07:08 RaviTharuma

Same investigation as #196 / #200. 402 retries can keep store/search busy after formation timeout.

RaviTharuma avatar Aug 14 '26 07:08 RaviTharuma

1.6.1 已发。运行中的 HTTP 控制面会暴露真实 embedding 状态;授权、账单、超时和上游故障都会显示为 degraded,doctor 不会再用一次新的本地探测把已退化的服务说成 ready。

AVIDS2 avatar Aug 17 '26 04:08 AVIDS2