mem0ai/mem0 · error · Exception
Update failed for document {vector_id}: {doc}
Error message
Update failed for document {vector_id}: {doc} What it means
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.
Source
Thrown at mem0/vector_stores/azure_ai_search.py:318
Update a vector and its payload.
Args:
vector_id (str): ID of the vector to update.
vector (List[float], optional): Updated vector.
payload (Dict, optional): Updated payload.
"""
document = {"id": vector_id}
if vector is not None:
document["vector"] = vector
if payload is not None:
json_payload = json.dumps(payload)
document["payload"] = json_payload
for field in ["user_id", "run_id", "agent_id"]:
document[field] = payload.get(field)
response = self.search_client.merge_or_upload_documents(documents=[document])
for doc in response:
if not hasattr(doc, "status_code") and doc.get("status_code") != 200:
raise Exception(f"Update failed for document {vector_id}: {doc}")
return response
def get(self, vector_id) -> OutputData:
"""
Retrieve a vector by ID.
Args:
vector_id (str): ID of the vector to retrieve.
Returns:
OutputData: Retrieved vector.
"""
try:
result = self.search_client.get_document(key=vector_id)
except ResourceNotFoundError:
return None
payload = json.loads(extract_json(result["payload"]))
return OutputData(id=result["id"], score=None, payload=payload)View on GitHub (pinned to 001c235229)
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
Example fix
# before memory.update(memory_id, data) # Update failed for document ... # after: after switching embedders, rebuild the index cfg['vector_store']['config']['collection_name'] = 'mem0_idx_v2' cfg['vector_store']['config']['embedding_model_dims'] = 1536 memory = Memory.from_config(cfg) # create_col builds correct schema
Defensive patterns
Strategy: retry
Validate before calling
# guard dimension drift before updates
emb_dims = 1536
if index_vector_dim != emb_dims:
raise ConfigError('recreate index before updating with the new embedder') Try / catch
import time
for attempt in range(5):
try:
memory.update(memory_id, data)
break
except Exception as e:
if 'Update failed for document' in str(e) and attempt < 4:
time.sleep(2 ** attempt)
continue
raise Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Insert failed for document ${result.key}: ${result.errorMess
- Update failed for document ${vectorId}: ${result.errorMessag
- Insert failed for document {doc.get('id')}: {doc}
- Delete failed for document ${vectorId}: ${result.errorMessag
- Baidu Mochow table '${label}' exists but is missing the id/d
AI-assisted analysis of mem0ai/mem0@001c235229 (2026-08-15).
Data as JSON: /api/errors/e08282a9d5f58f94.
Report an issue: GitHub.