KAG is a logical form-guided reasoning and retrieval framework based on OpenSPG engine and LLMs. It is used to build logical reasoning and factual Q&A solutions for professional domain knowledge bases. It can effectively overcome the shortcomings of the traditional RAG vector similarity calculation model.
Open in github.dev Open in a new github.dev tab Open in codespace
Name | Name |
Last commit message |
Last commit date |
|
---|---|---|---|---|
English | 简体中文 | 日本語版ドキュメント
中文 | 简体中文 | 日语文档
KAG is a logical reasoning and Q&A framework based on the OpenSPG engine and large language models, which is used to build logical reasoning and Q&A solutions for vertical domain knowledge bases. KAG can effectively overcome the ambiguity of traditional RAG vector similarity calculation and the noise problem of GraphRAG introduced by OpenIE. KAG supports logical reasoning and multi-hop fact Q&A, etc., and is significantly better than the current SOTA method.
KAG 是基于 OpenSPG 引擎和大型语言模型的逻辑推理和问答框架,用于构建垂直领域知识库的逻辑推理和问答解决方案。KAG 可以有效克服传统 RAG 向量相似度计算的歧义和 OpenIE 引入的 GraphRAG 噪声问题。KAG 支持逻辑推理和多跳事实问答等,明显优于目前的 SOTA 方法。
The goal of KAG is to build a knowledge-enhanced LLM service framework in professional domains, supporting logical reasoning, factual Q&A, etc. KAG fully integrates the logical and factual characteristics of the KGs. Its core features include:
KAG 的目标是在专业领域构建知识增强的LLM服务框架,支持逻辑推理、事实问答等。KAG 充分整合了 KG 的逻辑和事实特征。其核心功能包括:
- Knowledge and Chunk Mutual Indexing structure to integrate more complete contextual text information
Knowledge 和 Chunk Mutual Indexing 结构,用于集成更完整的上下文文本信息 - Knowledge alignment using conceptual semantic reasoning to alleviate the noise problem caused by OpenIE
使用概念语义推理进行知识对齐,缓解 OpenIE 带来的噪声问题 - Schema-constrained knowledge construction to support the representation and construction of domain expert knowledge
模式约束知识构造,支持领域专家知识的表示和构造 - Logical form-guided hybrid reasoning and retrieval to support logical reasoning and multi-hop reasoning Q&A
逻辑形式引导的混合推理和检索,支持逻辑推理和多跳推理 Q&A
⭐️ Star our repository to stay up-to-date with exciting new features and improvements! Get instant notifications for new releases! 🌟
⭐️ 为我们的存储库加注星标,以了解令人兴奋的新功能和改进!获取新版本的即时通知!🌟
In the context of private knowledge bases, unstructured data, structured information, and business expert experience often coexist. KAG references the DIKW hierarchy to upgrade SPG to a version that is friendly to LLMs.
在私有知识库的上下文中,非结构化数据、结构化信息和业务专家经验经常共存。KAG 引用 DIKW 层次结构,将 SPG 升级到适合 LLMs.
For unstructured data such as news, events, logs, and books, as well as structured data like transactions, statistics, and approvals, along with business experience and domain knowledge rules, KAG employs techniques such as layout analysis, knowledge extraction, property normalization, and semantic alignment to integrate raw business data and expert rules into a unified business knowledge graph.
对于非结构化数据(如新闻、事件、日志和书籍)以及结构化数据(如交易、统计数据和审批),以及业务经验和领域知识规则,KAG 采用布局分析、知识提取、属性规范化和语义对齐等技术,将原始业务数据和专家规则集成到统一的业务知识图谱中。
This makes it compatible with schema-free information extraction and schema-constrained expertise construction on the same knowledge type (e. G., entity type, event type), and supports the cross-index representation between the graph structure and the original text block.
这使得它兼容相同知识类型(例如实体类型、事件类型)上的无模式信息提取和模式约束的专业知识构建,并支持图结构和原始文本块之间的交叉索引表示。
This mutual index representation is helpful to the construction of inverted index based on graph structure, and promotes the unified representation and reasoning of logical forms.
这种互向指标表示有助于基于图结构的倒排指标的构建,促进了逻辑形式的统一表示和推理。
KAG proposes a logically formal guided hybrid solution and inference engine.
KAG 提出了一种逻辑形式化的引导式混合解决方案和推理引擎。
The engine includes three types of operators: planning, reasoning, and retrieval, which transform natural language problems into problem solving processes that combine language and notation.
该引擎包括三种类型的运算符:计划、推理和检索,它们将自然语言问题转化为结合语言和符号的问题解决过程。
In this process, each step can use different operators, such as exact match retrieval, text retrieval, numerical calculation or semantic reasoning, so as to realize the integration of four different problem solving processes: Retrieval, Knowledge Graph reasoning, language reasoning and numerical calculation.
在这个过程中,每个步骤都可以使用不同的运算符,如精确匹配检索、文本检索、数值计算或语义推理,从而实现检索、知识图谱推理、语言推理和数值计算四个不同问题解决过程的集成。
- 2025.04.17: Released KAG 0.7 Version
2025.04.17:发布 KAG 0.7 版本- First, we refactored the KAG-Solver framework. Added support for two task planning modes, static and iterative, while implementing a more rigorous knowledge layering mechanism for the reasoning phase.
首先,我们重构了 KAG-Solver 框架。添加了对两种任务规划模式(静态和迭代)的支持,同时为推理阶段实施了更严格的知识分层机制。 - Second, we optimized the product experience: introduced dual modes—"Simple Mode" and "Deep Reasoning"—during the reasoning phase, along with support for streaming inference output, automatic rendering of graph indexes, and linking generated content to original references.
其次,我们优化了产品体验:在推理阶段引入了“简单模式”和“深度推理”双模式,并支持流式推理输出、图形索引的自动渲染以及将生成的内容链接到原始参考。 - Added an open_benchmark directory to the top level of the KAG repository, comparing various RAG methods under the same base to achieve state-of-the-art (SOTA) results.
在 KAG 存储库的顶层添加了一个 open_benchmark 目录,用于比较同一基础下的各种 RAG 方法,以获得最先进的 (SOTA) 结果。 - Introduced a "Lightweight Build" mode, reducing knowledge construction token costs by 89%.
引入 “Lightweight Build” 模式,将知识构建代币成本降低 89%。
- First, we refactored the KAG-Solver framework. Added support for two task planning modes, static and iterative, while implementing a more rigorous knowledge layering mechanism for the reasoning phase.
- 2025.01.07: Support domain knowledge injection, domain schema customization, QFS tasks support, Visual query analysis, enables schema-constraint mode for extraction, etc.
2025.01.07 : 支持领域知识注入、领域架构定制、QFS 任务支持、可视化查询分析、开启架构约束模式进行提取等。 - 2024.11.21: Support Word docs upload, model invoke concurrency setting, User experience optimization, etc.
2024.11.21 : 支持 Word 文档上传、模型调用并发设置、用户体验优化等 - 2024.10.25: KAG initial release
2024.10.25:KAG 初始版本 - Logical reasoning optimization, conversational tasks support
逻辑推理优化,对话任务支持 - kag-model release, kag solution for event reasoning knowledge graph and medical knowledge graph
kag-model release,事件推理知识图谱和医学知识图谱的 kag 解决方案 - kag front-end open source, distributed build support, mathematical reasoning optimization
KAG 前端开源,分布式构建支持,数学推理优化 - Recommend System Version:
推荐系统版本:macOS User:macOS Monterey 12.6 or later Linux User:CentOS 7 / Ubuntu 20.04 or later Windows User:Windows 10 LTSC 2021 or later
- Software Requirements:软件要求:
macOS / Linux User:Docker,Docker Compose Windows User:WSL 2 / Hyper-V,Docker,Docker Compose
Use the following commands to download the docker-compose.yml file and launch the services with Docker Compose.
使用以下命令下载 docker-compose.yml 文件并使用 Docker Compose 启动服务。
# set the HOME environment variable (only Windows users need to execute this command)
# set HOME=%USERPROFILE%
curl -sSL https://raw.githubusercontent.com/OpenSPG/openspg/refs/heads/master/dev/release/docker-compose-west.yml -o docker-compose-west.yml
docker compose -f docker-compose-west.yml up -d
Navigate to the default url of the KAG product with your browser: http://127.0.0.1:8887
使用浏览器导航到 KAG 产品的默认 URL: http://127.0.0.1:8887
Default Username: openspg
Default password: openspg@kag
See KAG usage (product mode) for detailed introduction.
详细介绍请参见 KAG 使用(产品模式)。
Refer to the 3.1 section to complete the installation of the engine & dependent image.
请参考3.1部分完成引擎和依赖镜像的安装。
macOS / Linux developers macOS / Linux 开发人员
# Create conda env: conda create -n kag-demo python=3.10 && conda activate kag-demo
# Clone code: git clone https://github.com/OpenSPG/KAG.git
# Install KAG: cd KAG && pip install -e .
Windows developers Windows 开发人员
# Install the official Python 3.8.10 or later, install Git.
# Create and activate Python venv: py -m venv kag-demo && kag-demo\Scripts\activate
# Clone code: git clone https://github.com/OpenSPG/KAG.git
# Install KAG: cd KAG && pip install -e .
Please refer to KAG usage (developer mode) guide for detailed introduction of the toolkit. Then you can use the built-in components to reproduce the performance results of the built-in datasets, and apply those components to new busineness scenarios.
请参考 KAG 使用(开发者模式) 指南,了解该工具包的详细介绍。然后,您可以使用内置组件重现内置数据集的性能结果,并将这些组件应用于新的业务场景。
The KAG framework includes three parts: kg-builder, kg-solver, and kag-model. This release only involves the first two parts, kag-model will be gradually open source release in the future.
KAG 框架包括三个部分:kg-builder、kg-solver 和 kag-model。本次发布仅涉及前两部分,后续 kag-model 将逐步开源发布。
kg-builder implements a knowledge representation that is friendly to large-scale language models (LLM). Based on the hierarchical structure of DIKW (data, information, knowledge and wisdom), IT upgrades SPG knowledge representation ability, and is compatible with information extraction without schema constraints and professional knowledge construction with schema constraints on the same knowledge type (such as entity type and event type), it also supports the mutual index representation between the graph structure and the original text block, which supports the efficient retrieval of the reasoning question and answer stage.
kg-builder 实现了对大规模语言模型友好的知识表示 (LLM)。基于 DIKW(数据、信息、知识和智慧)的层次结构,IT 升级了 SPG 知识表示能力,兼容同一知识类型(如实体类型、事件类型)上无模式约束的信息提取和模式约束的专业知识构建,还支持图结构与原始文本块之间的互向索引表示, 支持推理问答环节的高效检索。
kg-solver uses a logical symbol-guided hybrid solving and reasoning engine that includes three types of operators: planning, reasoning, and retrieval, to transform natural language problems into a problem-solving process that combines language and symbols. In this process, each step can use different operators, such as exact match retrieval, text retrieval, numerical calculation or semantic reasoning, so as to realize the integration of four different problem solving processes: Retrieval, Knowledge Graph reasoning, language reasoning and numerical calculation.
kg-solver 使用逻辑符号引导的混合求解和推理引擎,该引擎包括三种类型的运算符:规划、推理和检索,将自然语言问题转换为结合语言和符号的问题解决过程。在这个过程中,每个步骤都可以使用不同的运算符,如精确匹配检索、文本检索、数值计算或语义推理,从而实现检索、知识图谱推理、语言推理和数值计算四个不同问题解决过程的集成。
GitHub: https://github.com/OpenSPG/KAG
GitHub : https://github.com/OpenSPG/KAG
Website: https://openspg.github.io/v2/docs_en
网站 : https://openspg.github.io/v2/docs_en
Join our Discord community.
加入我们的 Discord 社区。
WeChat 微信
Follow OpenSPG Official Account to get technical articles and product updates about OpenSPG and KAG.
关注 OpenSPG 官方帐户,获取有关 OpenSPG 和 KAG 的技术文章和产品更新。
Scan the QR code below to join our WeChat group.
扫描下方二维码加入我们的微信群。
KAG introduction and applications: https://github.com/orgs/OpenSPG/discussions/52
KAG 介绍和应用 : https://github.com/orgs/OpenSPG/discussions/52
If you use this software, please cite it as below:
如果您使用此软件,请按以下方式引用:
- KAG: Boosting LLMs in Professional Domains via Knowledge Augmented Generation
KAG:通过知识增强生成促进LLMs专业领域的发展 - KGFabric: A Scalable Knowledge Graph Warehouse for Enterprise Data Interconnection
KGFabric:用于企业数据互连的可扩展知识图谱仓库
@article{liang2024kag,
title={KAG: Boosting LLMs in Professional Domains via Knowledge Augmented Generation},
author={Liang, Lei and Sun, Mengshu and Gui, Zhengke and Zhu, Zhongshu and Jiang, Zhouyu and Zhong, Ling and Zhao, Peilong and Bo, Zhongpu and Yang, Jin and others},
journal={arXiv preprint arXiv:2409.13731},
year={2024}
}
@article{yikgfabric,
title={KGFabric: A Scalable Knowledge Graph Warehouse for Enterprise Data Interconnection},
author={Yi, Peng and Liang, Lei and Da Zhang, Yong Chen and Zhu, Jinye and Liu, Xiangyu and Tang, Kun and Chen, Jialin and Lin, Hao and Qiu, Leijie and Zhou, Jun}
}
License 许可证
Apache License 2.0 Apache 许可证 2.0
Lei Liang, Mengshu Sun, Zhengke Gui, Zhongshu Zhu, Zhouyu Jiang, Ling Zhong, Peilong Zhao, Zhongpu Bo, Jin Yang, Huaidong Xiong, Lin Yuan, Jun Xu, Zaoyang Wang, Zhiqiang Zhang, Wen Zhang, Huajun Chen, Wenguang Chen, Jun Zhou, Haofen Wang
梁磊, 孙梦舒, 桂正科, 朱钟书, 江周玉, 钟玲, 赵培龙, 波忠普, 杨锦, 熊怀东, 林媛, 徐军, 王枣阳, 张志强, 张温, 陈华军, 陈文光, 周军, 王浩芬
Releases 4
Packages
No packages published
Deployments 6
Languages
- Python 99.9%
- Other 0.1%