SimpleFileNodeParser#
SimpleFileNodeParser is a format-dispatching node parser in llama-index-core. Given a sequence of documents, it reads each document's metadata["extension"] field and routes parsing to the appropriate format-specific parser — or falls back to a plain text split for unsupported extensions.
Dispatch table#
The routing is driven by a module-level registry :
| Extension | Delegated parser |
|---|---|
.md | MarkdownNodeParser |
.html | HTMLNodeParser |
.json | JSONNodeParser |
| (other) | build_nodes_from_splits (raw text) |
Delegation and config propagation#
For each recognized extension, _parse_nodes instantiates the matching parser, forwarding three fields from self :
include_metadatainclude_prev_next_relcallback_manager
id_func is not forwarded. The delegated parsers are constructed without an explicit id_func= argument, so they fall back to the inherited default (default_id_func) defined in NodeParser. This means a custom id_func set on a SimpleFileNodeParser instance is not propagated to the sub-parsers that handle .md, .html, or .json documents.
By contrast, for unsupported extensions the fallback path calls build_nodes_from_splits with id_func=self.id_func explicitly , so custom IDs are respected for those files.
id_func in the base class and sub-parsers#
id_func is declared on the NodeParser base class as an Optional[IdFuncCallable] field . A BeforeValidator replaces None with default_id_func at construction time, so the field is never truly None after initialization . All three delegated parsers inherit this field and pass self.id_func through to build_nodes_from_splits within their own _build_node_from_split / get_nodes_from_node methods .
Known issue: JSON array ID stability#
JSONNodeParser had a separate bug (independent of SimpleFileNodeParser) where a custom id_func produced duplicate IDs for JSON arrays because the chunk index reset to zero per element. PR #23221 fixes this by collecting all per-element text splits first, then calling build_nodes_from_splits once, so the id_func receives sequential chunk indexes across the full array.
Entry points#
| Item | Path |
|---|---|
SimpleFileNodeParser source | node_parser/file/simple_file.py |
NodeParser base / id_func | node_parser/interface.py |
MarkdownNodeParser | node_parser/file/markdown.py |
HTMLNodeParser | node_parser/file/html.py |
JSONNodeParser | node_parser/file/json.py |