mem0ai/mem0 · error · Error

Failed to extract embedding values from batch response

Error message

Failed to extract embedding values from batch response

What it means

In embedBatch(), every prediction in the batch response is decoded with helpers.fromValue and checked by isValidEmbedding. If any single decoded prediction lacks the embeddings.values structure, this error aborts the whole batch (the SDK prefers failing over returning a misaligned vector array).

Source

Thrown at mem0-ts/src/oss/src/embeddings/vertexai.ts:235

      );
      const parameters = {
        outputDimensionality: this.embeddingDims,
      };

      const [response] = await this.client.predict({
        endpoint: this.endpoint(),
        instances,
        parameters: this.helpers.toValue(parameters) as any,
      });

      if (!response.predictions || response.predictions.length === 0) {
        throw new Error("No predictions returned from Vertex AI batch request");
      }

      for (const prediction of response.predictions) {
        const decoded = this.helpers.fromValue(prediction as any);
        if (!isValidEmbedding(decoded)) {
          throw new Error(
            "Failed to extract embedding values from batch response",
          );
        }
        allEmbeddings.push(decoded.embeddings.values);
      }
    }

    if (allEmbeddings.length !== texts.length) {
      throw new Error(
        `Vertex AI embedBatch() returned ${allEmbeddings.length} embeddings for ${texts.length} texts using model '${this.model}'`,
      );
    }

    return allEmbeddings;
  }
}

View on GitHub (pinned to 001c235229)

Solutions

  1. Sanitize inputs before batching: drop or replace empty/whitespace-only strings
  2. Reproduce with smaller batches (binary-search the chunk) to identify the offending input, then fix or filter it
  3. Pin a current @google-cloud/aiplatform version and a stable (non-preview) embedding model id
  4. Retry once; transient malformed responses from regional endpoints occur

Example fix

// before
await embedder.embedBatch(allTexts); // may include "" entries

// after
const clean = allTexts.map((t) => t.trim()).filter((t) => t.length > 0);
await embedder.embedBatch(clean);
Defensive patterns

Strategy: validation

Validate before calling

const clean = texts.map((t) => (typeof t === "string" ? t.trim() : "")).filter((t) => t.length > 0);
if (clean.length === 0) throw new Error("No non-empty texts to embed");
await embedder.embedBatch(clean, memoryAction);

Type guard

function isBatchExtractError(err: unknown): boolean {
  return err instanceof Error && err.message === "Failed to extract embedding values from batch response";
}

Try / catch

try { await embedder.embedBatch(texts); }
catch (err) {
  if (err instanceof Error && err.message === "Failed to extract embedding values from batch response") {
    // Bisect to find the offending input, then filter and retry
    if (texts.length > 1) {
      const mid = Math.ceil(texts.length / 2);
      return [...(await embedBatchSafe(texts.slice(0, mid))), ...(await embedBatchSafe(texts.slice(mid)))];
    }
    return [] as number[][]; // drop the single bad text
  }
  throw err;
}

Prevention

When it happens

Trigger: One item in a chunk producing a non-embedding payload (e.g. an input string the model rejects or truncates to empty, or an error record embedded in the response); preview models with mixed output envelopes; aiplatform library version decoding values differently.

Common situations: Batch containing empty strings, whitespace-only, or oversized texts after preprocessing; mixing languages/inputs that the embedding model errors on individually; version drift between the SDK's expected response shape and the installed @google-cloud/aiplatform.

Related errors


AI-assisted analysis of mem0ai/mem0@001c235229 (2026-08-15). Data as JSON: /api/errors/948b7a69c4272019. Report an issue: GitHub.