{"record":{"id":"35b2a20d463a3be8","repo":"run-llama/llama_index","slug":"fnnodemapping-does-not-support-persist-method","errorCode":null,"errorMessage":"FnNodeMapping does not support persist method.","messagePattern":"FnNodeMapping does not support persist method\\.","errorType":"exception","errorClass":"NotImplementedError","httpStatus":null,"severity":"error","filePath":"llama-index-core/llama_index/core/objects/fn_node_mapping.py","lineNumber":56,"sourceCode":"\n    def to_node(self, obj: Any) -> BaseNode:\n        \"\"\"To node.\"\"\"\n        return self._to_node_fn(obj)\n\n    def _from_node(self, node: BaseNode) -> Any:\n        \"\"\"From node.\"\"\"\n        return self._from_node_fn(node)\n\n    @property\n    def obj_node_mapping(self) -> Dict[int, Any]:\n        \"\"\"The mapping data structure between node and object.\"\"\"\n        raise NotImplementedError(\"FnNodeMapping does not support obj_node_mapping\")\n\n    def persist(\n        self, persist_dir: str = ..., obj_node_mapping_fname: str = ...\n    ) -> None:\n        \"\"\"Persist objs.\"\"\"\n        raise NotImplementedError(\"FnNodeMapping does not support persist method.\")\n\n    @classmethod\n    def from_persist_dir(\n        cls,\n        persist_dir: str = DEFAULT_PERSIST_DIR,\n        obj_node_mapping_fname: str = DEFAULT_PERSIST_FNAME,\n    ) -> \"FnNodeMapping\":\n        raise NotImplementedError(\"FnNodeMapping does not support persist method.\")\n","sourceCodeStart":38,"sourceCodeEnd":65,"githubUrl":"https://github.com/run-llama/llama_index/blob/afd0fef371831f9bda13e5af7167cf4e981278ab/llama-index-core/llama_index/core/objects/fn_node_mapping.py#L38-L65","documentation":"FnObjectNodeMapping.persist raises NotImplementedError because a function-based mapping holds no state worth pickling (its behavior lives in the to/from-node callables, which are generally not pickleable anyway). Persistence must be handled by the user outside the class.","triggerScenarios":"Calling obj_index.persist(persist_dir) (ObjectIndex.persist delegates to the mapping's persist) when the ObjectIndex was built with FnObjectNodeMapping; or calling fn_mapping.persist(...) directly.","commonSituations":"Building an ObjectIndex from custom functions then trying to save/load it across sessions; copy-pasting persistence code from a SimpleObjectNodeMapping example onto an Fn-based index.","solutions":["Persist only the underlying index (persist its storage_context / index_store) and rebuild the FnObjectNodeMapping from the same callables at load time","Use SimpleObjectNodeMapping instead if whole-object persistence is required","Wrap the persist call in a check for the mapping type before calling it"],"exampleFix":"# before\nobj_index = ObjectIndex.from_objects(objs, object_mapping_fn=..., index=index)\nobj_index.persist(\"./storage\")  # NotImplementedError from FnObjectNodeMapping.persist\n\n# after\nindex.storage_context.persist(persist_dir=\"./storage\")  # save index only\n# at load time: rebuild FnObjectNodeMapping(to_node_fn, from_node_fn) and ObjectIndex(index=loaded_index, object_node_mapping=fn_mapping)","handlingStrategy":"type-guard","validationCode":"from llama_index.core.objects import FnObjectNodeMapping\nif isinstance(obj_index.object_node_mapping, FnObjectNodeMapping):\n    obj_index.index.storage_context.persist(persist_dir=persist_dir)  # persist index only\nelse:\n    obj_index.persist(persist_dir)","typeGuard":"def can_persist_mapping(mapping) -> bool:\n    from llama_index.core.objects import FnObjectNodeMapping\n    return not isinstance(mapping, FnObjectNodeMapping)","tryCatchPattern":"try:\n    obj_index.persist(persist_dir)\nexcept NotImplementedError:\n    obj_index.index.storage_context.persist(persist_dir=persist_dir)\n    # rebuild FnObjectNodeMapping with the same callables at load time","preventionTips":["Branch persistence on mapping type in shared helpers","Define to/from-node functions at module level so they can be re-supplied after restart"],"tags":["persistence","object-index","not-implemented","api-limitation"],"backgroundTag":null,"analyzedSha":"afd0fef371831f9bda13e5af7167cf4e981278ab","analyzedAt":"2026-08-15T05:42:58.429Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}