{"record":{"id":"fbaffc4dbdd2ba82","repo":"chroma-core/chroma","slug":"failed-to-generate-embeddings","errorCode":null,"errorMessage":"Failed to generate embeddings.","messagePattern":"Failed to generate embeddings\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"clients/new-js/packages/ai-embeddings/chroma-cloud-qwen/src/index.ts","lineNumber":134,"sourceCode":"      instruction =\n        this.instructions[this.task][ChromaCloudQwenEmbeddingTarget.DOCUMENTS];\n    }\n\n    const body: ChromaCloudEmbeddingRequest = {\n      texts,\n      instructions: instruction,\n    };\n\n    try {\n      const response = await fetch(this.url, {\n        method: \"POST\",\n        headers: this.headers,\n        body: JSON.stringify(snakeCase(body)),\n      });\n\n      const data = (await response.json()) as ChromaCloudEmbeddingsResponse;\n      if (!data || !data.embeddings) {\n        throw new Error(\"Failed to generate 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      }\n    }\n  }\n\n  public async generateForQueries(texts: string[]): Promise<number[][]> {\n    if (texts.length === 0) {\n      return [];\n    }\n\n    let instruction = \"\";\n    if (this.task && this.task in this.instructions) {","sourceCodeStart":116,"sourceCodeEnd":152,"githubUrl":"https://github.com/chroma-core/chroma/blob/aecdd12c8a891610db8653630b066b32ceb678b5/clients/new-js/packages/ai-embeddings/chroma-cloud-qwen/src/index.ts#L116-L152","documentation":"Thrown by ChromaCloudQwenEmbeddingFunction.generate() when the Chroma Embedding API response JSON parses successfully but has no embeddings field. Because this package does not check response.ok, an error payload (auth failure, bad model, invalid request) that comes back as JSON without \"embeddings\" lands here. Note this throw happens inside the try block, so it is re-thrown wrapped as \"Error calling Chroma Embedding API: Failed to generate embeddings.\" — that is the message you actually see.","triggerScenarios":"POST to the embed endpoint with an invalid or missing x-chroma-token (CHROMA_API_KEY unset — the constructor only warns) so the server returns a JSON error body; wrong or unavailable model in the x-chroma-embedding-model header; malformed request body that the API answers with a structured error instead of embeddings.","commonSituations":"Forgot to export CHROMA_API_KEY (constructor only console.warns, then sends an empty token); rotating/revoked API keys; using a model id not enabled for the account; pointing getChromaEmbedUrl() at a different environment via env override.","solutions":["Verify the API key: export CHROMA_API_KEY=... (or pass apiKeyEnvVar/client headers) so the x-chroma-token header is a valid key.","Confirm the model value is exactly a supported enum, e.g. ChromaCloudQwenEmbeddingModel.QWEN3_EMBEDDING_0p6B (\"Qwen/Qwen3-Embedding-0.6B\").","Reproduce the raw call with curl and inspect the JSON body — the API's own error message is more specific than this generic throw.","If the body is not JSON at all you will get the wrapped variant instead; check proxies/gateways that return HTML errors."],"exampleFix":"// before\nconst ef = new ChromaCloudQwenEmbeddingFunction({\n  model: ChromaCloudQwenEmbeddingModel.QWEN3_EMBEDDING_0p6B,\n  task: null,\n}); // CHROMA_API_KEY never set -> token sent as \"\"\n\n// after\nexport CHROMA_API_KEY=<your-key>\nconst ef = new ChromaCloudQwenEmbeddingFunction({\n  model: ChromaCloudQwenEmbeddingModel.QWEN3_EMBEDDING_0p6B,\n  task: null,\n});","handlingStrategy":"try-catch","validationCode":"if (!process.env.CHROMA_API_KEY) {\n  throw new Error(\"CHROMA_API_KEY must be set before embedding\");\n}\nconst ef = new ChromaCloudQwenEmbeddingFunction({\n  model: ChromaCloudQwenEmbeddingModel.QWEN3_EMBEDDING_0p6B,\n  task: null,\n});","typeGuard":null,"tryCatchPattern":"try {\n  const vectors = await ef.generate(texts);\n} catch (e) {\n  const msg = (e as Error).message;\n  if (msg.includes(\"Failed to generate embeddings\")) {\n    // JSON body without embeddings: check API key, model header, request shape\n  }\n  throw e;\n}","preventionTips":["Assert the API key exists at startup — the constructor only warns.","Use the model enum values, never hand-typed model strings.","Keep one shared embed-endpoint config across environments to avoid shape drift."],"tags":["embeddings","cloud-api","qwen","api-response"],"backgroundTag":"api-response-missing-field","analyzedSha":"aecdd12c8a891610db8653630b066b32ceb678b5","analyzedAt":"2026-08-16T21:53:27.228Z","schemaVersion":2},"datasetVersion":"2026-08-16T23:17:17.608Z"}