Skip to content

API Reference parrot.knowledge.pageindex.tree_ops

github-actions[bot] edited this page Dec 2, 2026 · 4 revisions

parrot.knowledge.pageindex.tree_ops

View source

Mutation helpers for PageIndex trees.

A tree is a dict {doc_name, structure: [node, ...]} where each node is a dict with optional nodes (children). These helpers splice subtrees into existing trees, delete nodes by id, and renumber node_id across the whole tree so ids remain contiguous after any mutation.

OKF Integration (FEAT-238): splice_subtree automatically assigns concept_id values to new nodes that arrive without one. reindex_node_ids intentionally leaves concept_id untouched — it is a stable identity anchor and must never be overwritten by a node_id renumber pass.

Function delete_node

Remove the node with node_id and all its descendants.

Returns True if a node was removed, False if not found.

delete_node(tree: dict[str, Any], node_id: str) -> bool

Parameter Type Default Description
tree dict[str, Any]
node_id str

Returns: bool

Alias find_node_by_id

Re-exported from parrot.knowledge.pageindex.utils.find_node_by_id.

Function make_folder_node

Build a synthetic inner node representing a directory.

make_folder_node(name: str) -> dict[str, Any]

Parameter Type Default Description
name str

Returns: dict[str, Any]

Function reindex_node_ids

Reassign sequential 4-digit node_id values across the tree.

Only node_id is modified. OKF fields (concept_id, type, source, relates_to) are never touched — concept_id in particular is a stable identity anchor that must survive renumbering.

reindex_node_ids(tree: dict[str, Any]) -> None

Parameter Type Default Description
tree dict[str, Any]

Function splice_subtree

Insert subtree under parent_node_id (or at root if None).

Returns the new node_id of each freshly spliced root node, taken after the tree-wide reindex.

After splicing and reindexing, assign_concept_ids is called on the whole target tree so that any new nodes arriving without a concept_id receive one. Existing concept_id values on all nodes (pre-existing and newly spliced) are preserved.

splice_subtree(target: dict[str, Any], subtree: dict[str, Any] | list[dict[str, Any]], parent_node_id: Optional[str] = None) -> list[str]

Parameter Type Default Description
target dict[str, Any]
subtree dict[str, Any] | list[dict[str, Any]]
parent_node_id Optional[str] None

Returns: list[str]

Alias write_node_id

Re-exported from parrot.knowledge.pageindex.utils.write_node_id.

Architecture

Clients

Bots & Agents

Memory

Knowledge

Tools & Toolkits

Flows

Experts

Skills

Stores & Loaders

MCP & A2A

Server & APIs

Integrations

Outputs & A2UI

Prompts

Security

Operations

Migration

SDD Tooling

LLM Wiki

Deployment

Decisions

API Reference

Clone this wiki locally