返回顶部
t

tree-graph-rag

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.

作者: admin | 来源: ClawHub
源自
ClawHub
版本
V 1.0.0
安全检测
已通过
91
下载量
0
收藏
概述
安装方式
版本历史

tree-graph-rag

# 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 - **Tree (Macro)**: Represents the document's native hierarchy. Gives the LLM the structural skeleton (Chapter -> Section). - **Graph (Micro)**: Represents Entities and Relationships. Gives the LLM cross-document, fine-grained factual connections. - **Fusion**: Every node and edge in the Graph is anchored to a specific `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: - **[schema.sql](references/schema.sql)**: The complete PostgreSQL table definitions required for this architecture. - **[ingestion_core.py](scripts/ingestion_core.py)**: Python script demonstrating how to flatten the Tree JSON into Postgres and how to extract graph entities anchored to the tree. - **[retrieval_core.py](scripts/retrieval_core.py)**: Python script demonstrating the Hybrid Retrieval logic (Querying the Graph to find Tree node_ids, then extracting the macro context). - **[smoke_test.py](scripts/smoke_test.py)**: Minimal no-database smoke test that validates the ingestion and retrieval flow with a fake pool. - **[integration-pattern.md](references/integration-pattern.md)**: Explains what this skill covers, what it intentionally does not reimplement, and where it should sit in a real service. - **[queries.md](references/queries.md)**: Common SQL patterns for loading skeletons, anchoring graph hits, and assembling answer context. ## Standard Workflows ### 1. Indexing Workflow 1. **Tree Extraction**: Extract headers/TOC. Save skeleton to `nodes` 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 the `entities` and `relationships` tables to find matching factual details. 2. **Anchor Resolution**: Get the `node_id`s associated with the matched graph elements. 3. **Contextualization (Tree Traversal)**: Query the `nodes` table using the `node_id`s. 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 Chunks ## Output 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 - **Always enforce bone-meat separation**: Never store massive text chunks in the `nodes` or `entities` tables. - **Always maintain multi-tenancy**: Ensure every query filters by `workspace`. - When users ask to implement a retrieval function, write SQL queries that join `relationships` -> `nodes` -> `node_contents` to demonstrate the hybrid power. - Do not build a full product scaffold inside the skill. Keep the focus on database design, ingestion, anchoring, and retrieval patterns. - Do not rewrite PageIndex or LightRAG in full inside the skill. Reuse their existing pipelines and apply this skill at the integration seam.

标签

skill ai

通过对话安装

该技能支持在以下平台通过对话安装:

OpenClaw WorkBuddy QClaw Kimi Claude

方式一:安装 SkillHub 和技能

帮我安装 SkillHub 和 tree-graph-rag-1776020461 技能

方式二:设置 SkillHub 为优先技能安装源

设置 SkillHub 为我的优先技能安装源,然后帮我安装 tree-graph-rag-1776020461 技能

通过命令行安装

skillhub install tree-graph-rag-1776020461

下载 Zip 包

⬇ 下载 tree-graph-rag v1.0.0

文件大小: 7.73 KB | 发布时间: 2026-4-13 12:23

v1.0.0 最新 2026-4-13 12:23
Initial release of tree-graph-rag skill.

- Provides a guide for designing and implementing a PostgreSQL database fusing tree (hierarchical) and graph (entity/relationship) structures for RAG systems.
- Includes schema definitions, ingestion and retrieval logic, and integration patterns for a hybrid tree-graph knowledge base.
- Emphasizes anchoring graph details to tree nodes for flexible contextual retrieval.
- Supplies example code for ingestion, retrieval, and minimal smoke testing of the end-to-end data flow.
- Outlines standard workflows and developer guidelines for schema design and SQL usage.

Archiver·手机版·闲社网·闲社论坛·羊毛社区· 多链控股集团有限公司 · 苏ICP备2025199260号-1

Powered by Discuz! X5.0   © 2024-2025 闲社网·线报更新论坛·羊毛分享社区·http://xianshe.com

p2p_official_large
返回顶部