跳到主内容
@wquguru
精选88r/LLMDevs(Reddit)技巧与观点

GraphRAG实战:6种高级架构模式详解

GraphRAG: A Practitioner's Guide to 6 Advanced Architectural Patterns

原文
发到 X
推荐理由

做 RAG 的同学必看,这篇把 GraphRAG 的六种主流架构拆解得很透彻,特别是稀疏图和自适应路由的设计思路,能直接指导你的链路优化。

I - Core Components of a GraphRAG Pipeline

一、GraphRAG 管道的核心组件

Information Extraction: Raw unstructured text is passed through an LLM instructed to perform Named Entity Recognition (NER) and Relationship Extraction

信息抽取:原始的非结构化文本通过大语言模型(LLM),该模型被指示执行命名实体识别(NER)和关系抽取

Graph Storage: The extracted nodes and edges are loaded into a Graph Database (like Neo4j, NebulaGraph, Memgraph etc). These databases use specialized query languages like Cypher to traverse nodes and relationships

图存储:提取出的节点和边被加载到图数据库(如 Neo4j、NebulaGraph、Memgraph 等)。这些数据库使用专门的查询语言(如 Cypher)来遍历节点和关系

Retrieval: The mechanism by which a user query interacts with the graph. The architectural patterns diverge significantly in this aspect

检索:用户查询与图进行交互的机制。在这一方面,架构模式存在显著差异

Generation: The retrieved graph data is injected into the LLM's context window to synthesize the final, grounded response

生成:检索到的图数据被注入到大语言模型的上下文窗口中,以合成最终的、有依据的回答

II - 6 Architectural Patterns of GraphRAG

二、GraphRAG 的 6 种架构模式

Pattern 1: Text-to-Cypher / Graph Query Generation

模式 1:Text-to-Cypher / 图查询生成

The user inputs a natural language query. The system provides a LLM with the graph database's schema (node labels, edge types, and properties) via the system prompt. The LLM's primary job is to translate the natural language into a valid graph query language (e.g., Cypher for Neo4j, or Gremlin). This query is then executed directly against the graph database. The exact, factual results returned by the database are either presented directly to the user or passed to a second LLM to be formatted into a natural language response.

用户输入自然语言查询。系统通过系统提示词向大语言模型提供图数据库的模式(节点标签、边类型和属性)。大语言模型的主要任务是将自然语言转换为有效的图查询语言(例如 Neo4j 的 Cypher 或 Gremlin)。然后直接针对图数据库执行此查询。数据库返回的确切事实结果要么直接呈现给用户,要么传递给第二个大语言模型以格式化为自然语言回答。

Pattern 2: Parallel Hybrid RAG (Vector + Graph)

模式 2:并行混合 RAG(向量 + 图)

In the Parallel Hybrid pattern, the system maintains two separate databases: a vector index of the original unstructured document chunks, and a knowledge graph of the extracted entities and relationships. When a user query arrives, the system queries both databases simultaneously. This approach acknowledges that a single, complex query often contains some parts that are best answered by the deterministic graph (e.g., "What was the revenue?") and others better answered by the vector database (e.g., "What were the strategic priorities?")

在并行混合模式中,系统维护两个独立的数据库:原始非结构化文档分块的向量索引,以及提取出的实体和关系的知识图谱。当用户查询到达时,系统同时查询这两个数据库。这种方法承认单个复杂查询通常包含某些部分最适合由确定性图回答(例如“收入是多少?”),而其他部分更适合由向量数据库回答(例如“战略重点是什么?”)

Pattern 3: Sequential Hybrid (Graph-First)

模式 3:顺序混合(图优先)

Unlike the parallel approach, Sequential Hybrid architectures use the results of one retrieval method to explicitly inform and filter the other. This creates a highly focused, precise context window, reducing the redundancy and high token costs of the parallel approach. The first variant of this is Graph-First RAG

与并行方法不同,顺序混合架构使用一种检索方法的结果来明确地告知和过滤另一种方法。这创建了一个高度聚焦、精确的上下文窗口,减少了并行方法的冗余和高令牌成本。这种变体的第一种是图优先 RAG

Corollary: The Sparse Graph Architecture (Cost-Efficient Graph-First RAG)

推论:稀疏图架构(成本高效的图优先 RAG)

It is worth noting that a major barrier to adopting any form of GraphRAG is the immense cost of extracting a dense knowledge graph using LLMs. The Sparse Graph Architecture is a direct corollary to the Graph-First pattern designed to alleviate this cost problem. Because Graph-First RAG relies heavily on the downstream vector search for nuance, we don't actually need a dense graph to capture all relations. Instead of using expensive LLMs, the system can use fast, deterministic NLP techniques (like SpaCy), or smaller LLMs to build a "sparse" skeletal graph of only the most critical, high-level entities. The retrieval flow remains identical to Pattern 3 (Traverse Sparse Graph -> Filtered Vector Search -> Synthesis). We rely entirely on the vector chunks to fill in the missing context and answer relation based queries accurately.

值得注意的是,采用任何形式 GraphRAG 的主要障碍在于使用大语言模型(LLM)提取稠密知识图谱的巨大成本。稀疏图架构是“图谱优先”模式的直接推论,旨在缓解这一成本问题。由于图谱优先的 RAG 严重依赖下游向量搜索来捕捉细微差别,我们实际上并不需要稠密图来捕获所有关系。系统可以不使用昂贵的大语言模型,而是使用快速、确定性的 NLP 技术(如 SpaCy),或较小的大语言模型来构建仅包含最关键、高层级实体的“稀疏”骨架图。检索流程与模式 3(遍历稀疏图 -> 过滤后的向量搜索 -> 综合)完全相同。我们完全依赖向量分块来填补缺失的上下文,并准确回答基于关系的查询。

Pattern 4: Sequential Hybrid (Vector-First)

模式 4:顺序混合(向量优先)

The inverse of the previous pattern. This architecture acknowledges that sometimes a user's query is too broad or fuzzy to start with a rigid graph traversal. Instead, we cast a wide semantic net first, and then use the graph to sharpen the context.

这是前一种模式的逆过程。该架构承认,有时用户的查询过于宽泛或模糊,无法从刚性的图谱遍历开始。相反,我们先撒下广泛的语义网,然后利用图谱来细化上下文。

Pattern 5: The Adaptive Router Agent

模式 5:自适应路由智能体

The Adaptive Router Agent introduces a decision-making layer at the very front of the pipeline.

自适应路由智能体在管道最前端引入了一个决策层。

An intelligent routing agent (which can be a fast LLM or a fine-tuned classification model) analyzes the user's incoming query. It evaluates the query's intent, entity density, and relational complexity, and then dynamically routes it down the optimal architectural path (Text-to-Cypher, Vector-Only, Graph-First, Vector-First, or Parallel Hybrid)

一个智能路由智能体(可以是一个快速的大语言模型或微调的分类模型)分析用户传入的查询。它评估查询的意图、实体密度和关系复杂性,然后动态地将其路由到最优的架构路径(Text-to-Cypher、纯向量、图谱优先、向量优先或并行混合)。

Pattern 6: Agentic GraphRAG The 6th and final pattern is Agentic GraphRAG. Instead of a single, predetermined retrieval pass, this pattern employs autonomous agents that interact with the graph dynamically.

模式 6:代理式 GraphRAG 第 6 个也是最后一个模式是代理式 GraphRAG。该模式不执行单一的、预定的检索过程,而是采用与图谱动态交互的自主智能体。

Given a complex query, an autonomous agent is equipped with tools to interact with both the graph database and the vector database. It might start by identifying a starting node in the graph, executing a query to view its neighbors. It evaluates this intermediate context and decides: "Do I need to traverse further down this edge, or should I use the source_document_id of this node to read the unstructured text in the vector database?" The agent iteratively navigates between structured relationships and unstructured text, gathering clues and backtracking if it hits a dead end, until it forms a complete answer

面对复杂查询,自主智能体配备了与图谱数据库和向量数据库交互的工具。它可能首先识别图谱中的一个起始节点,执行查询以查看其邻居。它评估这个中间上下文并做出决定:“我是否需要沿着这条边继续遍历,还是应该使用该节点的 source_document_id 来读取向量数据库中非结构化的文本?”智能体在结构化关系和非结构化文本之间迭代导航,收集线索,如果遇到死胡同则回溯,直到形成完整的答案

更进一步:量化金融体系

看懂新闻只是起点——沿量化金融路径,把它变成能交付的工程能力

进入量化体系 →

相似阅读

关联信息,但可能不是同一事件