{"record":{"id":"780277a57d9a6c95","repo":"TencentCloud/TencentDB-Agent-Memory","slug":"embedding-api-returned-unexpected-format-missing","errorCode":null,"errorMessage":"Embedding API returned unexpected format: missing 'data' array","messagePattern":"Embedding API returned unexpected format: missing 'data' array","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"MemoryCore/src/core/store/embedding.ts","lineNumber":551,"sourceCode":"\n          if (!resp.ok) {\n            const errBody = await resp.text().catch(() => \"(unable to read body)\");\n            const err = new EmbeddingApiError(\n              `Embedding API error: HTTP ${resp.status} ${resp.statusText} — ${errBody.slice(0, 500)}`,\n              resp.status,\n            );\n            // Don't retry on 4xx client errors (except 429 rate limit)\n            if (resp.status >= 400 && resp.status < 500 && resp.status !== 429) {\n              throw err;\n            }\n            lastError = err;\n            continue;\n          }\n\n          const json = (await resp.json()) as OpenAIEmbeddingResponse;\n\n          if (!json.data || !Array.isArray(json.data)) {\n            throw new Error(\"Embedding API returned unexpected format: missing 'data' array\");\n          }\n\n          // Sort by index to ensure correct order, then sanitize+normalize for consistency with local provider\n          const sorted = [...json.data].sort((a, b) => a.index - b.index);\n          return sorted.map((d) => sanitizeAndNormalize(d.embedding));\n        } finally {\n          clearTimeout(timeoutId);\n        }\n      } catch (err) {\n        // Non-retryable errors (4xx client errors) — rethrow immediately\n        if (err instanceof EmbeddingApiError && err.isClientError()) {\n          throw err;\n        }\n        lastError = err instanceof Error ? err : new Error(String(err));\n        // AbortError = timeout, retry\n        if (attempt < MAX_RETRIES) {\n          // Exponential backoff: 500ms, 1000ms\n          const delay = 500 * (attempt + 1);","sourceCodeStart":533,"sourceCodeEnd":569,"githubUrl":"https://github.com/TencentCloud/TencentDB-Agent-Memory/blob/3efcd317b84146d6a08518ac0f7ee7c8a8d200ec/MemoryCore/src/core/store/embedding.ts#L533-L569","documentation":"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.","triggerScenarios":"_callApi (used by chunkResults and embedBatch) receives a successful HTTP response whose parsed JSON has no `data` field or a non-array `data`.","commonSituations":"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.","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"],"exampleFix":"// before\nbaseUrl: 'https://api.example.com/v1/chat/completions'\n// after\nbaseUrl: 'https://api.example.com/v1' // client appends /embeddings; response includes { data: [...] }","handlingStrategy":"try-catch","validationCode":"function isOpenAIEmbeddingResponse(json) {\n  return !!json && Array.isArray(json.data) && json.data.every(d => Array.isArray(d.embedding));\n}","typeGuard":"function isEmbeddingResponse(j): j is OpenAIEmbeddingResponse {\n  return typeof j === 'object' && j !== null && Array.isArray((j as any).data);\n}","tryCatchPattern":"try {\n  const vecs = await svc.embedBatch(texts);\n} catch (e) {\n  if (String(e.message).includes(\"missing 'data' array\")) {\n    logger.error('Embedding endpoint returned a non-OpenAI payload — check baseUrl points at /v1 embeddings');\n    throw new UpstreamFormatError(e.message);\n  }\n  throw e;\n}","preventionTips":["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"],"tags":["network","api-response","embedding","schema-mismatch"],"backgroundTag":"unexpected-api-response-format","analyzedSha":"3efcd317b84146d6a08518ac0f7ee7c8a8d200ec","analyzedAt":"2026-09-01T05:44:22.276Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}