chroma-core/chroma · error

Failed to generate embeddings.

Error message

Failed to generate embeddings.

What it means

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.

Source

Thrown at clients/new-js/packages/ai-embeddings/chroma-cloud-qwen/src/index.ts:134

      instruction =
        this.instructions[this.task][ChromaCloudQwenEmbeddingTarget.DOCUMENTS];
    }

    const body: ChromaCloudEmbeddingRequest = {
      texts,
      instructions: instruction,
    };

    try {
      const response = await fetch(this.url, {
        method: "POST",
        headers: this.headers,
        body: JSON.stringify(snakeCase(body)),
      });

      const data = (await response.json()) as ChromaCloudEmbeddingsResponse;
      if (!data || !data.embeddings) {
        throw new Error("Failed to generate embeddings.");
      }
      return data.embeddings;
    } catch (error) {
      if (error instanceof Error) {
        throw new Error(`Error calling Chroma Embedding API: ${error.message}`);
      } else {
        throw new Error(`Error calling Chroma Embedding API: ${error}`);
      }
    }
  }

  public async generateForQueries(texts: string[]): Promise<number[][]> {
    if (texts.length === 0) {
      return [];
    }

    let instruction = "";
    if (this.task && this.task in this.instructions) {

View on GitHub (pinned to aecdd12c8a)

Solutions

  1. Verify the API key: export CHROMA_API_KEY=... (or pass apiKeyEnvVar/client headers) so the x-chroma-token header is a valid key.
  2. Confirm the model value is exactly a supported enum, e.g. ChromaCloudQwenEmbeddingModel.QWEN3_EMBEDDING_0p6B ("Qwen/Qwen3-Embedding-0.6B").
  3. Reproduce the raw call with curl and inspect the JSON body — the API's own error message is more specific than this generic throw.
  4. If the body is not JSON at all you will get the wrapped variant instead; check proxies/gateways that return HTML errors.

Example fix

// before
const ef = new ChromaCloudQwenEmbeddingFunction({
  model: ChromaCloudQwenEmbeddingModel.QWEN3_EMBEDDING_0p6B,
  task: null,
}); // CHROMA_API_KEY never set -> token sent as ""

// after
export CHROMA_API_KEY=<your-key>
const ef = new ChromaCloudQwenEmbeddingFunction({
  model: ChromaCloudQwenEmbeddingModel.QWEN3_EMBEDDING_0p6B,
  task: null,
});
Defensive patterns

Strategy: try-catch

Validate before calling

if (!process.env.CHROMA_API_KEY) {
  throw new Error("CHROMA_API_KEY must be set before embedding");
}
const ef = new ChromaCloudQwenEmbeddingFunction({
  model: ChromaCloudQwenEmbeddingModel.QWEN3_EMBEDDING_0p6B,
  task: null,
});

Try / catch

try {
  const vectors = await ef.generate(texts);
} catch (e) {
  const msg = (e as Error).message;
  if (msg.includes("Failed to generate embeddings")) {
    // JSON body without embeddings: check API key, model header, request shape
  }
  throw e;
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of chroma-core/chroma@aecdd12c8a (2026-08-16). Data as JSON: /api/errors/fbaffc4dbdd2ba82. Report an issue: GitHub.