run-llama/llama_index · error · NotImplementedError

FnNodeMapping does not support obj_node_mapping

Error message

FnNodeMapping does not support obj_node_mapping

What it means

FnObjectNodeMapping maps objects to nodes purely through user-supplied to/from-node functions and keeps no in-memory dict. Therefore the obj_node_mapping property is declared but intentionally unimplemented and raises NotImplementedError. There is no stored mapping to expose by design.

Source

Thrown at llama-index-core/llama_index/core/objects/fn_node_mapping.py:50

    ) -> "BaseObjectNodeMapping":
        """Initialize node mapping."""
        return cls(from_node_fn, to_node_fn)

    def _add_object(self, obj: Any) -> None:
        """Add object. NOTE: unused."""

    def to_node(self, obj: Any) -> BaseNode:
        """To node."""
        return self._to_node_fn(obj)

    def _from_node(self, node: BaseNode) -> Any:
        """From node."""
        return self._from_node_fn(node)

    @property
    def obj_node_mapping(self) -> Dict[int, Any]:
        """The mapping data structure between node and object."""
        raise NotImplementedError("FnNodeMapping does not support obj_node_mapping")

    def persist(
        self, persist_dir: str = ..., obj_node_mapping_fname: str = ...
    ) -> None:
        """Persist objs."""
        raise NotImplementedError("FnNodeMapping does not support persist method.")

    @classmethod
    def from_persist_dir(
        cls,
        persist_dir: str = DEFAULT_PERSIST_DIR,
        obj_node_mapping_fname: str = DEFAULT_PERSIST_FNAME,
    ) -> "FnNodeMapping":
        raise NotImplementedError("FnNodeMapping does not support persist method.")

View on GitHub (pinned to afd0fef371)

Solutions

  1. Track objects yourself in a dict when using FnObjectNodeMapping and use that instead of obj_node_mapping
  2. Switch to SimpleObjectNodeMapping if you need an inspectable in-memory mapping and your objects are pickleable
  3. Guard generic code with hasattr/try-except NotImplementedError before touching obj_node_mapping

Example fix

# before
node_mapping = FnObjectNodeMapping(to_node_fn, from_node_fn)
items = node_mapping.obj_node_mapping  # NotImplementedError

# after
node_mapping = SimpleObjectNodeMapping.from_objects(objs)  # pickleable objs
items = node_mapping.obj_node_mapping
Defensive patterns

Strategy: type-guard

Validate before calling

from llama_index.core.objects import FnObjectNodeMapping
if isinstance(node_mapping, FnObjectNodeMapping):
    raise TypeError("FnObjectNodeMapping exposes no obj_node_mapping; keep your own object registry")

Type guard

def supports_obj_node_mapping(mapping) -> bool:
    from llama_index.core.objects import SimpleObjectNodeMapping
    return isinstance(mapping, SimpleObjectNodeMapping)

Try / catch

try:
    items = mapping.obj_node_mapping
except NotImplementedError:
    items = {}  # Fn-based mapping: nothing to enumerate; use your own registry

Prevention

When it happens

Trigger: Accessing fn_mapping.obj_node_mapping on an FnObjectNodeMapping instance, or any code path that iterates/inspects mappings generically (e.g. len(mapping), list(mapping.obj_node_mapping.items())) after building an ObjectIndex with FnObjectNodeMapping.

Common situations: Generic tooling written against BaseObjectNodeMapping that assumes every mapping exposes obj_node_mapping; interactive inspection of an ObjectIndex built over functions; reusing code that worked with SimpleObjectNodeMapping.

Related errors


AI-assisted analysis of run-llama/llama_index@afd0fef371 (2026-08-15). Data as JSON: /api/errors/095e81a606d0383a. Report an issue: GitHub.