{"record":{"id":"c5a698cb515ecfa0","repo":"mem0ai/mem0","slug":"update-vector-has-dimension-len-vector-but-the","errorCode":null,"errorMessage":"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.","messagePattern":"Update vector has dimension (.+?), but the index '(.+?)' expects dimension (.+?)\\. Ensure your embedding model's output dimensions match the vector store configuration\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"mem0/vector_stores/opensearch.py","lineNumber":325,"sourceCode":"\n        response = self.client.search(index=self.collection_name, body=search_query)\n        hits = response.get(\"hits\", {}).get(\"hits\", [])\n\n        if not hits:\n            return\n\n        opensearch_id = hits[0][\"_id\"]\n\n        # Delete using the actual document ID\n        self.client.delete(index=self.collection_name, id=opensearch_id)\n\n    def update(self, vector_id: str, vector: Optional[List[float]] = None, payload: Optional[Dict] = None) -> None:\n        \"\"\"Update a vector and its payload using the custom 'id' field.\"\"\"\n        if vector is not None:\n            if len(vector) == 0:\n                raise ValueError(\"Cannot update with an empty vector.\")\n            if len(vector) != self.embedding_model_dims:\n                raise ValueError(\n                    f\"Update vector has dimension {len(vector)}, \"\n                    f\"but the index '{self.collection_name}' expects dimension {self.embedding_model_dims}. \"\n                    f\"Ensure your embedding model's output dimensions match the vector store configuration.\"\n                )\n\n        # First, find the document by custom ID\n        search_query = {\"query\": {\"term\": {\"id\": vector_id}}}\n\n        response = self.client.search(index=self.collection_name, body=search_query)\n        hits = response.get(\"hits\", {}).get(\"hits\", [])\n\n        if not hits:\n            return\n\n        opensearch_id = hits[0][\"_id\"]  # The actual document ID in OpenSearch\n\n        # Prepare updated fields\n        doc = {}","sourceCodeStart":307,"sourceCodeEnd":343,"githubUrl":"https://github.com/mem0ai/mem0/blob/001c235229be8795e3834520467bd0d661ed8f34/mem0/vector_stores/opensearch.py#L307-L343","documentation":"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.","triggerScenarios":"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.","commonSituations":"Same drift causes as insert: provider switch, dims typo in config, multi-tenant setups where one index is shared across models with different dimensions.","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)"],"exampleFix":"# before\nstore.update(vector_id=vid, vector=small_model_embed(text), payload=p)  # 768 vs 1536 index\n\n# after\nstore.update(vector_id=vid, vector=embed(text), payload=p)  # same model/dims as index","handlingStrategy":"type-guard","validationCode":"if vector is not None and len(vector) != store.embedding_model_dims:\n    raise ValueError(f\"update vector is {len(vector)}-dim; index expects {store.embedding_model_dims}\")\nstore.update(vector_id=vector_id, vector=vector, payload=payload)","typeGuard":"def update_dims_ok(vector, dims: int) -> bool:\n    return vector is None or len(vector) == dims","tryCatchPattern":"try:\n    store.update(vector_id=vid, vector=vec, payload=p)\nexcept ValueError as e:\n    if \"expects dimension\" in str(e):\n        vec = embed(text)  # re-embed with the index-matching model\n        store.update(vector_id=vid, vector=vec, payload=p)\n    else:\n        raise","preventionTips":["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"],"tags":["opensearch","dimension-mismatch","configuration","update","embeddings"],"backgroundTag":null,"analyzedSha":"001c235229be8795e3834520467bd0d661ed8f34","analyzedAt":"2026-08-15T01:55:42.685Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}