{"record":{"id":"2b1b652e525dcfec","repo":"mem0ai/mem0","slug":"vector-with-id-vector-id-not-found-in-collection","errorCode":null,"errorMessage":"Vector with id {vector_id} not found in collection {self.collection_name}","messagePattern":"Vector with id (.+?) not found in collection (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"mem0/vector_stores/milvus.py","lineNumber":293,"sourceCode":"\n        Args:\n            vector_id (str): ID of the vector to delete.\n        \"\"\"\n        self.client.delete(collection_name=self.collection_name, ids=[vector_id])\n\n    def update(self, vector_id=None, vector=None, payload=None):\n        \"\"\"\n        Update a vector and its payload.\n\n        Args:\n            vector_id (str): ID of the vector to update.\n            vector (List[float], optional): Updated vector.\n            payload (Dict, optional): Updated payload.\n        \"\"\"\n        if vector is None or payload is None:\n            existing = self.client.get(collection_name=self.collection_name, ids=vector_id)\n            if not existing:\n                raise ValueError(f\"Vector with id {vector_id} not found in collection {self.collection_name}\")\n            if vector is None:\n                vector = existing[0].get(\"vectors\")\n                if vector is None:\n                    raise ValueError(f\"Existing record {vector_id} has no vector data\")\n            if payload is None:\n                payload = existing[0].get(\"metadata\")\n\n        schema = {\"id\": vector_id, \"vectors\": vector, \"metadata\": payload}\n        if self._has_bm25_schema:\n            text = \"\"\n            if payload:\n                text = (payload.get(\"text_lemmatized\") or payload.get(\"data\", \"\"))[:65535]\n            schema[\"text\"] = text\n        self.client.upsert(collection_name=self.collection_name, data=schema)\n\n    def get(self, vector_id) -> Optional[OutputData]:\n        \"\"\"\n        Retrieve a vector by ID.","sourceCodeStart":275,"sourceCodeEnd":311,"githubUrl":"https://github.com/mem0ai/mem0/blob/001c235229be8795e3834520467bd0d661ed8f34/mem0/vector_stores/milvus.py#L275-L311","documentation":"Raised by MilvusVectorStore.update() when only one of vector/payload is supplied, so the store must fetch the existing record to fill in the other, but the Milvus client returns no entity for that vector_id in the configured collection. It is a precondition failure: the update path cannot reconstruct the full record because nothing exists under that ID.","triggerScenarios":"Calling mem0's Milvus vector store update(vector_id=..., vector=None or payload=None) after the memory was deleted, after a collection reset/recreation, or with an ID from a different collection/environment. Also occurs when MilvusGetResult comes back empty because the flush/consistency lag means the record is not yet visible.","commonSituations":"Stale memory IDs held by an application after Mem0's memory history was cleared; pointing the vector store config at a different collection name or Milvus instance than the one that wrote the data; updating a memory immediately after insertion before consistency kicks in.","solutions":["Verify the record exists first: call vector_store.get(vector_id) and handle a None result before updating","Check that collection_name in the Milvus config matches the collection the original insert targeted","If the memory was deleted upstream, drop the stale reference instead of updating it","For very fresh writes, retry the update after the Milvus flush/consistency interval"],"exampleFix":"// before\nstore.update(vector_id=memory_id, payload=new_payload)\n\n// after\nif store.get(memory_id) is None:\n    raise KeyError(f\"memory {memory_id} no longer exists; refresh history\")\nstore.update(vector_id=memory_id, payload=new_payload)","handlingStrategy":"validation","validationCode":"existing = milvus_store.get(vector_id)\nif existing is None:\n    raise KeyError(f\"vector {vector_id} not found; cannot partial-update\")\nmilvus_store.update(vector_id=vector_id, vector=vec, payload=payload)","typeGuard":null,"tryCatchPattern":"try:\n    store.update(vector_id=vid, payload=p)\nexcept ValueError as e:\n    if \"not found in collection\" in str(e):\n        # treat as deleted upstream: drop stale reference, re-add instead of update\n        store.insert(vectors=[vec], payloads=[p], ids=[vid])\n    else:\n        raise","preventionTips":["Check existence with get() before any partial update","Persist collection_name with stored IDs so they are always used against the same collection","After deleting memories, invalidate cached memory IDs in the application layer"],"tags":["milvus","vector-store","stale-id","data-integrity"],"backgroundTag":null,"analyzedSha":"001c235229be8795e3834520467bd0d661ed8f34","analyzedAt":"2026-08-15T01:55:42.685Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}