mem0ai/mem0 · error · ValueError
Update vector has dimension {len(vector)}, but the index '{s
Error message
Update vector has dimension {len(vector)}, but the index '{self.collection_name}' expects dimension {self.embedding_model_dims}. Ensure your embedding model's output dimensions match the vector store configuration. What it means
update() checks a supplied vector's length against the index's embedding_model_dims before modifying the document. The OpenSearch knn_vector field is fixed-dimension, so an update with a different-size vector would be rejected by the server after the lookup; this moves the failure to the caller with a clear message.
Source
Thrown at mem0/vector_stores/opensearch.py:325
response = self.client.search(index=self.collection_name, body=search_query)
hits = response.get("hits", {}).get("hits", [])
if not hits:
return
opensearch_id = hits[0]["_id"]
# Delete using the actual document ID
self.client.delete(index=self.collection_name, id=opensearch_id)
def update(self, vector_id: str, vector: Optional[List[float]] = None, payload: Optional[Dict] = None) -> None:
"""Update a vector and its payload using the custom 'id' field."""
if vector is not None:
if len(vector) == 0:
raise ValueError("Cannot update with an empty vector.")
if len(vector) != self.embedding_model_dims:
raise ValueError(
f"Update vector has dimension {len(vector)}, "
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."
)
# First, find the document by custom ID
search_query = {"query": {"term": {"id": vector_id}}}
response = self.client.search(index=self.collection_name, body=search_query)
hits = response.get("hits", {}).get("hits", [])
if not hits:
return
opensearch_id = hits[0]["_id"] # The actual document ID in OpenSearch
# Prepare updated fields
doc = {}View on GitHub (pinned to 001c235229)
Solutions
- Make the update vector come from the same embedding model (and dims) as the index
- Fix the dimension configs and recreate the index if the model genuinely changed
- Pre-check len(vector) == embedding_model_dims before calling update (see guard below)
Example fix
# before store.update(vector_id=vid, vector=small_model_embed(text), payload=p) # 768 vs 1536 index # after store.update(vector_id=vid, vector=embed(text), payload=p) # same model/dims as index
Defensive patterns
Strategy: type-guard
Validate before calling
if vector is not None and len(vector) != store.embedding_model_dims:
raise ValueError(f"update vector is {len(vector)}-dim; index expects {store.embedding_model_dims}")
store.update(vector_id=vector_id, vector=vector, payload=payload) Type guard
def update_dims_ok(vector, dims: int) -> bool:
return vector is None or len(vector) == dims Try / catch
try:
store.update(vector_id=vid, vector=vec, payload=p)
except ValueError as e:
if "expects dimension" in str(e):
vec = embed(text) # re-embed with the index-matching model
store.update(vector_id=vid, vector=vec, payload=p)
else:
raise Prevention
- Always re-embed update text with the same model that built the index
- Single source of truth for dimension config across embedding and vector store
- Rebuild the index when the embedding model changes; do not mix old and new vectors
When it happens
Trigger: update(vector_id=X, vector=<768-dim>) on an index created with embedding_model_dims=1536, or any embedding model/config change made after index creation without re-indexing.
Common situations: Same drift causes as insert: provider switch, dims typo in config, multi-tenant setups where one index is shared across models with different dimensions.
Related errors
- Vector at index {idx} has dimension {len(vec)}, but the inde
- Baidu Mochow table '${label}' stores ${dimension}-dimensiona
- Vector dimension mismatch. Expected ${this.dimension}, got $
- Vector at index ${index} has dimension ${vector.length}, but
- Cannot update with an empty vector.
AI-assisted analysis of mem0ai/mem0@001c235229 (2026-08-15).
Data as JSON: /api/errors/c5a698cb515ecfa0.
Report an issue: GitHub.