{"record":{"id":"718d06ba8874dca7","repo":"mem0ai/mem0","slug":"invalid-docstore-format-index-to-id-must-be-a-dic","errorCode":null,"errorMessage":"Invalid docstore format: index_to_id must be a dict","messagePattern":"Invalid docstore format: index_to_id must be a dict","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"mem0/vector_stores/faiss.py","lineNumber":102,"sourceCode":"    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\n    return docstore, index_to_id\n\n","sourceCodeStart":84,"sourceCodeEnd":120,"githubUrl":"https://github.com/mem0ai/mem0/blob/001c235229be8795e3834520467bd0d661ed8f34/mem0/vector_stores/faiss.py#L84-L120","documentation":"Raised by _validate_docstore_structure() when the second element of the loaded tuple, index_to_id (faiss row -> memory id), is not a dict. This mapping is what ties FAISS row numbers to payload ids; a non-dict means incompatible or corrupt persistence. ValueError raised at load time.","triggerScenarios":"Loading a persisted docstore where data[1] is a list, None, or other non-dict — e.g. a JSON file edited to remove the second element, or a pickle from a different schema.","commonSituations":"Hand-migrating JSON docstores between environments; version drift between mem0 releases that changed the tuple layout; truncated files.","solutions":["Inspect the persisted file and confirm element [1] is an object mapping integer-like keys to id strings","Restore from backup or delete the file and rebuild the index","Regenerate index_to_id by re-adding all memories in the same order"],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":"import json\ndata = json.load(open(p))\nassert isinstance(data[1], dict), 'index_to_id must be a dict of row -> id'","typeGuard":"def is_valid_index_to_id(x) -> bool:\n    return isinstance(x, dict) and all(isinstance(k, int) and isinstance(v, str) for k, v in x.items())","tryCatchPattern":null,"preventionTips":["Always persist and migrate docstore and index_to_id as a pair","Automate format checks in CI for any data migration scripts"],"tags":["faiss","vector-store","serialization","data-corruption"],"backgroundTag":null,"analyzedSha":"001c235229be8795e3834520467bd0d661ed8f34","analyzedAt":"2026-08-15T01:55:42.685Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}