{"record":{"id":"5ea543aa7b62c557","repo":"mem0ai/mem0","slug":"invalid-index-to-id-key-type-type-key-expecte","errorCode":null,"errorMessage":"Invalid index_to_id key type: {type(key)}, expected int","messagePattern":"Invalid index_to_id key type: (.+?), expected int","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"mem0/vector_stores/faiss.py","lineNumber":114,"sourceCode":"    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):\n    def __init__(\n        self,\n        collection_name: str,\n        path: Optional[str] = None,\n        distance_strategy: str = \"euclidean\",","sourceCodeStart":96,"sourceCodeEnd":132,"githubUrl":"https://github.com/mem0ai/mem0/blob/001c235229be8795e3834520467bd0d661ed8f34/mem0/vector_stores/faiss.py#L96-L132","documentation":"Raised while validating index_to_id entries: a key (FAISS row number) is not an int. Rows must be integers because they are used to reconstruct/delete vectors by position. ValueError raised at load.","triggerScenarios":"A persisted index_to_id dict whose keys are strings — the classic result of round-tripping the tuple through JSON, where integer keys are coerced to strings.","commonSituations":"Externally editing or re-serializing the JSON docstore; a migration script that did json.load/json.dump without int() key conversion.","solutions":["Re-serialize with integer keys: {int(k): v for k, v in index_to_id.items()}","Regenerate the whole store through mem0 to rebuild a consistent index_to_id","Avoid manual edits to the persisted files"],"exampleFix":"# before\nindex_to_id = data[1]  # keys are '0','1',... after JSON round-trip\n\n# after\nindex_to_id = {int(k): v for k, v in data[1].items()}\ndata[1] = index_to_id","handlingStrategy":"validation","validationCode":"data[1] = {int(k): v for k, v in data[1].items()}  # repair string keys from JSON round-trips","typeGuard":"def index_to_id_keys_are_int(x) -> bool:\n    return isinstance(x, dict) and all(isinstance(k, int) for k in x)","tryCatchPattern":null,"preventionTips":["After any JSON round-trip of the docstore, re-int() the index_to_id keys","Avoid re-serializing persisted stores with custom tooling"],"tags":["faiss","vector-store","json","type-coercion"],"backgroundTag":null,"analyzedSha":"001c235229be8795e3834520467bd0d661ed8f34","analyzedAt":"2026-08-15T01:55:42.685Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}