{"record":{"id":"350eb904bf9b2aa8","repo":"mem0ai/mem0","slug":"vector-vector-id-not-found","errorCode":null,"errorMessage":"Vector {vector_id} not found","messagePattern":"Vector (.+?) not found","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"mem0/vector_stores/faiss.py","lineNumber":504,"sourceCode":"    def update(\n        self,\n        vector_id: str,\n        vector: Optional[List[float]] = None,\n        payload: Optional[Dict] = None,\n    ):\n        \"\"\"\n        Update a vector and its payload.\n\n        Args:\n            vector_id (str): ID of the vector to update.\n            vector (Optional[List[float]], optional): Updated vector. Defaults to None.\n            payload (Optional[Dict], optional): Updated payload. Defaults to None.\n        \"\"\"\n        if self.index is None:\n            raise ValueError(\"Collection not initialized. Call create_col first.\")\n\n        if vector_id not in self.docstore:\n            raise ValueError(f\"Vector {vector_id} not found\")\n\n        current_payload = self.docstore[vector_id].copy()\n\n        if payload is not None:\n            self.docstore[vector_id] = payload.copy()\n            current_payload = self.docstore[vector_id].copy()\n\n        if vector is not None:\n            self.delete(vector_id)\n            self.insert([vector], [current_payload], [vector_id])\n        else:\n            self._save()\n\n        logger.info(f\"Updated vector {vector_id} in collection {self.collection_name}\")\n\n    def get(self, vector_id: str) -> OutputData:\n        \"\"\"\n        Retrieve a vector by ID.","sourceCodeStart":486,"sourceCodeEnd":522,"githubUrl":"https://github.com/mem0ai/mem0/blob/001c235229be8795e3834520467bd0d661ed8f34/mem0/vector_stores/faiss.py#L486-L522","documentation":"FAISS.update() raises ValueError when the given vector_id has no entry in the docstore — you cannot update a memory the store never held (or that was already deleted). The check happens before any payload merge.","triggerScenarios":"Updating an id after it was deleted in the same session (delete rebuilds index_to_id and removes the docstore entry); stale ids cached in application memory; ids from a different collection/user scope.","commonSituations":"Race between delete and update in concurrent workers; multi-tenant stores where the id exists for another user_id; retrying an update after the record was garbage-collected.","solutions":["Check existence first: vs.get(vector_id) returns None for missing ids","Re-fetch current memory ids (list/search) before updating","Serialize delete/update per memory id, or use a per-id lock in concurrent pipelines"],"exampleFix":"# before\nvs.update(vector_id, payload=new_payload)  # ValueError: Vector ... not found\n\n# after\nif vs.get(vector_id) is not None:\n    vs.update(vector_id, payload=new_payload)\nelse:\n    vs.insert([vector], [new_payload], [vector_id])","handlingStrategy":"type-guard","validationCode":"if vs.get(vector_id) is None:\n    # absent: insert instead of update\n    pass","typeGuard":"def memory_exists(vs, vector_id: str) -> bool:\n    return vs.get(vector_id) is not None","tryCatchPattern":"try:\n    vs.update(vector_id, payload=p)\nexcept ValueError as e:\n    if 'not found' in str(e):\n        vs.insert([vec], [p], [vector_id])  # upsert fallback\n    else:\n        raise","preventionTips":["Check existence with get() before update (implement upsert yourself)","Refresh cached ids after deletes; serialize delete/update per id in concurrent flows"],"tags":["faiss","vector-store","update","missing-record"],"backgroundTag":null,"analyzedSha":"001c235229be8795e3834520467bd0d661ed8f34","analyzedAt":"2026-08-15T01:55:42.685Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}