{"record":{"id":"e08282a9d5f58f94","repo":"mem0ai/mem0","slug":"update-failed-for-document-vector-id-doc","errorCode":null,"errorMessage":"Update failed for document {vector_id}: {doc}","messagePattern":"Update failed for document (.+?): (.+?)","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"mem0/vector_stores/azure_ai_search.py","lineNumber":318,"sourceCode":"        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\n            for field in [\"user_id\", \"run_id\", \"agent_id\"]:\n                document[field] = payload.get(field)\n        response = self.search_client.merge_or_upload_documents(documents=[document])\n        for doc in response:\n            if not hasattr(doc, \"status_code\") and doc.get(\"status_code\") != 200:\n                raise Exception(f\"Update failed for document {vector_id}: {doc}\")\n        return response\n\n    def get(self, vector_id) -> OutputData:\n        \"\"\"\n        Retrieve a vector by ID.\n\n        Args:\n            vector_id (str): ID of the vector to retrieve.\n\n        Returns:\n            OutputData: Retrieved vector.\n        \"\"\"\n        try:\n            result = self.search_client.get_document(key=vector_id)\n        except ResourceNotFoundError:\n            return None\n        payload = json.loads(extract_json(result[\"payload\"]))\n        return OutputData(id=result[\"id\"], score=None, payload=payload)","sourceCodeStart":300,"sourceCodeEnd":336,"githubUrl":"https://github.com/mem0ai/mem0/blob/001c235229be8795e3834520467bd0d661ed8f34/mem0/vector_stores/azure_ai_search.py#L300-L336","documentation":"Raised by AzureAISearch.update after merge_or_upload_documents returns a non-success status for vector_id. update() rebuilds the document from vector/payload and merges it into the existing index doc; failures typically stem from schema violations (vector length ≠ index dimension, payload JSON not valid for the field), a missing pre-existing document when merge semantics require it, or throttling/auth. The guard only triggers on dict-like responses lacking status_code, so a raise means a genuine rejection captured in doc.","triggerScenarios":"Calling memory.update(memory_id, data) after changing embedding models so the new vector dimension mismatches the index field; payload containing non-JSON-serializable objects that json.dumps renders incompatibly; concurrent updates on the same id exceeding etag/ordering constraints; throttled bulk update loops.","commonSituations":"Embedding-model migration without index recreation; updating memories whose payload grew beyond field limits; background jobs updating many memories in tight loops hitting QPS caps.","solutions":["Inspect the doc dict status: 400 → schema/dimension mismatch, 429 → throttle, 403 → auth","If vector dims changed, recreate the index with the new embedding_model_dims and re-add data","Serialize payloads to plain JSON types before update; strip non-serializable fields","Add backoff/retry and batch pacing for bulk updates"],"exampleFix":"# before\nmemory.update(memory_id, data)  # Update failed for document ...\n\n# after: after switching embedders, rebuild the index\ncfg['vector_store']['config']['collection_name'] = 'mem0_idx_v2'\ncfg['vector_store']['config']['embedding_model_dims'] = 1536\nmemory = Memory.from_config(cfg)  # create_col builds correct schema","handlingStrategy":"retry","validationCode":"# guard dimension drift before updates\nemb_dims = 1536\nif index_vector_dim != emb_dims:\n    raise ConfigError('recreate index before updating with the new embedder')","typeGuard":null,"tryCatchPattern":"import time\nfor attempt in range(5):\n    try:\n        memory.update(memory_id, data)\n        break\n    except Exception as e:\n        if 'Update failed for document' in str(e) and attempt < 4:\n            time.sleep(2 ** attempt)\n            continue\n        raise","preventionTips":["Recreate the index after embedding-model changes; do not update into a stale schema","Keep payloads JSON-serializable (no datetime/objects) before update","Pace bulk update jobs and add exponential backoff","Log the doc dict from the exception to triage 400 vs 429 vs 403"],"tags":["azure","vector-store","update","schema-mismatch"],"backgroundTag":null,"analyzedSha":"001c235229be8795e3834520467bd0d661ed8f34","analyzedAt":"2026-08-15T01:55:42.685Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}