{"record":{"id":"8da3a1e214c4fbaa","repo":"mem0ai/mem0","slug":"invalid-docstore-format-docstore-must-be-a-dict","errorCode":null,"errorMessage":"Invalid docstore format: docstore must be a dict","messagePattern":"Invalid docstore format: docstore must be a dict","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"mem0/vector_stores/faiss.py","lineNumber":99,"sourceCode":"    \"\"\"\n    Validate that loaded data has the expected structure.\n\n    Args:\n        data: The loaded data to validate.\n\n    Returns:\n        Tuple of (docstore, index_to_id) if valid.\n\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","sourceCodeStart":81,"sourceCodeEnd":117,"githubUrl":"https://github.com/mem0ai/mem0/blob/001c235229be8795e3834520467bd0d661ed8f34/mem0/vector_stores/faiss.py#L81-L117","documentation":"Raised by _validate_docstore_structure() when the first element of the loaded (docstore, index_to_id) tuple is not a dict. The docstore maps memory-id -> payload dict; a non-dict means the pickle/JSON was tampered with or written by incompatible code. Raised during FAISS load as a ValueError.","triggerScenarios":"Loading a docstore tuple where data[0] is a list, string, or LangChain Docstore object instead of a plain dict — typically a legacy file produced by langchain_community FAISS serialization rather than mem0's own.","commonSituations":"Migrating a FAISS index saved via langchain's FAISS.save_local (whose docstore is a Docstore instance) into mem0's FAISS vector store; hand-editing the JSON file.","solutions":["Convert the foreign docstore to a plain dict before importing (dict(docstore) with str keys and dict values)","Delete the incompatible file and rebuild via mem0 adds","Write a one-off migration script that reads the old format and emits mem0's [docstore_dict, index_to_id_dict] JSON"],"exampleFix":"# before\n# file saved by langchain FAISS.save_local -> docstore is Docstore, not dict\nvs = FAISS(config)  # ValueError: docstore must be a dict\n\n# after\n# migration: dump as plain dict in mem0's expected shape\nimport json\njson.dump([dict(docstore), index_to_id], open('faiss.docstore.json', 'w'))","handlingStrategy":"type-guard","validationCode":"import json\ndata = json.load(open(p))\nassert isinstance(data[0], dict), 'docstore must be a plain dict — convert Docstore objects first'","typeGuard":"def is_plain_dict_docstore(data) -> bool:\n    return isinstance(data, (tuple, list)) and len(data) == 2 and isinstance(data[0], dict)","tryCatchPattern":null,"preventionTips":["When importing langchain FAISS stores, convert Docstore to dict(docstore) explicitly","Keep migration scripts that emit mem0's exact [dict, dict] shape"],"tags":["faiss","vector-store","serialization","migration"],"backgroundTag":null,"analyzedSha":"001c235229be8795e3834520467bd0d661ed8f34","analyzedAt":"2026-08-15T01:55:42.685Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}