tree-graph-rag
by @h4444433333
Guide for designing and implementing a PostgreSQL database that fuses PageIndex-style document trees with LightRAG-style entity-relationship anchors. Use thi...
clawhub install tree-graph-ragπ About This Skill
name: tree-graph-rag description: Guide for designing and implementing a PostgreSQL database that fuses PageIndex-style document trees with LightRAG-style entity-relationship anchors. Use this skill when Claude needs to design schemas, write ingestion logic, or implement retrieval SQL for a hybrid tree-graph knowledge base, especially when converting nested tree output into relational tables.
Tree-Graph Hybrid RAG
This skill teaches Claude how to build the database layer of a Tree-Graph Hybrid RAG system. It focuses on the integration seam between PageIndex-style tree output and LightRAG-style graph extraction, both stored in PostgreSQL.
Core Philosophy
node_id in the Tree, enabling bidirectional traversal (from graph detail to tree context, or tree context to graph detail).Bundled Resources
This skill includes the minimum resources needed to teach Claude the database design and data flow:
Standard Workflows
1. Indexing Workflow
1. Tree Extraction: Extract headers/TOC. Save skeleton tonodes and text to node_contents.
2. Graph Extraction: Pass each node_contents to an LLM to extract entities and relations.
3. Anchoring: Save entities/relations with their corresponding node_id as a foreign key.2. Retrieval Workflow
1. Entity/Relation Search: Extract keywords from the user query. Search theentities and relationships tables to find matching factual details.
2. Anchor Resolution: Get the node_ids associated with the matched graph elements.
3. Contextualization (Tree Traversal): Query the nodes table using the node_ids. Traverse up (parent_id) to gather the section titles and summaries.
4. Content Fetch: Retrieve the full text from node_contents only for the required nodes.
5. Synthesis: Feed the LLM a prompt containing:
- Found Entities & Relations
- Tree Context (e.g., "This was mentioned in Chapter 3: Financials")
- Raw Text ChunksOutput Expectations
When this skill is triggered, prefer producing:
1. PostgreSQL DDL or migration SQL
2. Tree-flattening ingestion code
3. Graph anchoring logic tied to node_id
4. Retrieval SQL that starts from graph hits and resolves back to tree context
5. Clear explanation of why this database design is preferable to storing one giant nested JSON blob
Developer Guidelines
nodes or entities tables.workspace.relationships -> nodes -> node_contents to demonstrate the hybrid power.