chroma-core/chroma · error · ChromaValueError

Embedding function returned unexpected number of embeddings.

Error message

Embedding function returned unexpected number of embeddings.

What it means

Consistency check in embedKnnLiteral(): after embedding a single query literal via embed([queryValue], true), the result was empty or did not contain exactly one embedding. The embedding function broke the one-input-one-output contract for queries.

Solutions

  1. Fix the embedding function to return exactly one embedding for a single query input
  2. Verify the EF's generateForQueries/query path isn't returning [] or multiple vectors
  3. Test the EF's query-mode output length directly
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at clients/new-js/packages/chromadb/src/collection.ts:644 when the library encounters an invalid state.

Common situations: See trigger scenarios.


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

Appendix: source

Thrown at clients/new-js/packages/chromadb/src/collection.ts:644

    return resultMetadatas as Metadata[];
  }

  private async embedKnnLiteral(
    knn: Record<string, unknown>,
  ): Promise<Record<string, unknown>> {
    const queryValue = knn.query as unknown;
    if (typeof queryValue !== "string") {
      return { ...knn };
    }

    const keyValue = knn.key as unknown;
    const key = typeof keyValue === "string" ? keyValue : EMBEDDING_KEY;

    if (key === EMBEDDING_KEY) {
      const embeddings = await this.embed([queryValue], true);
      if (!embeddings || embeddings.length !== 1) {
        throw new ChromaValueError(
          "Embedding function returned unexpected number of embeddings.",
        );
      }
      return { ...knn, query: embeddings[0] };
    }

    const schema = this._schema;
    if (!schema) {
      throw new ChromaValueError(
        `Cannot embed string query for key '${key}': schema is not available. Provide an embedded vector or configure an embedding function.`,
      );
    }

    const valueTypes = schema.keys[key];
    if (!valueTypes) {
      throw new ChromaValueError(
        `Cannot embed string query for key '${key}': key not found in schema. Provide an embedded vector or configure an embedding function.`,
      );

View on GitHub (pinned to aecdd12c8a)