Principle:0xK3vin MegaMemory Graph Hierarchy Organization
| Knowledge Sources | |
|---|---|
| Domains | Knowledge_Graph, Information_Architecture, Data_Modeling |
| Last Updated | 2026-10-27 12:00 GMT |
Overview
A structuring technique that organizes a knowledge graph into a shallow tree hierarchy (max 3 levels) via parent-child relationships, balancing navigability with flatness for search.
Description
Graph hierarchy organization imposes a shallow tree structure on a knowledge graph using parent_id foreign keys. Root concepts (no parent) represent top-level systems; child concepts nest under roots via parent_id. A depth cap prevents unreasonably deep nesting that would fragment knowledge and complicate traversal.
Problem solved: A flat graph of hundreds of concepts is hard to navigate or summarize. A deeply nested tree fragments knowledge and makes cross-cutting relationships invisible. A 3-level hierarchy provides a navigable "table of contents" (roots → modules → patterns/components) while keeping the graph shallow enough that semantic search and edge traversal remain effective.
Context: MegaMemory enforces a maximum depth of 3 levels (root → child → grandchild), enforced by the skill plugin (plugin/megamemory.ts). Concept IDs are hierarchical slugs ("root/child/grandchild"), making the tree structure visible in the ID itself. listRoots returns only top-level concepts and their direct children, giving the agent a compact overview. getChildren retrieves descendants for deeper traversal.
Usage
Use this principle when:
- You need a navigable overview of a large concept space (roots as a "table of contents")
- You want hierarchical IDs that encode parentage (module/pattern)
- A depth cap prevents knowledge fragmentation while keeping structure
- Root-level concepts should be discoverable without traversing the entire graph
Theoretical Basis
The graph is a forest of shallow trees, where each node has at most one parent:
Constraint: for all nodes.
ID derivation:
Pseudo-code:
# Abstract creation (NOT real implementation)
def create_concept(name, parent_id):
slug = name.lower().replace(" ", "-")
node_id = f"{parent_id}/{slug}" if parent_id else slug
depth = count_depth(parent_id) + 1
assert depth <= 3, "Max 3 levels deep"
db.insert(id=node_id, parent_id=parent_id, ...)
Root retrieval: Roots are nodes where parent_id IS NULL AND removed_at IS NULL. This is a single SQL query that serves as the "table of contents."