mem0ai/mem0 · error · ValueError
Vertex AI embed_batch() returned {len(all_embeddings)} embed
Error message
Vertex AI embed_batch() returned {len(all_embeddings)} embeddings for {len(texts)} texts using model '{self.config.model}' What it means
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.
Source
Thrown at mem0/embeddings/vertexai.py:81
return embeddings[0].values
def embed_batch(self, texts, memory_action="add"):
if not texts:
return []
embedding_type = "SEMANTIC_SIMILARITY"
if memory_action is not None:
if memory_action not in self.embedding_types:
raise ValueError(f"Invalid memory action: {memory_action}")
embedding_type = self.embedding_types[memory_action]
all_embeddings = []
for i in range(0, len(texts), 250):
chunk = texts[i : i + 250]
inputs = [TextEmbeddingInput(text=t, task_type=embedding_type) for t in chunk]
results = self.model.get_embeddings(texts=inputs, output_dimensionality=self.config.embedding_dims)
all_embeddings.extend(r.values for r in results)
if len(all_embeddings) != len(texts):
raise ValueError(
f"Vertex AI embed_batch() returned {len(all_embeddings)} embeddings for {len(texts)} texts"
f" using model '{self.config.model}'"
)
return all_embeddings
View on GitHub (pinned to 001c235229)
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
Example fix
// before
embs = embedder.embed_batch(texts) # e.g. 10000 texts
# after
embs = []
for i in range(0, len(texts), 64):
embs.extend(embedder.embed_batch(texts[i:i+64])) Defensive patterns
Strategy: retry
Validate before calling
# stay under Vertex per-request input limits; 64 is safe across model versions
for i in range(0, len(texts), 64):
embedder.embed_batch(texts[i:i+64]) Try / catch
try:
vecs = embedder.embed_batch(chunk)
except ValueError as e:
if "embed_batch() returned" in str(e):
half = max(1, len(chunk)//2)
vecs = embedder.embed_batch(chunk[:half]) + embedder.embed_batch(chunk[half:])
else:
raise Prevention
- 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
When it happens
Trigger: 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.
Common situations: Bulk memory ingestion on Vertex AI; switching model versions without adjusting chunk size; regional endpoint differences in limits.
Related errors
- OpenAI embed_batch() returned {len(all_embeddings)} embeddin
- Together embed_batch() returned {len(embeddings)} embeddings
- LM Studio embed_batch() returned {len(embeddings)} embedding
- Ollama embed() returned {len(embeddings)} embeddings for {le
- Invalid memory action: {memory_action}
AI-assisted analysis of mem0ai/mem0@001c235229 (2026-08-15).
Data as JSON: /api/errors/6e0e2dcf4825883e.
Report an issue: GitHub.