{"record":{"id":"afa9fb4bae43db6d","repo":"mem0ai/mem0","slug":"cannot-update-with-an-empty-vector","errorCode":null,"errorMessage":"Cannot update with an empty vector.","messagePattern":"Cannot update with an empty vector\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"mem0/vector_stores/opensearch.py","lineNumber":323,"sourceCode":"        # 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\"]\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","sourceCodeStart":305,"sourceCodeEnd":341,"githubUrl":"https://github.com/mem0ai/mem0/blob/001c235229be8795e3834520467bd0d661ed8f34/mem0/vector_stores/opensearch.py#L305-L341","documentation":"update() in the OpenSearch store refuses an explicitly supplied empty vector (len 0). Unlike None (meaning 'keep existing'), an empty list is a real value that cannot be indexed, so it fails fast before searching for the document. It pairs with the dimension check immediately after it.","triggerScenarios":"update(vector_id=X, vector=[]) — usually an embedding call that returned an empty list for the new text, or a placeholder that mistakenly defaults to [] instead of None.","commonSituations":"Re-embedding code paths where the new text is blank; stub/mock embedders returning []; passing [] intending 'no change' when None is required.","solutions":["Pass vector=None when you do not want to change the embedding","If updating the embedding, supply a full-length vector: vector=embed(new_text)","Guard the embedder to raise on empty output instead of returning []"],"exampleFix":"# before\nstore.update(vector_id=vid, vector=[], payload=p)\n\n# after\nstore.update(vector_id=vid, vector=embed(p[\"data\"]) if p.get(\"data\") else None, payload=p)","handlingStrategy":"validation","validationCode":"if vector is not None and len(vector) == 0:\n    vector = None  # interpret as 'no embedding change'\nstore.update(vector_id=vector_id, vector=vector, payload=payload)","typeGuard":"def is_valid_update_vector(v) -> bool:\n    return v is None or (isinstance(v, list) and len(v) > 0)","tryCatchPattern":"try:\n    store.update(vector_id=vid, vector=vec, payload=p)\nexcept ValueError as e:\n    if \"empty vector\" in str(e):\n        store.update(vector_id=vid, vector=None, payload=p)\n    else:\n        raise","preventionTips":["Use None to mean 'keep existing embedding', never []","Make the embedder raise on empty output","Encode the distinction (None vs empty) in your update API types"],"tags":["opensearch","embeddings","validation","update"],"backgroundTag":null,"analyzedSha":"001c235229be8795e3834520467bd0d661ed8f34","analyzedAt":"2026-08-15T01:55:42.685Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}