KAG
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.
KAG is a Python framework for building question-answering systems over professional knowledge bases using knowledge graphs alongside large language models, designed to handle multi-hop reasoning that standard retrieval approaches miss.
KAG (Knowledge Augmented Generation) is a Python framework for building question-answering systems over professional knowledge bases, using knowledge graphs alongside large language models. It was designed to address known weaknesses in the more common RAG (Retrieval-Augmented Generation) approach, where answers are retrieved by finding text passages that are semantically similar to a question. That similarity-based approach can fail on questions requiring logic, multi-step reasoning, or precise fact-checking.
The core idea is to represent knowledge in a structured graph rather than as raw text chunks, then use that structure to guide reasoning. When a user asks a question, the system breaks it into sub-problems and solves each one using the most appropriate method: exact matches against the knowledge graph, text retrieval, numerical calculations, or language model reasoning. The results are then combined to produce a final answer. This multi-hop approach allows it to answer questions that depend on chaining several facts together.
Knowledge can come from unstructured sources (documents, news articles, books) or structured data (tables, transaction records). The framework processes these into a unified knowledge graph, linking graph nodes back to the original text passages so both the structured knowledge and the source context are available during retrieval.
The project is built on the OpenSPG knowledge graph engine. It supports deployment via Docker and runs on macOS, Linux, and Windows. Version 0.8.0 added support for connecting to public data sources via the MCP protocol, including web search. The framework is licensed under Apache 2.0.
Where it fits
- Build a Q&A system over a large document collection that can answer multi-step questions by chaining facts from a knowledge graph.
- Process unstructured documents and structured tables into a unified knowledge graph so an LLM can reason over them together.
- Replace a standard RAG pipeline with KAG when your questions require logic, precise fact-checking, or multi-hop reasoning.
- Connect your KAG knowledge base to live web search via MCP to supplement internal knowledge with current information.