run-llama/llama_index · error · ValueError

Depth cannot be a negative number!

Error message

Depth cannot be a negative number!

What it means

Error "Depth cannot be a negative number!" thrown in run-llama/llama_index.

Source

Thrown at llama-index-core/llama_index/core/node_parser/relational/hierarchical.py:64

    for node in nodes:
        if NodeRelationship.CHILD not in node.relationships:
            continue

        children_ids.extend([r.node_id for r in (node.child_nodes or [])])

    child_nodes = []
    for candidate_node in all_nodes:
        if candidate_node.node_id not in children_ids:
            continue
        child_nodes.append(candidate_node)

    return child_nodes


def get_deeper_nodes(nodes: List[BaseNode], depth: int = 1) -> List[BaseNode]:
    """Get children of root nodes in given nodes that have given depth."""
    if depth < 0:
        raise ValueError("Depth cannot be a negative number!")
    root_nodes = get_root_nodes(nodes)
    if not root_nodes:
        raise ValueError("There is no root nodes in given nodes!")

    deeper_nodes = root_nodes
    for _ in range(depth):
        deeper_nodes = get_child_nodes(deeper_nodes, nodes)

    return deeper_nodes


class HierarchicalNodeParser(NodeParser):
    """
    Hierarchical node parser.

    Splits a document into a recursive hierarchy Nodes using a NodeParser.

    NOTE: this will return a hierarchy of nodes in a flat list, where there will be

View on GitHub (pinned to afd0fef371)

Solutions

  1. Pass a depth >= 0 to HierarchicalNodeParser.from_defaults.

When it happens

Trigger: Thrown at llama-index-core/llama_index/core/node_parser/relational/hierarchical.py:64 when the library encounters an invalid state.

Common situations: See trigger scenarios.


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