Knowledge Tree
Hierarchical organization of beliefs into a navigable tree structure.
The knowledge tree provides a hierarchical view of beliefs. While the knowledge graph connects beliefs by semantic relationships, the tree organizes them into a layered taxonomy of topics and sub-topics. A belief can appear in multiple locations in the tree.
Place a Belief
engine.tree_place_belief(belief_id) → list[str]
Places a belief in the knowledge tree hierarchy. Returns a list of node IDs where the belief was placed. A belief can appear in multiple nodes.
node_ids = engine.tree_place_belief("belief-id")
print(f"Belief placed in {len(node_ids)} tree nodes")
for nid in node_ids:
print(f" node: {nid}")
Get a Node
engine.tree_get_node(node_id) → dict
Returns the node details including its position in the tree.
node = engine.tree_get_node("node-id")
# Returns:
# {
# "id": "node-id",
# "name": "Defense Systems",
# "description": "Beliefs about defensive structures and strategies",
# "parent_ids": ["parent-node-id"],
# "layer": 2,
# "belief_count": 15,
# }
Node Fields
| Field | Type | Description |
|---|---|---|
id | str | Unique node identifier |
name | str | Human-readable node name |
description | str | What this category covers |
parent_ids | list[str] | Parent node IDs (can have multiple) |
layer | int | Depth in the tree (0 = root) |
belief_count | int | Number of beliefs in this node |
Get Children
engine.tree_get_children(node_id) → list[dict]
Returns all child nodes of the given node.
children = engine.tree_get_children("node-id")
for child in children:
print(f" {child['name']}: {child['belief_count']} beliefs")
Get Paths
engine.tree_get_path(belief_id) → list[list[str]]
Returns all paths from root to the nodes where this belief is placed. Each path is a list of node IDs from root to leaf.
paths = engine.tree_get_path("belief-id")
for path in paths:
names = [engine.tree_get_node(nid)["name"] for nid in path]
print(" → ".join(names))
# e.g. "Root → Military → Defense Systems → Fortifications"
Tree vs. Graph
The knowledge tree and knowledge graph serve different purposes:
| Feature | Knowledge Graph | Knowledge Tree |
|---|---|---|
| Structure | Arbitrary connections | Hierarchical taxonomy |
| Edges | Semantic similarity, dream synthesis | Category membership |
| Traversal | BFS from any node | Root-to-leaf paths |
| Use case | Finding related beliefs | Browsing by topic |
| Multiple parents | N/A (it is a graph) | Yes, beliefs can appear in multiple categories |