{"record":{"id":"c04dcb3ea3df0e33","repo":"chroma-core/chroma","slug":"invalid-response-format-expected-object","errorCode":null,"errorMessage":"Invalid response format: expected object","messagePattern":"Invalid response format: expected object","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"clients/new-js/packages/ai-embeddings/chroma-cloud-splade/src/index.ts","lineNumber":142,"sourceCode":"      const response = await fetch(this.url, {\n        method: \"POST\",\n        headers: this.headers,\n        body: JSON.stringify(snakeCase(body)),\n      });\n\n      if (!response.ok) {\n        const errorText = await response.text();\n        throw new Error(\n          `HTTP ${response.status} ${response.statusText}: ${errorText}`,\n        );\n      }\n\n      const data =\n        (await response.json()) as ChromaCloudSparseEmbeddingsResponse;\n\n      // Validate response structure\n      if (!data || typeof data !== \"object\") {\n        throw new Error(\"Invalid response format: expected object\");\n      }\n\n      if (!Array.isArray(data.embeddings)) {\n        throw new Error(\n          \"Invalid response format: missing or invalid embeddings array\",\n        );\n      }\n\n      // Sort the sparse vectors to match Python behavior\n      sortSparseVectors(data.embeddings);\n\n      return data.embeddings;\n    } catch (error) {\n      if (error instanceof Error) {\n        throw new Error(`Error calling Chroma Embedding API: ${error.message}`);\n      } else {\n        throw new Error(`Error calling Chroma Embedding API: ${error}`);\n      }","sourceCodeStart":124,"sourceCodeEnd":160,"githubUrl":"https://github.com/chroma-core/chroma/blob/aecdd12c8a891610db8653630b066b32ceb678b5/clients/new-js/packages/ai-embeddings/chroma-cloud-splade/src/index.ts#L124-L160","documentation":"Thrown by ChromaCloudSpladeEmbeddingFunction after a 2xx response whose JSON body is not a non-null object (e.g. the parsed value is a string, number, boolean, or null). This guards the response shape before data.embeddings is accessed; the follow-up check covers a missing embeddings array. It signals a malformed or unexpected payload from the endpoint — usually a proxy, gateway, or URL override returning something that is valid JSON but not the SPLADE response object.","triggerScenarios":"A gateway returns JSON-encoded strings (e.g. \"ok\") with 200; an embed URL override points at an endpoint that returns scalar JSON; serverless wrappers or caches transforming the response body; API contract change returning a different top-level shape.","commonSituations":"Custom reverse proxies in front of the API; misconfigured environment-specific embed endpoints; stale SDK versions talking to a changed API; response-stubbing in tests that returns non-object JSON.","solutions":["Log the raw body (response.text()) on failure and compare with the expected { embeddings: [...] } shape.","Remove or fix any embed-URL override so requests hit the real Chroma embed endpoint.","If a proxy is in the path, bypass it or configure it to pass responses through unmodified.","Upgrade the chroma-cloud-splade package in case the API contract changed with a matching SDK fix."],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":null,"typeGuard":"function isSparseEmbeddingsResponse(data: unknown): data is { embeddings: SparseVector[] } {\n  if (typeof data !== \"object\" || data === null) return false;\n  const emb = (data as { embeddings?: unknown }).embeddings;\n  if (!Array.isArray(emb)) return false;\n  return emb.every(\n    (v) =>\n      typeof v === \"object\" &&\n      v !== null &&\n      Array.isArray((v as SparseVector).indices) &&\n      Array.isArray((v as SparseVector).values) &&\n      (v as SparseVector).indices.length === (v as SparseVector).values.length,\n  );\n}","tryCatchPattern":"try {\n  const vectors = await spladeEf.generate(texts);\n} catch (e) {\n  const msg = (e as Error).message;\n  if (msg.includes(\"Invalid response format\")) {\n    // Log raw body / check proxies and embed URL overrides; not retryable as-is\n    console.error(\"Malformed embed response — verify endpoint and proxies\");\n  }\n  throw e;\n}","preventionTips":["Validate response shape with a type guard when calling the embed endpoint directly.","Ensure proxies/gateways pass API responses through unmodified.","Confirm any embed URL override targets the real Chroma embed endpoint.","Keep the SDK version aligned with the API version in use."],"tags":["cloud-api","splade","response-validation","embeddings"],"backgroundTag":"invalid-api-response-format","analyzedSha":"aecdd12c8a891610db8653630b066b32ceb678b5","analyzedAt":"2026-08-16T21:53:27.228Z","schemaVersion":2},"datasetVersion":"2026-08-16T23:17:17.608Z"}