TencentCloud/TencentDB-Agent-Memory · error

Embedding API returned unexpected format: missing 'data' arr

Error message

Embedding API returned unexpected format: missing 'data' array

What it means

The embedding HTTP client expects an OpenAI-style response with a `data` array of {index, embedding} objects. When the API responds 2xx but the JSON lacks a `data` array, the client throws this error because it cannot produce vectors from the payload.

Source

Thrown at MemoryCore/src/core/store/embedding.ts:551

          if (!resp.ok) {
            const errBody = await resp.text().catch(() => "(unable to read body)");
            const err = new EmbeddingApiError(
              `Embedding API error: HTTP ${resp.status} ${resp.statusText} — ${errBody.slice(0, 500)}`,
              resp.status,
            );
            // Don't retry on 4xx client errors (except 429 rate limit)
            if (resp.status >= 400 && resp.status < 500 && resp.status !== 429) {
              throw err;
            }
            lastError = err;
            continue;
          }

          const json = (await resp.json()) as OpenAIEmbeddingResponse;

          if (!json.data || !Array.isArray(json.data)) {
            throw new Error("Embedding API returned unexpected format: missing 'data' array");
          }

          // Sort by index to ensure correct order, then sanitize+normalize for consistency with local provider
          const sorted = [...json.data].sort((a, b) => a.index - b.index);
          return sorted.map((d) => sanitizeAndNormalize(d.embedding));
        } finally {
          clearTimeout(timeoutId);
        }
      } catch (err) {
        // Non-retryable errors (4xx client errors) — rethrow immediately
        if (err instanceof EmbeddingApiError && err.isClientError()) {
          throw err;
        }
        lastError = err instanceof Error ? err : new Error(String(err));
        // AbortError = timeout, retry
        if (attempt < MAX_RETRIES) {
          // Exponential backoff: 500ms, 1000ms
          const delay = 500 * (attempt + 1);

View on GitHub (pinned to 3efcd317b8)

Solutions

  1. Verify baseUrl points to an OpenAI-compatible embeddings endpoint (…/v1/embeddings), not a chat or generic LLM URL
  2. Log the raw response body for one request to see what the server actually returned
  3. Check provider status/compatibility docs; upgrade the provider or library if the response schema changed
  4. Wrap embedBatch/chunkResults calls in try-catch and surface the upstream payload for diagnosis

Example fix

// before
baseUrl: 'https://api.example.com/v1/chat/completions'
// after
baseUrl: 'https://api.example.com/v1' // client appends /embeddings; response includes { data: [...] }
Defensive patterns

Strategy: try-catch

Validate before calling

function isOpenAIEmbeddingResponse(json) {
  return !!json && Array.isArray(json.data) && json.data.every(d => Array.isArray(d.embedding));
}

Type guard

function isEmbeddingResponse(j): j is OpenAIEmbeddingResponse {
  return typeof j === 'object' && j !== null && Array.isArray((j as any).data);
}

Try / catch

try {
  const vecs = await svc.embedBatch(texts);
} catch (e) {
  if (String(e.message).includes("missing 'data' array")) {
    logger.error('Embedding endpoint returned a non-OpenAI payload — check baseUrl points at /v1 embeddings');
    throw new UpstreamFormatError(e.message);
  }
  throw e;
}

Prevention

When it happens

Trigger: _callApi (used by chunkResults and embedBatch) receives a successful HTTP response whose parsed JSON has no `data` field or a non-array `data`.

Common situations: Pointing baseUrl at a non-OpenAI-compatible endpoint (proxy, LLM chat endpoint, or error page returning 200 with HTML/JSON of a different shape), a gateway returning a soft error with 200, or an OpenAI-compatible server with a breaking schema change.

Related errors


AI-assisted analysis of TencentCloud/TencentDB-Agent-Memory@3efcd317b8 (2026-09-01). Data as JSON: /api/errors/780277a57d9a6c95. Report an issue: GitHub.