explaingit

openspg/kag

8,741PythonAudience · researcherComplexity · 4/5LicenseSetup · hard

TLDR

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.

Mindmap

mindmap
  root((repo))
    What it does
      Knowledge graph Q and A
      Multi-hop reasoning
      Structured retrieval
    Architecture
      Knowledge graph
      LLM reasoning
      Sub-problem decomposition
    Input types
      Documents and articles
      Tables and records
    Deployment
      Docker
      macOS and Linux
      MCP web search
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

Things people build with this

USE CASE 1

Build a Q&A system over a large document collection that can answer multi-step questions by chaining facts from a knowledge graph.

USE CASE 2

Process unstructured documents and structured tables into a unified knowledge graph so an LLM can reason over them together.

USE CASE 3

Replace a standard RAG pipeline with KAG when your questions require logic, precise fact-checking, or multi-hop reasoning.

USE CASE 4

Connect your KAG knowledge base to live web search via MCP to supplement internal knowledge with current information.

Tech stack

PythonDockerOpenSPG

Getting it running

Difficulty · hard Time to first run · 1h+

Requires Docker plus the OpenSPG knowledge graph engine and an LLM API endpoint configured before use.

Use freely for any purpose including commercial use with attribution under the Apache 2.0 license.

In plain English

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.

Copy-paste prompts

Prompt 1
I have a collection of PDF documents and want to build a Q&A system using KAG that can answer multi-hop questions. Walk me through ingesting the documents into a knowledge graph and running a question against it.
Prompt 2
Show me how KAG decomposes a complex question into sub-problems and routes each one to the right solver, graph match, text retrieval, or LLM reasoning.
Prompt 3
How do I deploy KAG using Docker on a Linux machine and connect it to an OpenAI-compatible LLM endpoint?
Prompt 4
I want to use KAG's MCP support to connect to a web search source. Show me the configuration and an example query that uses web search alongside the internal knowledge graph.
Open on GitHub → Explain another repo

← openspg on gitmyhub — every repo by this author, as a profile.

Verify against the repo before relying on details.