{"record":{"id":"2a1d2c746a81fa20","repo":"mem0ai/mem0","slug":"vertex-ai-embedbatch-returned-allembeddings-le","errorCode":null,"errorMessage":"Vertex AI embedBatch() returned ${allEmbeddings.length} embeddings for ${texts.length} texts using model '${this.model}'","messagePattern":"Vertex AI embedBatch\\(\\) returned (.+?) embeddings for (.+?) texts using model '(.+?)'","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"mem0-ts/src/oss/src/embeddings/vertexai.ts","lineNumber":244,"sourceCode":"      });\n\n      if (!response.predictions || response.predictions.length === 0) {\n        throw new Error(\"No predictions returned from Vertex AI batch request\");\n      }\n\n      for (const prediction of response.predictions) {\n        const decoded = this.helpers.fromValue(prediction as any);\n        if (!isValidEmbedding(decoded)) {\n          throw new Error(\n            \"Failed to extract embedding values from batch response\",\n          );\n        }\n        allEmbeddings.push(decoded.embeddings.values);\n      }\n    }\n\n    if (allEmbeddings.length !== texts.length) {\n      throw new Error(\n        `Vertex AI embedBatch() returned ${allEmbeddings.length} embeddings for ${texts.length} texts using model '${this.model}'`,\n      );\n    }\n\n    return allEmbeddings;\n  }\n}\n","sourceCodeStart":226,"sourceCodeEnd":252,"githubUrl":"https://github.com/mem0ai/mem0/blob/001c235229be8795e3834520467bd0d661ed8f34/mem0-ts/src/oss/src/embeddings/vertexai.ts#L226-L252","documentation":"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.","triggerScenarios":"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.","commonSituations":"Self-hosted or proxied Vertex-compatible endpoints with sloppy batch semantics; incidents on the Vertex side; very large batches during throttling.","solutions":["Retry: mismatches are virtually always transient service/gateway behavior","Reduce the batch size to lower per-request instance counts and retry","Bypass gateways and call Vertex directly to identify where records are lost","If reproducible with counts stable (e.g. always exactly one short), report an issue with model id, chunk size, and both counts"],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":"function isBatchCountMismatch(err: unknown): boolean {\n  return err instanceof Error && /Vertex AI embedBatch\\(\\) returned \\d+ embeddings for \\d+ texts/.test(err.message);\n}","tryCatchPattern":"async function embedBatchRetry(texts: string[], tries = 2) {\n  for (let i = 0; ; i++) {\n    try { return await embedder.embedBatch(texts); }\n    catch (err) {\n      if (i < tries && err instanceof Error && err.message.includes(\"Vertex AI embedBatch() returned\")) continue;\n      throw err;\n    }\n  }\n}","preventionTips":["Retry on mismatch - it is nearly always transient service/gateway behavior","Shrink batch sizes when it recurs to reduce per-request instance counts","Log both counts and the model id to spot systematic off-by-N patterns"],"tags":["vertexai","batch","embeddings","count-mismatch","typescript"],"backgroundTag":null,"analyzedSha":"001c235229be8795e3834520467bd0d661ed8f34","analyzedAt":"2026-08-15T01:55:42.685Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}