TrustGraph 详解:把知识图谱、Ontology、GraphRAG 和 AI Agent 串成一套系统

如果说普通 RAG 是"帮 AI 找资料",那么 TrustGraph 更想做的事情是:给 AI Agent 建立一层统一、结构化、可追踪的上下文。

项目名称:

text 复制代码
TrustGraph

GitHub:

text 复制代码
https://github.com/trustgraph-ai/trustgraph

官网:

text 复制代码
https://trustgraph.ai/

一、TrustGraph 是什么?

TrustGraph 是一个开源的 AI Context / Knowledge Graph 基础设施项目。

它现在给自己的定位是:

The Context Interoperability Layer for Agentic AI

翻译一下:

面向 Agentic AI 的上下文互操作层。

这个名字看起来有点抽象。

我们先用最简单的方式理解。

传统 AI 应用:

text 复制代码
用户
 ↓
LLM
 ↓
回答

后来有了 RAG:

text 复制代码
用户
 ↓
Vector Search
 ↓
Documents
 ↓
LLM
 ↓
回答

再后来有了 GraphRAG:

text 复制代码
用户
 ↓
Vector Search
 ↓
Knowledge Graph
 ↓
Graph Traversal
 ↓
LLM
 ↓
回答

而 TrustGraph 想进一步做成:

text 复制代码
                     AI Agent
                         |
                         ↓
                 Context Layer
                         |
        ┌────────────────────────┐
        |                        |
        ↓                        ↓
   Knowledge Graph           Vector Search
        |                        |
        └───────────┬────────────┘
                    ↓
                Ontology
                    ↓
      ┌─────────────┼─────────────┐
      ↓             ↓             ↓
   Documents      Database       APIs

也就是说:

把企业里的各种数据统一整理成 AI 能理解的 Context。


二、为什么普通 RAG 不够?

先看普通 RAG。

假设公司里有 10 万份文档:

text 复制代码
合同

产品文档

会议纪要

用户反馈

财务报告

技术文档

传统方法:

text 复制代码
Document
 ↓
Chunk
 ↓
Embedding
 ↓
Vector Database

用户问:

text 复制代码
A 客户现在使用哪个产品?

系统:

text 复制代码
问题
 ↓
Embedding
 ↓
Vector Search
 ↓
找到几个 Chunk
 ↓
LLM

这种方式最大的优点:

简单。

但是问题也很多。


三、第一个问题:Chunk 之间没有关系

例如:

文档 A:

text 复制代码
阿里巴巴购买了产品 X。

文档 B:

text 复制代码
产品 X 使用 PostgreSQL。

文档 C:

text 复制代码
PostgreSQL 数据库部署在服务器 Server-01。

用户问:

text 复制代码
阿里巴巴使用的数据库部署在哪台服务器?

这个问题需要:

text 复制代码
Alibaba

↓

Product X

↓

PostgreSQL

↓

Server-01

至少三跳关系。

普通 Vector RAG 很可能只找到:

text 复制代码
Alibaba → Product X

或者:

text 复制代码
PostgreSQL → Server-01

但是它不一定知道:

这三件事情其实属于同一条关系链。


四、Knowledge Graph 就开始发挥作用了

如果把这些知识变成图:

text 复制代码
Alibaba
   |
   | purchased
   ↓
Product X
   |
   | uses
   ↓
PostgreSQL
   |
   | deployedOn
   ↓
Server-01

现在问题:

text 复制代码
Alibaba 使用的数据库在哪台服务器?

就可以沿着图:

text 复制代码
Alibaba
 ↓
Product
 ↓
Database
 ↓
Server

一路查询。

这就是:

Multi-Hop Reasoning。

也就是:

多跳推理。


五、TrustGraph 的 GraphRAG

TrustGraph 一个很重要的能力就是:

text 复制代码
GraphRAG

它并不是完全放弃 Vector Search。

而是把:

text 复制代码
Vector Search

+

Knowledge Graph

组合起来。

整个流程大概是:

text 复制代码
Document

↓

Chunking

↓

Entity Extraction

↓

Relationship Extraction

↓

Embedding

↓

Knowledge Graph

查询:

text 复制代码
Question

↓

Vector Search

↓

找到相关 Entity

↓

Graph Traversal

↓

找到相关子图

↓

Subgraph Context

↓

LLM

↓

Answer

这比:

text 复制代码
问题

↓

找几个 Chunk

多了一层:

关系理解。


六、举一个更具体的例子

假设有三份文档。

第一份:

text 复制代码
王仕宇创建了 JavaPub。

第二份:

text 复制代码
JavaPub 主要发布 AI 和编程相关内容。

第三份:

text 复制代码
AI 编程课程属于 JavaPub 的内容体系。

普通 RAG:

text 复制代码
Document 1

Document 2

Document 3

三个 Chunk。

TrustGraph:

text 复制代码
王仕宇
   |
   | created
   ↓
JavaPub
   |
   | publishes
   ↓
AI / 编程内容
   |
   | includes
   ↓
AI 编程课程

于是用户问:

text 复制代码
王仕宇创建的品牌主要有哪些 AI 内容?

GraphRAG 可以沿着关系找到答案。

这就是:

text 复制代码
Graph + RAG

七、TrustGraph 还有一个更重要的能力:Ontology RAG

如果只是自动抽取知识图谱,会出现一个问题:

LLM 想抽什么就抽什么。

例如:

text 复制代码
Apple

到底是什么?

可能是:

text 复制代码
Company

Fruit

Product Brand

再例如:

text 复制代码
Java

可能是:

text 复制代码
ProgrammingLanguage

Island

Coffee

如果没有统一 Schema:

不同文档可能抽出完全不同的结构。


八、Ontology 解决什么问题?

Ontology 解决的是:

世界里有什么,以及这些东西之间可以有什么关系。

例如企业系统:

text 复制代码
Customer

Product

Order

Employee

Company

定义关系:

text 复制代码
Customer
   |
   | purchases
   ↓
Product

再定义:

text 复制代码
Employee
   |
   | worksFor
   ↓
Company

于是:

text 复制代码
Customer

不能随便:

text 复制代码
worksFor Product

因为这不符合 Ontology。


九、TrustGraph 支持 Ontology RAG

TrustGraph 可以使用 OWL Ontology 指导知识抽取。

流程:

text 复制代码
Document

↓

Chunk

↓

Ontology

↓

LLM Extraction

↓

Typed Entity

↓

Typed Relationship

↓

Knowledge Graph

↓

GraphRAG

这比普通 GraphRAG 多了一步:

text 复制代码
Ontology Constraint

什么意思?

普通 GraphRAG:

text 复制代码
LLM:

我觉得这是一个实体。

Ontology RAG:

text 复制代码
Ontology:

允许的实体类型:

Customer

Order

Product

Supplier

LLM:

text 复制代码
那我按照这些类型抽。

十、举一个电商 Ontology

比如我们定义:

text 复制代码
Customer

Order

Product

Supplier

Payment

关系:

text 复制代码
Customer
   |
   | places
   ↓
Order

Order
   |
   | contains
   ↓
Product

Product
   |
   | suppliedBy
   ↓
Supplier

Order
   |
   | paidBy
   ↓
Payment

现在给 AI 一份文档:

text 复制代码
王先生在 8 月 10 日购买了 MacBook,
订单由 Apple Store 提供,
使用支付宝完成付款。

TrustGraph 可以按照 Ontology 抽取:

text 复制代码
Customer:
王先生

Product:
MacBook

Supplier:
Apple Store

Payment:
支付宝

建立:

text 复制代码
王先生
 ↓ places
Order-001
 ↓ contains
MacBook
 ↓ suppliedBy
Apple Store

以及:

text 复制代码
Order-001
 ↓ paidBy
支付宝

这就变成了一套真正可查询的业务知识。


十一、Ontology RAG 和普通 GraphRAG 有什么区别?

可以直接看:

能力 RAG GraphRAG Ontology RAG
Vector Search
Knowledge Graph
Relationship
Multi-Hop
Schema
类型约束
OWL

可以简单理解:

text 复制代码
RAG

↓

找内容

GraphRAG:

text 复制代码
找内容

+

找关系

Ontology RAG:

text 复制代码
找内容

+

找关系

+

理解关系的业务含义

十二、为什么 Ontology 对企业 Agent 特别重要?

假设一个企业数据库里面有:

text 复制代码
客户

合同

订单

员工

供应商

项目

资产

如果没有统一语义:

CRM 叫:

text 复制代码
customer

ERP 叫:

text 复制代码
client

财务系统可能叫:

text 复制代码
payer

实际上:

可能都是:

text 复制代码
Customer

Ontology 可以把:

text 复制代码
customer

client

payer

统一到:

text 复制代码
Customer

这就是:

Semantic Layer。


十三、TrustGraph 想做的,其实就是 Context Layer

这个概念很重要。

现在 AI 领域越来越多人讨论:

text 复制代码
Context Engineering

以前我们关心:

text 复制代码
Prompt Engineering

也就是:

Prompt 怎么写?

现在越来越多系统开始关心:

到底应该给模型什么 Context?

因为模型本身已经越来越强。

真正影响 AI 输出的往往变成:

text 复制代码
Context

例如:

text 复制代码
哪些文档?

哪些实体?

哪些关系?

哪些历史?

哪些权限?

哪些业务规则?

TrustGraph 就想解决这件事情。


十四、Context Graph

TrustGraph 现在非常强调:

text 复制代码
Context Graph

可以简单理解:

为 AI Agent 服务的知识图谱。

传统知识图谱更多是:

text 复制代码
存知识

Context Graph 更强调:

text 复制代码
给 Agent 提供正确上下文

例如:

text 复制代码
                  Agent

                    ↓

               Context Graph

         ┌──────────┼──────────┐

         ↓          ↓          ↓

       User       Order     Contract

         ↓          ↓          ↓

       Role      Product     Policy

Agent 不需要一次读取:

text 复制代码
100 万条数据

而是从图中选择:

text 复制代码
当前问题真正需要的 Context

十五、TrustGraph 为什么开始强调 Hypergraph?

TrustGraph 现在还在强调一个概念:

text 复制代码
Hypergraph

传统 Knowledge Graph 通常:

text 复制代码
A → B

也就是二元关系。

例如:

text 复制代码
User

↓

purchased

↓

Product

但是企业业务往往更加复杂。

比如:

text 复制代码
张三

在 2026 年 8 月 1 日

通过支付宝

以 9999 元

购买 MacBook

订单属于 JavaPub 公司

这其实涉及:

text 复制代码
Person

Time

Payment

Amount

Product

Company

很多实体。

如果只用:

text 复制代码
A → B

表达起来会越来越复杂。


十六、Hypergraph 是什么?

Hypergraph 可以理解成:

一条关系可以连接多个对象。

传统 Graph:

text 复制代码
A ─── B

Hypergraph:

text 复制代码
          A

          |

    ┌─────┼─────┐

    ↓     ↓     ↓

    B     C     D

比如一次采购事件:

text 复制代码
              Purchase Event

       ┌────────┼─────────┬────────┐

       ↓        ↓         ↓        ↓

     User    Product    Payment   Time

整个:

text 复制代码
Purchase Event

可以作为一个完整 Context。

这对 AI Agent 很有价值。


十七、TrustGraph 的数据处理流程

我们可以把整个流程简化为:

text 复制代码
         Raw Data

            |

   ┌────────┼─────────┐

   ↓        ↓         ↓

 PDF      Wiki      Database

   \        |         /

        Ingestion

            ↓

         Chunking

            ↓

           LLM

            ↓

Entity / Relationship Extraction

            ↓

      Ontology Mapping

            ↓

      Knowledge Graph

            ↓

       Vector Index

            ↓

          GraphRAG

            ↓

         AI Agent

十八、TrustGraph 可以处理哪些数据?

典型包括:

text 复制代码
PDF

Text

企业文档

Wiki

API 数据

数据库数据

结构化信息

系统会把这些原始信息:

text 复制代码
Unstructured Data

逐渐转换成:

text 复制代码
AI-Ready Context

这其实就是 TrustGraph 的核心价值之一。


十九、TrustGraph 中的 Collection

TrustGraph 可以通过 Collection 组织知识。

例如:

text 复制代码
AI Research

Customer Support

Finance

Product Docs

分别建立:

text 复制代码
Collection

例如:

bash 复制代码
tg-set-collection \
  -n "AI Research" \
  -d "AI 研究资料" \
  ai-research

这样不同业务领域的数据可以分开管理。


二十、添加文档

可以将文档加入 Library。

例如:

bash 复制代码
tg-add-library-document \
  --name "AI Research Report" \
  --description "AI research report" \
  --tags "ai,research" \
  --id ai-report-001 \
  --kind text/plain \
  ./report.txt

进入系统之后:

text 复制代码
Document

↓

Library

↓

Processing Flow

↓

Knowledge Graph

二十一、创建 GraphRAG Flow

TrustGraph 使用 Flow 来组织数据处理 Pipeline。

例如:

bash 复制代码
tg-start-flow \
  -n graph-rag \
  -i graph-rag \
  -d "Graph RAG processing flow"

这个 Flow 可以负责:

text 复制代码
Document Chunking

↓

Entity Extraction

↓

Relationship Extraction

↓

Embedding

↓

Graph Construction

二十二、开始处理文档

例如:

bash 复制代码
tg-start-library-processing \
  --flow-id graph-rag \
  --document-id ai-report-001 \
  --collection ai-research \
  --processing-id process-001

然后系统开始:

text 复制代码
文档

↓

Chunk

↓

LLM 抽取

↓

Graph

↓

Vector

二十三、查询 GraphRAG

处理完成之后,可以直接查询:

bash 复制代码
tg-invoke-graph-rag \
  -f graph-rag \
  -C ai-research \
  -q "2026 年 AI Agent 主要发展方向是什么?"

查询过程:

text 复制代码
Question

↓

Semantic Search

↓

找到相关实体

↓

Graph Traversal

↓

提取 Subgraph

↓

LLM

↓

Answer

二十四、什么是 Subgraph Context?

这个概念很重要。

普通 RAG 给 LLM:

text 复制代码
Chunk 1

Chunk 2

Chunk 3

GraphRAG 给 LLM:

text 复制代码
            OpenAI

           /      \

          ↓        ↓

       Model      Agent

        |           |

        ↓           ↓

      GPT-X       Tool Use

也就是说:

不是几个孤立文本。

而是一张:

text 复制代码
小型关系网络

这就是:

text 复制代码
Subgraph Context

二十五、TrustGraph + MCP

TrustGraph 还有一个很有意思的能力:

text 复制代码
MCP

项目仓库里面已经包含:

text 复制代码
trustgraph-mcp

也就是说:

未来:

text 复制代码
Claude Code

Cursor

Codex

AI Agent

理论上都可以通过 MCP 调用 TrustGraph 提供的知识能力。

架构:

text 复制代码
Claude / Codex

       |

       ↓

      MCP

       |

       ↓

  TrustGraph

       |

       ↓

Context Graph

二十六、为什么 MCP + Knowledge Graph 很有意思?

普通 MCP:

text 复制代码
Agent

↓

Tool

↓

API

比如:

text 复制代码
查询数据库

发邮件

查天气

但是 TrustGraph:

text 复制代码
Agent

↓

MCP

↓

Context Graph

↓

企业知识

这就相当于:

给 Agent 增加一个"理解企业"的工具。

例如 Coding Agent 可以问:

text 复制代码
这个项目为什么当初选择 PostgreSQL?

Graph 里面可能有:

text 复制代码
Project

↓

Architecture Decision

↓

PostgreSQL

↓

Reason

↓

JSONB + Transaction

于是 Agent 不只是:

text 复制代码
看代码

还可以:

text 复制代码
理解项目历史。

二十七、TrustGraph 和 Graphiti 有什么区别?

前面我们介绍过 Graphiti。

两者确实有一些重叠。

但是侧重点不同。

Graphiti 更强调:

text 复制代码
Temporal Knowledge Graph

Agent Memory

Fact History

也就是:

世界发生了哪些变化?

TrustGraph 更强调:

text 复制代码
Context Graph

Ontology

GraphRAG

Enterprise Context

也就是:

AI Agent 应该如何理解整个企业上下文?

简单来说:

text 复制代码
Graphiti

↓

Memory

TrustGraph:

text 复制代码
Context

二十八、TrustGraph 和 Ontop 有什么区别?

Ontop:

text 复制代码
Database

↓

Ontology

↓

Virtual Knowledge Graph

它重点解决:

如何让关系数据库变成虚拟知识图谱。

TrustGraph:

text 复制代码
Documents

Database

APIs

↓

Knowledge Extraction

↓

Context Graph

重点解决:

如何把各种企业数据变成 Agent Context。

所以三者可以这样理解:

text 复制代码
Ontop

企业结构化数据
     ↓

TrustGraph

企业上下文
     ↓

Graphiti

长期动态记忆

二十九、这三个项目甚至可以组合

可以设想:

text 复制代码
              AI Agent

                  |

                  ↓

             TrustGraph

                  |

        Context / Ontology

        /               \

       ↓                 ↓

   Graphiti             Ontop

       ↓                 ↓

 Agent Memory      Enterprise DB

       ↓                 ↓

Temporal Graph     MySQL / Oracle

这是一个非常有意思的企业 Agent 架构。

其中:

text 复制代码
Ontop

负责:

当前业务数据。

text 复制代码
Graphiti

负责:

历史变化和长期记忆。

text 复制代码
TrustGraph

负责:

给 Agent 组织统一 Context。


三十、TrustGraph 最大的价值是什么?

我觉得不是:

text 复制代码
又一个 GraphRAG 框架

真正值得关注的是它背后的思想:

AI Agent 需要的不是更多 Token,而是更好的 Context。

以前我们想:

text 复制代码
上下文 128K

↓

上下文 1M

↓

上下文 10M

似乎:

上下文越大越好。

但是企业 AI 真正的问题可能不是:

text 复制代码
Context 不够长

而是:

text 复制代码
Context 不够准确。

真正需要的是:

text 复制代码
正确的数据

正确的实体

正确的关系

正确的时间

正确的权限

正确的业务语义

这才是:

text 复制代码
Context Engineering

三十一、Ontology 在这里扮演什么角色?

Ontology 相当于:

Agent 的世界说明书。

例如:

text 复制代码
Customer

Product

Order

Supplier

这是:

text 复制代码
概念。

然后:

text 复制代码
Customer purchases Product

这是:

text 复制代码
关系。

再进一步:

text 复制代码
Customer

必须是 Person / Organization

这是:

text 复制代码
约束。

因此:

text 复制代码
Ontology

↓

定义世界

Knowledge Graph:

text 复制代码
↓

记录世界

TrustGraph:

text 复制代码
↓

组织 Context

Agent:

text 复制代码
↓

理解世界并行动

三十二、未来企业 Agent 很可能是这种结构

我觉得未来很多企业 Agent 不会只是:

text 复制代码
LLM + Vector DB

而会变成:

text 复制代码
                      AI Agent

                         |

                         ↓

                 Context Engine

                         |

          ┌──────────────┼──────────────┐

          ↓              ↓              ↓

       Ontology      Knowledge       Memory
                       Graph

          |              |              |

          ↓              ↓              ↓

       Schema         GraphRAG       Temporal

          \              |              /

                 Enterprise Data

           ┌─────────┼─────────┐

           ↓         ↓         ↓

          DB       Docs       APIs

TrustGraph 正在尝试做的事情:

其实就是中间这层。


三十三、TrustGraph 更适合什么项目?

我觉得它比较适合:

1. 企业知识 Agent

例如:

text 复制代码
员工助手

销售助手

客服 Agent

财务 Agent

2. GraphRAG

特别是需要:

text 复制代码
Multi-Hop Reasoning

的场景。


3. Ontology RAG

例如:

text 复制代码
金融

医疗

制造业

法律

这种有明确 Schema 的领域。


4. 企业 Context Layer

大量系统:

text 复制代码
CRM

ERP

OA

Wiki

Database

需要统一语义。


5. Coding Agent Memory

把:

text 复制代码
架构设计

PR

Issue

文档

代码

技术决策

组织成图。


三十四、它不适合什么?

如果你的项目就是:

text 复制代码
100 个 PDF

然后:

text 复制代码
问答

那我觉得:

完全没必要一开始就上 TrustGraph。

一个简单的:

text 复制代码
Embedding

+

Vector DB

+

LLM

就够了。

TrustGraph 更适合:

text 复制代码
数据复杂

关系复杂

需要多跳查询

需要 Ontology

需要 Agent

需要企业 Context

这样的场景。


三十五、普通 RAG、GraphRAG、Ontology RAG 怎么选?

可以记住:

text 复制代码
简单文档问答

↓

RAG

如果问题大量涉及:

text 复制代码
谁和谁有什么关系?

选择:

text 复制代码
GraphRAG

如果业务还有明确:

text 复制代码
实体类型

业务模型

数据规范

选择:

text 复制代码
Ontology RAG

最终:

text 复制代码
RAG
 ↓
GraphRAG
 ↓
Ontology RAG
 ↓
Context Graph
 ↓
AI Agent

这条路线其实越来越清晰。


三十六、我怎么看 TrustGraph?

我认为 TrustGraph 最值得研究的并不是:

text 复制代码
GraphRAG API

而是:

text 复制代码
Context Layer

这个概念。

现在的大模型已经很聪明。

真正的问题变成:

如何把正确的信息,在正确的时间,以正确的结构交给 AI?

传统方法:

text 复制代码
Prompt

后来:

text 复制代码
Prompt + RAG

未来可能变成:

text 复制代码
Agent

+

Context Graph

+

Ontology

+

Tools

+

Memory

所以我觉得:

TrustGraph 本质上更像一个 Agent 的上下文基础设施。


三十七、总结

一句话总结 TrustGraph:

TrustGraph 是一个开源的 AI Context 基础设施,通过 Knowledge Graph、GraphRAG、Ontology、Vector Search 和 MCP 等能力,把企业原始数据组织成 AI Agent 可以理解和使用的结构化上下文。

如果用一张图表示:

text 复制代码
Documents
Database
APIs
Wiki

   ↓

TrustGraph

   ↓

Ontology

   ↓

Knowledge Graph

   ↓

GraphRAG

   ↓

Context Graph

   ↓

AI Agent

前面我们讲了:

text 复制代码
Graphiti

解决:

text 复制代码
Agent Memory

然后:

text 复制代码
Ontop

解决:

text 复制代码
Enterprise Data Layer

这次的:

text 复制代码
TrustGraph

更像是在解决:

text 复制代码
Agent Context Layer

三者放在一起:

text 复制代码
                    AI Agent

                       |

                       ↓

                  TrustGraph

                Context Layer

                 /         \

                ↓           ↓

            Graphiti       Ontop

                ↓           ↓

             Memory     Enterprise DB

而最上面贯穿这一切的,其实就是:

text 复制代码
Ontology

因为它负责告诉 AI:

这个业务世界到底是什么样的。

我认为这也是 Ontology 在 AI Agent 时代重新值得研究的真正原因。


项目地址

GitHub:

text 复制代码
https://github.com/trustgraph-ai/trustgraph

官网:

text 复制代码
https://trustgraph.ai/

王仕宇 JavaPub

https://javapub.net.cn/

相关推荐
迷迭香yy1 小时前
回测过拟合检测体系从样本内外到组合稳健性评估 IG50免费开源股票数据API接口
服务器·开发语言·数据库·人工智能·python
数字融合1 小时前
透明化数字孪生:未来医疗的核心平台
大数据·人工智能·virtualenv
richard_first1 小时前
Transformer 与大语言模型:第7章 Multi-Head Attention 多头注意
人工智能·深度学习·机器学习
大江东去浪淘尽千古风流人物1 小时前
【HMD-Poser】CVPR2024 头显端实时全身动捕:可伸缩稀疏观测、LSTM+Transformer 时空解耦与在线体型估计
人工智能·lstm·transformer·vr·人体姿态估计
Mr数据杨1 小时前
酒店房间图像识别辅助人口贩卖调查
人工智能·数据分析·kaggle竞赛
qq7422349841 小时前
Gradio 极简入门:三分钟为AI模型打造交互界面,并对比Streamlit与Dash如何选型
人工智能·算法·大模型·交互·dash
月亮和九磅十五便士1 小时前
朝闻 AI|2026-08-26
人工智能·大模型·ai agent
会编程的吕洞宾1 小时前
Spring AI 2.0 接 Milvus 做混合检索:RAG 召回率翻倍的实战方案
人工智能·spring·milvus
段一凡-华北理工大学1 小时前
高炉炉况智能诊断与预警实战~系列文章14:机器学习炉况分类:样本构建、类别不平衡与模型选型
大数据·人工智能·机器学习·分类·高炉智能化·炉况诊断·炉况分类