{"record":{"id":"158fd09a51cf312a","repo":"mem0ai/mem0","slug":"invalid-docstore-value-type-type-value-expect","errorCode":null,"errorMessage":"Invalid docstore value type: {type(value)}, expected dict","messagePattern":"Invalid docstore value type: (.+?), expected dict","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"mem0/vector_stores/faiss.py","lineNumber":109,"sourceCode":"        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\n\nclass FAISS(VectorStoreBase):","sourceCodeStart":91,"sourceCodeEnd":127,"githubUrl":"https://github.com/mem0ai/mem0/blob/001c235229be8795e3834520467bd0d661ed8f34/mem0/vector_stores/faiss.py#L91-L127","documentation":"Raised while validating docstore entries: a value (the payload) is not a dict. Every docstore entry must map an id to a payload dict (the memory metadata). ValueError raised during FAISS load.","triggerScenarios":"A persisted docstore where a payload is a string, list, or LangChain Document instead of a dict — typically from converting another framework's FAISS store to mem0's format.","commonSituations":"Langchain-to-mem0 migrations where Document objects were serialized raw; hand-crafted JSON payloads; partial schema changes between versions.","solutions":["Convert each non-dict payload to a dict (e.g. {'text': doc.page_content, 'metadata': doc.metadata}) in a migration script","Delete and rebuild the store via mem0 add() calls","Validate the file offline with a loop asserting isinstance(v, dict) before constructing FAISS"],"exampleFix":"# before\n# payload stored as a raw string\n# after\npayloads = {k: (v if isinstance(v, dict) else {'data': v}) for k, v in docstore.items()}","handlingStrategy":"validation","validationCode":"data[0] = {k: (v if isinstance(v, dict) else {'data': v}) for k, v in data[0].items()}","typeGuard":"def docstore_values_are_dicts(d) -> bool:\n    return isinstance(d, dict) and all(isinstance(v, dict) for v in d.values())","tryCatchPattern":null,"preventionTips":["Store only plain-dict payloads via mem0's add API","Convert foreign Document objects to dicts during migrations"],"tags":["faiss","vector-store","data-validation","migration"],"backgroundTag":null,"analyzedSha":"001c235229be8795e3834520467bd0d661ed8f34","analyzedAt":"2026-08-15T01:55:42.685Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}