█

AI/TLDR

Buy me a coffee
Buy me a coffee

KAG

Knowledge-graph reasoning and Q&A framework for professional domains

RAG Frameworks & PlatformsOpen source
Language
Python
License
Apache-2.0
IN SHORT

What is KAG?

KAG (Knowledge Augmented Generation) is a logical reasoning and question-answering framework built on the OpenSPG engine and large language models. It is designed to build reasoning and Q&A solutions over vertical-domain knowledge bases, where unstructured documents, structured records, and expert rules all need to work together. It sits in the RAG Frameworks & Platforms category of the Retrieval & Knowledge (RAG) tools and is open-source, written in Python and licensed Apache-2.0.

Overview

KAG (Knowledge Augmented Generation) is a logical reasoning and question-answering framework built on the OpenSPG engine and large language models. It is designed to build reasoning and Q&A solutions over vertical-domain knowledge bases, where unstructured documents, structured records, and expert rules all need to work together.

Plain vector RAG often struggles with ambiguity, and GraphRAG built from open information extraction can add noise. KAG aims to reduce both problems by linking knowledge to text chunks through a mutual index and by using logical forms to guide how a question is planned, retrieved, and reasoned over. It supports multi-hop fact questions and reports results that beat earlier methods on its benchmarks.

What it does

  • Knowledge and chunk mutual indexing that ties graph structure back to the original text for richer context
  • Schema-constrained knowledge construction so domain expert rules and entity/event types can be represented
  • Logical-form-guided hybrid solver with planning, reasoning, and retrieval operators
  • Combines four problem-solving paths: exact-match retrieval, text retrieval, numerical calculation, and semantic reasoning
  • Supports both private knowledge bases and public web sources through the MCP protocol
  • Knowledge alignment via conceptual semantic reasoning to cut down on extraction noise

Getting started

KAG offers a product mode for ordinary users (run the full engine with Docker Compose) and a toolkit mode for developers (install the Python package). The toolkit path below is the quickest way to start building on macOS or Linux.

Launch the engine with Docker Compose

Download the docker-compose file and start the OpenSPG engine and its dependent services. Then open the product UI at http://127.0.0.1:8887 (default login openspg / openspg@kag).

bashbash
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

Create a Python environment

For the developer toolkit, create and activate a Python 3.10 environment using conda.

bashbash
conda create -n kag-demo python=3.10 && conda activate kag-demo

Clone and install KAG

Clone the repository and install the package in editable mode so you can use the built-in components.

bashbash
git clone https://github.com/OpenSPG/KAG.git
cd KAG && pip install -e .

Commands and code are distilled from the project's own documentation — always check the official repo for the latest.

When to use it

  • Building factual Q&A over a private, vertical-domain knowledge base that mixes documents and structured data
  • Answering multi-hop questions that need several reasoning steps rather than a single similarity lookup
  • Injecting domain expert rules and a custom schema to constrain how knowledge is extracted and reasoned over
  • Powering inference-driven Q&A inside agent workflows by exposing KAG over the MCP protocol

How KAG compares

KAG alongside other open-source rag frameworks & platforms tools AI/TLDR tracks, ranked by GitHub stars.

ToolStarsWhat it does
Dify★ 162kAn open-source platform with a visual workflow builder for creating LLM and RAG applications without writing much code.
graphify★ 155kTurns a folder of code, docs, PDFs and images into a local knowledge graph with tree-sitter AST parsing and Leiden communities — queryable by agents over MCP, no vector store.
RAGFlow★ 95kA RAG engine built around deep document understanding that turns complex files into a grounded, citation-backed question-answering layer.
Context7★ 65.7kContext7 pulls current, version-specific documentation and code examples for any library and feeds them into your LLM, available as a CLI skill or an MCP server.
Pathway★ 61.9kA Python framework with a Rust streaming engine that keeps ETL, real-time analytics and RAG pipelines continuously up to date as source data changes.
LightRAG★ 41kA graph-based RAG system that builds an entity-and-relationship knowledge graph for fast retrieval and easy incremental updates.
PageIndex★ 40.8kPageIndex turns long PDFs into a table-of-contents tree and uses LLM reasoning to retrieve relevant sections, with no vector database and no chunking.
KAG★ 9.2kKnowledge-graph reasoning and Q&A framework for professional domains