mem0ai/mem0 · error · ValueError
Invalid docstore key type: {type(key)}, expected str
Error message
Invalid docstore key type: {type(key)}, expected str What it means
Raised while validating each entry of the loaded docstore: a key (the memory id) is not a str. Mem0 requires string ids because they are also the payload lookup keys after load. ValueError surfaced during FAISS load.
Source
Thrown at mem0/vector_stores/faiss.py:107
Raises:
ValueError: If the data structure is invalid.
"""
if not isinstance(data, tuple) or len(data) != 2:
raise ValueError("Invalid docstore format: expected tuple of (docstore, index_to_id)")
docstore, index_to_id = data
if not isinstance(docstore, dict):
raise ValueError("Invalid docstore format: docstore must be a dict")
if not isinstance(index_to_id, dict):
raise ValueError("Invalid docstore format: index_to_id must be a dict")
# Validate docstore entries
for key, value in docstore.items():
if not isinstance(key, str):
raise ValueError(f"Invalid docstore key type: {type(key)}, expected str")
if not isinstance(value, dict):
raise ValueError(f"Invalid docstore value type: {type(value)}, expected dict")
# Validate index_to_id entries
for key, value in index_to_id.items():
if not isinstance(key, int):
raise ValueError(f"Invalid index_to_id key type: {type(key)}, expected int")
if not isinstance(value, str):
raise ValueError(f"Invalid index_to_id value type: {type(value)}, expected str")
return docstore, index_to_id
class OutputData(BaseModel):
id: Optional[str] # memory id
score: Optional[float] # distance
payload: Optional[Dict] # metadata
View on GitHub (pinned to 001c235229)
Solutions
- Sanitize the file: stringify all docstore keys (and matching index_to_id values) before loading
- Regenerate the store through mem0's API so ids are always str(uuid4())
- Delete the store and re-add memories if the data is reproducible
Example fix
# sanitize before load
import json
data = json.load(open(p))
docstore = {str(k): v for k, v in data[0].items()}
data[0] = docstore
json.dump(data, open(p, 'w')) Defensive patterns
Strategy: validation
Validate before calling
bad = [k for k in data[0] if not isinstance(k, str)]
if bad:
data[0] = {str(k): v for k, v in data[0].items()}
data[1] = {i: str(vid) for i, vid in data[1].items()} Type guard
def docstore_keys_are_str(d) -> bool:
return isinstance(d, dict) and all(isinstance(k, str) for k in d) Prevention
- Let mem0 generate ids (str(uuid4())) instead of supplying custom non-string ids
- Sanitize external data before importing into a docstore
When it happens
Trigger: A persisted docstore dict containing non-string keys, e.g. integer ids from an externally built file or JSON keys that were coerced to numbers by another tool and re-serialized via pickle.
Common situations: Importing a docstore generated outside mem0; using uuid objects as keys in a custom pickle; schema drift after a manual data merge.
Related errors
- Invalid docstore value type: {type(value)}, expected dict
- Invalid index_to_id value type: {type(value)}, expected str
- Invalid distance_strategy. Must be one of: 'euclidean', 'inn
- Extra fields not allowed: {', '.join(extra_fields)}. Please
- Invalid docstore format: expected tuple of (docstore, index_
AI-assisted analysis of mem0ai/mem0@001c235229 (2026-08-15).
Data as JSON: /api/errors/4893efe74cf7adb9.
Report an issue: GitHub.