mem0ai/mem0 · error · Error

Vertex AI embedBatch() returned ${allEmbeddings.length} embe

Error message

Vertex AI embedBatch() returned ${allEmbeddings.length} embeddings for ${texts.length} texts using model '${this.model}'

What it means

After all chunks are processed, embedBatch() verifies the total number of collected embeddings equals the number of input texts. A mismatch means the service returned a different number of predictions than instances sent; returning them would silently misalign vectors with memories, so the SDK throws with both counts and the model id.

Source

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

      });

      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. Retry: mismatches are virtually always transient service/gateway behavior
  2. Reduce the batch size to lower per-request instance counts and retry
  3. Bypass gateways and call Vertex directly to identify where records are lost
  4. If reproducible with counts stable (e.g. always exactly one short), report an issue with model id, chunk size, and both counts
Defensive patterns

Strategy: retry

Type guard

function isBatchCountMismatch(err: unknown): boolean {
  return err instanceof Error && /Vertex AI embedBatch\(\) returned \d+ embeddings for \d+ texts/.test(err.message);
}

Try / catch

async function embedBatchRetry(texts: string[], tries = 2) {
  for (let i = 0; ; i++) {
    try { return await embedder.embedBatch(texts); }
    catch (err) {
      if (i < tries && err instanceof Error && err.message.includes("Vertex AI embedBatch() returned")) continue;
      throw err;
    }
  }
}

Prevention

When it happens

Trigger: Vertex returning fewer/more predictions than instances for a chunk (service or gateway bug); chunking logic interacting badly with a model whose per-request instance limit differs from maxInstancesPerRequest; a proxy duplicating or dropping records. Extremely rare against healthy endpoints.

Common situations: Self-hosted or proxied Vertex-compatible endpoints with sloppy batch semantics; incidents on the Vertex side; very large batches during throttling.

Related errors


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