{"record":{"id":"4893efe74cf7adb9","repo":"mem0ai/mem0","slug":"invalid-docstore-key-type-type-key-expected-s","errorCode":null,"errorMessage":"Invalid docstore key type: {type(key)}, expected str","messagePattern":"Invalid docstore key type: (.+?), expected str","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"mem0/vector_stores/faiss.py","lineNumber":107,"sourceCode":"\n    Raises:\n        ValueError: If the data structure is invalid.\n    \"\"\"\n    if not isinstance(data, tuple) or len(data) != 2:\n        raise ValueError(\"Invalid docstore format: expected tuple of (docstore, index_to_id)\")\n\n    docstore, index_to_id = data\n\n    if not isinstance(docstore, dict):\n        raise ValueError(\"Invalid docstore format: docstore must be a dict\")\n\n    if not isinstance(index_to_id, dict):\n        raise ValueError(\"Invalid docstore format: index_to_id must be a dict\")\n\n    # Validate docstore entries\n    for key, value in docstore.items():\n        if not isinstance(key, str):\n            raise ValueError(f\"Invalid docstore key type: {type(key)}, expected str\")\n        if not isinstance(value, dict):\n            raise ValueError(f\"Invalid docstore value type: {type(value)}, expected dict\")\n\n    # Validate index_to_id entries\n    for key, value in index_to_id.items():\n        if not isinstance(key, int):\n            raise ValueError(f\"Invalid index_to_id key type: {type(key)}, expected int\")\n        if not isinstance(value, str):\n            raise ValueError(f\"Invalid index_to_id value type: {type(value)}, expected str\")\n\n    return docstore, index_to_id\n\n\nclass OutputData(BaseModel):\n    id: Optional[str]  # memory id\n    score: Optional[float]  # distance\n    payload: Optional[Dict]  # metadata\n","sourceCodeStart":89,"sourceCodeEnd":125,"githubUrl":"https://github.com/mem0ai/mem0/blob/001c235229be8795e3834520467bd0d661ed8f34/mem0/vector_stores/faiss.py#L89-L125","documentation":"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.","triggerScenarios":"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.","commonSituations":"Importing a docstore generated outside mem0; using uuid objects as keys in a custom pickle; schema drift after a manual data merge.","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"],"exampleFix":"# sanitize before load\nimport json\ndata = json.load(open(p))\ndocstore = {str(k): v for k, v in data[0].items()}\ndata[0] = docstore\njson.dump(data, open(p, 'w'))","handlingStrategy":"validation","validationCode":"bad = [k for k in data[0] if not isinstance(k, str)]\nif bad:\n    data[0] = {str(k): v for k, v in data[0].items()}\n    data[1] = {i: str(vid) for i, vid in data[1].items()}","typeGuard":"def docstore_keys_are_str(d) -> bool:\n    return isinstance(d, dict) and all(isinstance(k, str) for k in d)","tryCatchPattern":null,"preventionTips":["Let mem0 generate ids (str(uuid4())) instead of supplying custom non-string ids","Sanitize external data before importing into a docstore"],"tags":["faiss","vector-store","data-validation"],"backgroundTag":null,"analyzedSha":"001c235229be8795e3834520467bd0d661ed8f34","analyzedAt":"2026-08-15T01:55:42.685Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}