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
- Verify baseUrl points to an OpenAI-compatible embeddings endpoint (…/v1/embeddings), not a chat or generic LLM URL
- Log the raw response body for one request to see what the server actually returned
- Check provider status/compatibility docs; upgrade the provider or library if the response schema changed
- 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
- Point baseUrl strictly at OpenAI-compatible embeddings endpoints
- Log one raw response body when wiring up a new provider
- Prefer providers advertising OpenAI embeddings-schema compatibility
- Monitor for this error as a signal of gateway/proxy misconfiguration
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
- [instance-config] Config source returned empty VDB config fo
- Local embedding model initialization failed: ${this.initErro
- Local embedding model is still loading (download/initializat
- Local embedding model warmup has not been started. Call star
- EmbeddingService: apiKey is required for remote provider
AI-assisted analysis of TencentCloud/TencentDB-Agent-Memory@3efcd317b8 (2026-09-01).
Data as JSON: /api/errors/780277a57d9a6c95.
Report an issue: GitHub.