{"record":{"id":"948b7a69c4272019","repo":"mem0ai/mem0","slug":"failed-to-extract-embedding-values-from-batch-resp","errorCode":null,"errorMessage":"Failed to extract embedding values from batch response","messagePattern":"Failed to extract embedding values from batch response","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"mem0-ts/src/oss/src/embeddings/vertexai.ts","lineNumber":235,"sourceCode":"      );\n      const parameters = {\n        outputDimensionality: this.embeddingDims,\n      };\n\n      const [response] = await this.client.predict({\n        endpoint: this.endpoint(),\n        instances,\n        parameters: this.helpers.toValue(parameters) as any,\n      });\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":217,"sourceCodeEnd":252,"githubUrl":"https://github.com/mem0ai/mem0/blob/001c235229be8795e3834520467bd0d661ed8f34/mem0-ts/src/oss/src/embeddings/vertexai.ts#L217-L252","documentation":"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).","triggerScenarios":"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.","commonSituations":"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.","solutions":["Sanitize inputs before batching: drop or replace empty/whitespace-only strings","Reproduce with smaller batches (binary-search the chunk) to identify the offending input, then fix or filter it","Pin a current @google-cloud/aiplatform version and a stable (non-preview) embedding model id","Retry once; transient malformed responses from regional endpoints occur"],"exampleFix":"// before\nawait embedder.embedBatch(allTexts); // may include \"\" entries\n\n// after\nconst clean = allTexts.map((t) => t.trim()).filter((t) => t.length > 0);\nawait embedder.embedBatch(clean);","handlingStrategy":"validation","validationCode":"const clean = texts.map((t) => (typeof t === \"string\" ? t.trim() : \"\")).filter((t) => t.length > 0);\nif (clean.length === 0) throw new Error(\"No non-empty texts to embed\");\nawait embedder.embedBatch(clean, memoryAction);","typeGuard":"function isBatchExtractError(err: unknown): boolean {\n  return err instanceof Error && err.message === \"Failed to extract embedding values from batch response\";\n}","tryCatchPattern":"try { await embedder.embedBatch(texts); }\ncatch (err) {\n  if (err instanceof Error && err.message === \"Failed to extract embedding values from batch response\") {\n    // Bisect to find the offending input, then filter and retry\n    if (texts.length > 1) {\n      const mid = Math.ceil(texts.length / 2);\n      return [...(await embedBatchSafe(texts.slice(0, mid))), ...(await embedBatchSafe(texts.slice(mid)))];\n    }\n    return [] as number[][]; // drop the single bad text\n  }\n  throw err;\n}","preventionTips":["Sanitize inputs: trim and drop empty strings before batching","Keep a bisection helper around batches so one bad input does not kill the run","Pin stable embedding model ids and matching aiplatform versions"],"tags":["vertexai","batch","response-shape","embeddings","typescript"],"backgroundTag":null,"analyzedSha":"001c235229be8795e3834520467bd0d661ed8f34","analyzedAt":"2026-08-15T01:55:42.685Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}