{"record":{"id":"b242aa50abb74bc2","repo":"mem0ai/mem0","slug":"delete-failed-for-document-vector-id-doc","errorCode":null,"errorMessage":"Delete failed for document {vector_id}: {doc}","messagePattern":"Delete failed for document (.+?): (.+?)","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"mem0/vector_stores/azure_ai_search.py","lineNumber":294,"sourceCode":"        )\n\n        results = []\n        for result in search_results:\n            payload = json.loads(extract_json(result[\"payload\"]))\n            results.append(OutputData(id=result[\"id\"], score=result[\"@search.score\"], payload=payload))\n        return results\n\n    def delete(self, vector_id):\n        \"\"\"\n        Delete a vector by ID.\n\n        Args:\n            vector_id (str): ID of the vector to delete.\n        \"\"\"\n        response = self.search_client.delete_documents(documents=[{\"id\": vector_id}])\n        for doc in response:\n            if not hasattr(doc, \"status_code\") and doc.get(\"status_code\") != 200:\n                raise Exception(f\"Delete failed for document {vector_id}: {doc}\")\n        logger.info(f\"Deleted document with ID '{vector_id}' from index '{self.index_name}'.\")\n        return response\n\n    def update(self, vector_id, 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        document = {\"id\": vector_id}\n        if vector is not None:\n            document[\"vector\"] = vector\n        if payload is not None:\n            json_payload = json.dumps(payload)\n            document[\"payload\"] = json_payload","sourceCodeStart":276,"sourceCodeEnd":312,"githubUrl":"https://github.com/mem0ai/mem0/blob/001c235229be8795e3834520467bd0d661ed8f34/mem0/vector_stores/azure_ai_search.py#L276-L312","documentation":"Raised by AzureAISearch.delete after search_client.delete_documents returns a non-success response for the given vector_id. Deletion fails when the document does not exist under that exact id, the id contains characters the index key rejects, the credential lacks delete permissions, or the service is throttling. As with insert, the guard only fires for dict-like responses without a status_code attribute, so a raise here reflects a real server-side rejection reported in the doc dict.","triggerScenarios":"Calling memory.delete(memory_id) where the memory was already deleted or its id was reformatted; concurrent deletes racing each other; API-key scoped to read-only; index recreated so old ids no longer exist.","commonSituations":"Retrying an already-completed delete from a queue consumer; id mismatch after migrating stores; RBAC/Key permissions missing the delete action.","solutions":["Inspect the doc dict in the exception for the HTTP status (404 → already gone, 403 → permissions, 429 → throttle)","Make delete idempotent: catch the error, verify with get(vector_id) that it is gone, and treat 404 as success","Check the API key/RBAC has Documents.Read/Write (delete) on the index","For races, deduplicate delete requests by id before dispatching"],"exampleFix":"# before\nmemory.delete(memory_id)  # Delete failed for document ...\n\n# after\ndef safe_delete(memory, memory_id):\n    try:\n        memory.delete(memory_id)\n    except Exception:\n        if memory.get(memory_id) is None:\n            return  # already gone\n        raise","handlingStrategy":"try-catch","validationCode":"def delete_is_safe(memory, memory_id) -> bool:\n    return memory.get(memory_id) is not None  # skip no-op deletes","typeGuard":null,"tryCatchPattern":"try:\n    memory.delete(memory_id)\nexcept Exception as e:\n    if 'Delete failed for document' in str(e):\n        if memory.get(memory_id) is None:\n            return  # idempotent success\n        raise\n    raise","preventionTips":["Make delete flows idempotent: treat 'already absent' as success after verifying with get()","Scope API keys/RBAC to include delete permission up front","Deduplicate delete requests by id in queue consumers to avoid races"],"tags":["azure","vector-store","delete","idempotency"],"backgroundTag":null,"analyzedSha":"001c235229be8795e3834520467bd0d661ed8f34","analyzedAt":"2026-08-15T01:55:42.685Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}