{"record":{"id":"6e0e2dcf4825883e","repo":"mem0ai/mem0","slug":"vertex-ai-embed-batch-returned-len-all-embeddin","errorCode":null,"errorMessage":"Vertex AI embed_batch() returned {len(all_embeddings)} embeddings for {len(texts)} texts using model '{self.config.model}'","messagePattern":"Vertex AI embed_batch\\(\\) returned (.+?) embeddings for (.+?) texts using model '(.+?)'","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"mem0/embeddings/vertexai.py","lineNumber":81,"sourceCode":"\n        return embeddings[0].values\n\n    def embed_batch(self, texts, memory_action=\"add\"):\n        if not texts:\n            return []\n        embedding_type = \"SEMANTIC_SIMILARITY\"\n        if memory_action is not None:\n            if memory_action not in self.embedding_types:\n                raise ValueError(f\"Invalid memory action: {memory_action}\")\n            embedding_type = self.embedding_types[memory_action]\n        all_embeddings = []\n        for i in range(0, len(texts), 250):\n            chunk = texts[i : i + 250]\n            inputs = [TextEmbeddingInput(text=t, task_type=embedding_type) for t in chunk]\n            results = self.model.get_embeddings(texts=inputs, output_dimensionality=self.config.embedding_dims)\n            all_embeddings.extend(r.values for r in results)\n        if len(all_embeddings) != len(texts):\n            raise ValueError(\n                f\"Vertex AI embed_batch() returned {len(all_embeddings)} embeddings for {len(texts)} texts\"\n                f\" using model '{self.config.model}'\"\n            )\n        return all_embeddings\n","sourceCodeStart":63,"sourceCodeEnd":86,"githubUrl":"https://github.com/mem0ai/mem0/blob/001c235229be8795e3834520467bd0d661ed8f34/mem0/embeddings/vertexai.py#L63-L86","documentation":"Raised by VertexAIEmbedding.embed_batch after chunking texts into groups of 250 and collecting all vectors: total embeddings must equal total texts. A mismatch means the Vertex AI text-embedding endpoint returned a different number of values for at least one chunk — usually per-request input limits or output_dimensionality interactions with older model versions.","triggerScenarios":"Batching more texts than a chunk's API input limit for the model (text-embedding-004 caps inputs per request); using an older model (textembedding-gecko) whose batch limits differ from 250; API responses for a chunk returning fewer values for the requested output_dimensionality.","commonSituations":"Bulk memory ingestion on Vertex AI; switching model versions without adjusting chunk size; regional endpoint differences in limits.","solutions":["Lower the client-side batch size below the model's per-request input limit (e.g. chunks of 32-64 texts)","Use a current model (text-embedding-004 or newer) whose limits match the 250 chunking","Retry the failing chunk and log per-chunk counts to isolate the request that loses items","Ensure output_dimensionality is supported by the chosen model"],"exampleFix":"// before\nembs = embedder.embed_batch(texts)  # e.g. 10000 texts\n\n# after\nembs = []\nfor i in range(0, len(texts), 64):\n    embs.extend(embedder.embed_batch(texts[i:i+64]))","handlingStrategy":"retry","validationCode":"# stay under Vertex per-request input limits; 64 is safe across model versions\nfor i in range(0, len(texts), 64):\n    embedder.embed_batch(texts[i:i+64])","typeGuard":null,"tryCatchPattern":"try:\n    vecs = embedder.embed_batch(chunk)\nexcept ValueError as e:\n    if \"embed_batch() returned\" in str(e):\n        half = max(1, len(chunk)//2)\n        vecs = embedder.embed_batch(chunk[:half]) + embedder.embed_batch(chunk[half:])\n    else:\n        raise","preventionTips":["Chunk below 250 (the provider's internal chunk size), ideally 64","Prefer text-embedding-004+ with known limits","Log per-chunk counts during bulk ingestion"],"tags":["python","vertexai","embeddings","batching","api","mem0"],"backgroundTag":null,"analyzedSha":"001c235229be8795e3834520467bd0d661ed8f34","analyzedAt":"2026-08-15T01:55:42.685Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}