mem0ai/mem0 · error · ValueError
Vector at index {idx} is empty. Expected a vector of dimensi
Error message
Vector at index {idx} is empty. Expected a vector of dimension {self.embedding_model_dims}, got an empty vector. What it means
insert() rejects vectors whose length is 0. An empty list is structurally a vector of dimension 0, which cannot match the index's configured embedding_model_dims, so the store fails fast with a message naming the expected dimension rather than letting OpenSearch reject the bulk write.
Source
Thrown at mem0/vector_stores/opensearch.py:170
def insert(
self, vectors: List[List[float]], payloads: Optional[List[Dict]] = None, ids: Optional[List[str]] = None
) -> List[OutputData]:
"""Insert vectors into the index."""
if not ids:
ids = [str(i) for i in range(len(vectors))]
if payloads is None:
payloads = [{} for _ in range(len(vectors))]
for idx, vec in enumerate(vectors):
if vec is None:
raise ValueError(
f"Vector at index {idx} is null. "
f"This usually means the embedding model failed to generate an embedding. "
f"Check that your embedding model is configured correctly and returning valid vectors."
)
if len(vec) == 0:
raise ValueError(
f"Vector at index {idx} is empty. "
f"Expected a vector of dimension {self.embedding_model_dims}, got an empty vector."
)
if len(vec) != self.embedding_model_dims:
raise ValueError(
f"Vector at index {idx} has dimension {len(vec)}, "
f"but the index '{self.collection_name}' expects dimension {self.embedding_model_dims}. "
f"Ensure your embedding model's output dimensions match the vector store configuration."
)
results = []
for i, (vec, id_) in enumerate(zip(vectors, ids)):
body = {
"vector_field": vec,
"payload": payloads[i],
"id": id_,
}
try:View on GitHub (pinned to 001c235229)
Solutions
- Filter out empty inputs before embedding: skip blank documents
- Make the embedder raise on empty input instead of returning []
- Pre-validate vector shapes with the guard below
Example fix
# before
vectors = [embed(t) for t in texts] # embed(" ") -> []
store.insert(vectors, payloads, ids)
# after
texts = [t for t in texts if t and t.strip()]
vectors = [embed(t) for t in texts]
store.insert(vectors, payloads, ids) Defensive patterns
Strategy: validation
Validate before calling
texts = [t for t in texts if t and t.strip()] vectors = [embedder.embed(t) for t in texts] assert all(len(v) > 0 for v in vectors), "empty vector produced" store.insert(vectors=vectors, payloads=payloads[:len(texts)], ids=ids[:len(texts)])
Type guard
def has_no_empty_vectors(vectors) -> bool:
return all(v is not None and len(v) > 0 for v in vectors) Try / catch
try:
store.insert(vectors, payloads, ids)
except ValueError as e:
if "is empty" in str(e):
keep = [i for i, v in enumerate(vectors) if len(v) > 0]
store.insert([vectors[i] for i in keep], [payloads[i] for i in keep], [ids[i] for i in keep])
else:
raise Prevention
- Strip blank/whitespace documents before embedding
- Embedder contract: raise on empty input, never return []
- Unit-test the embedder with edge-case inputs (empty string, whitespace, unicode-only)
When it happens
Trigger: Passing vectors=[[]] — an embedder that returned an empty list (some tokenizers do for whitespace-only input), or a slicing bug producing empty rows.
Common situations: Empty/whitespace strings reaching the embedding pipeline; embedding stubs in tests returning []; off-by-one batching that truncates a vector.
Related errors
- Vector at index ${index} is null or undefined.
- Vector at index ${index} is empty. Expected dimension ${this
- Vector at index ${index} has dimension ${vector.length}, but
- Vector at index {idx} is null. This usually means the embedd
- Cannot update with an empty vector.
AI-assisted analysis of mem0ai/mem0@001c235229 (2026-08-15).
Data as JSON: /api/errors/6cdccac2ef7307d5.
Report an issue: GitHub.