一个基于 Knowledge Graph + Vector Retrieval + Multi-Agent 的 Agentic GraphRAG 问答系统。
项目实现了完整的 Agent Workflow,包括:
- Planner(任务规划)
- Query Rewrite(查询改写)
- Retriever(知识图谱 + 向量联合检索)
- Context Filter(上下文过滤)
- Judge(结果判断)
- Self-RAG(检索增强)
- Answer Generator(答案生成)
相比传统 GraphRAG,能够完成更复杂的多跳推理、多条件交集推理以及开放式总结任务。
AgenticGraphRAG
│
├── Agents/ # Agent模块
│ ├── planner_agent.py
│ ├── query_rewrite_agent.py
│ ├── context_filter_agent.py
│ ├── judge_agent.py
│ ├── self_rag_agent.py
│ └── answer_agent.py
│
├── Benchmark/ # Benchmark测试集
│ ├── benchmark_v1.json
│ ├── benchmark_v2.json
│ ├── benchmark_v3.json
│ ├── benchmark_v4.json
│ └── benchmark_test.json
│
├── DataBase/
│ ├── GraphData/
│ │ └── create_graph_knowledge.py
│ ├── config.py
│ └── prompt_utils.py
│
├── Models/
│ ├── LLM_Models.py
│ ├── Embed_Models.py
│ ├── local_llm.py
│ ├── model_utils.py
│ ├── query_convert.py
│ └── vision_models.py
│
├── Prompts/
│ ├── prompt_entity_extract.py
│ └── prompt_graph.py
│
├── evaluate_agenticgraphrag_v3.py
├── evaluate_graphrag_v3.py
├── main_AgenticGraphRAG_v8.py
├── main_GraphBuild_v2.py
├── main_build_vector_db.py
├── main_GraphRagRetriever_v2.py
├── main_GraphRetriever_v2.py
├── main_RAGRetriever.py
└── main_vector_retriever.py
整个系统采用如下工作流程:
Benchmark共30道题,覆盖四类知识推理任务:
| 类型 | 占比 |
|---|---|
| 多跳推理 | 40% |
| 交集推理 | 30% |
| 全局总结 | 20% |
| 枚举问题 | 10% |
| 方法 | Accuracy | 平均耗时 |
|---|---|---|
| GraphRAG | 60.00% | 1.76 s |
| Agentic GraphRAG | 80.00% | 7.82 s |
| 方法 | Accuracy | 平均耗时 |
|---|---|---|
| GraphRAG | 66.67% | 1.11 s |
| Agentic GraphRAG | 80.00% | 6.42 s |
Prompt优化后:
- GraphRAG准确率提升 6.67%
- GraphRAG耗时下降 36.9%
- Agentic GraphRAG耗时下降 17.9%
- Entity Extraction耗时约下降 48%
Agentic GraphRAG在复杂推理任务中具有明显优势:
- 多跳推理稳定完成实体关系链推理
- 多条件交集推理准确率显著高于传统GraphRAG
- 开放式总结能够融合更多检索结果
- 枚举类问题具有更高知识覆盖率
代价是推理时间相较GraphRAG有所增加。
Python >= 3.10
安装依赖:
pip install -r requirements.txt构建知识图谱
python main_GraphBuild_v2.py构建向量数据库
python main_build_vector_db.py运行GraphRAG
python main_GraphRagRetriever_v2.py运行Agentic GraphRAG
python main_AgenticGraphRAG_v8.py运行Benchmark
python evaluate_graphrag_v3.py
python evaluate_agenticgraphrag_v3.py目前系统仍有进一步优化空间,包括:
- 更高质量的实体抽取
- 更精细的Retriever排序策略
- Agent工具调用优化
- 多Agent协同策略
- 更大规模Benchmark测试
本项目基于多个优秀的开源项目实现。一些模块根据本工作的需要进行了适配和扩展。
SMARTGRAPHQA
https://github.com/tangjun1878/SMARTGRAPHQA
Mainly referenced for:
- Knowledge graph construction
- Graph retrieval pipeline
- Neo4j-based retrieval framework
All-in-RAG
https://github.com/datawhalechina/all-in-rag
Mainly referenced for:
- Vector retrieval pipeline
- RAG workflow implementation
LangGraph
https://github.com/langchain-ai/langgraph
Referenced for the design philosophy of multi-agent workflow and iterative reasoning.
感谢开源社区的贡献。
