OpenSPG/KAG
OpenSPG graph-and-text RAG for multi-hop reasoning and domain Q&A
Automated SPDX check for reference only — not legal advice. Disclaimer
GitHub Star History
Full-history star trajectory from GitHub official history. Switch ranges or hover any point for exact counts.
Evidence-Backed Technical Brief
AI Deep ReviewArchitecture & Core Mechanics
KAG is a Python framework built on the OpenSPG engine. Its two released components divide ingestion from query execution. The kg-builder extracts and normalizes knowledge, supports open extraction alongside schema-constrained construction for the same entity or event type, and cross-indexes graph structures with source text chunks. The kg-solver turns a natural-language question into a logical-form plan: planning, retrieval, and reasoning operators can combine exact matches, text search, graph relationships, semantic reasoning, and numerical computation in one workflow.
The architecture also names a third component, kag-model, which is not part of the released builder and solver. Adaptation for KAG-Thinker in v0.8.0 does not imply that the model ships with the framework. The Python dependency set includes NetworkX, the Neo4j client, OpenAI, DashScope, Ollama, and mcp==1.6.0; those entries do not establish that every integration is enabled or required in every deployment. MCP is the explicit protocol boundary for connecting public sources and making KAG question answering available to agent workflows.
Key Capabilities & Differentiators
KAG fits questions that require more than fetching a similar passage: resolve an entity, follow a relationship, retrieve its source context, and perform a calculation where needed. The builder aligns concepts and normalizes properties to bring structured records, unstructured documents, and expert rules into a shared graph. The dependency manifest includes PDF, DOCX, and Markdown tooling, but parser availability does not establish reliable extraction for every document layout.
In v0.8.0, private knowledge bases support Outline, Summary, KnowledgeUnit, AtomicQuery, Chunk, and Table indexes; public knowledge bases can draw on sources such as web search and location-based services through MCP. Applications can attach multiple knowledge bases and select retrievers according to the indexes built for each. The v0.7 solver refactor added static and iterative planning, Simple and Deep Reasoning modes, streamed output, and links to original sources. Those links make answers easier to audit, but do not by themselves verify that the cited material supports every inference.
Trade-offs & Limitations
A vector-only RAG pipeline is the cheaper baseline to build and maintain when most questions are answered by one or two passages. A simpler GraphRAG pipeline may be enough when graph traversal primarily supplies additional context. KAG earns its extra complexity when a query needs to execute different steps, such as joining facts across entities, looking up an exact value, and calculating a result while preserving access to source text.
The cost is more work on schemas, extraction quality, entity alignment, and index rebuilds as the corpus changes. A wrong entity match can contaminate a multi-hop answer, and iterative planning can introduce variable latency and model spend. Evaluate those risks on representative questions, including cases with missing evidence, rather than assuming that a richer reasoning pipeline improves all answers. Apache-2.0 supports commercial use, but model, image, API, and public-data terms still need separate review.
Hardware & Deployment Guide
For product mode, start the OpenSPG engine and dependent images with Docker Compose using dev/release/docker-compose-west.yml from the separate OpenSPG/openspg repository. The documented download tracks the master branch, so review the Compose file and pin a tested revision and image versions for repeatable deployments. Windows requires WSL 2 or Hyper-V alongside Docker and Docker Compose. Developer mode uses the same backend services and installs the Python toolkit with pip install -e . from the KAG checkout. Change the default product credentials before exposing the service.
Self-hosting OpenSPG is separate from running model inference locally. The manifest includes clients for hosted providers and Ollama, but an offline deployment also needs local model and embedding endpoints, pre-staged dependencies and images, and an audit of public MCP integrations. Size storage for source chunks and indexes, measure ingestion separately from online query load, and budget for model calls on iterative queries. v0.7 refactored planning and reasoning; v0.8.0 separated applications from knowledge bases. When upgrading, validate application-to-base mappings and retriever selection before moving traffic.
Teams building professional Q&A over records, documents, and expert rules, where answers need multi-step reasoning and traceable source evidence.
Most questions are single-passage lookups, or the team cannot maintain schemas, extraction quality, and a separate OpenSPG deployment.
Quick Start & Installation
# 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
Comparison vs. Top RAG, Data & Memory Alternatives
Full comparison →| Repository | Stars | 7d Trend | Stack | License | Core Positioning |
|---|---|---|---|---|---|
| KAG ★ | 9.2k | +16 | Python | Apache-2.0 | OpenSPG graph-and-text RAG for multi-hop reasoning and domain Q&A |
| auto-ontology | 19.1k | +3.2k | Python | Apache-2.0 | An ontology framework that grounds agent-generated SQL in reviewed business defi |
| llama_index | 53.1k | +110 | Python | MIT | A modular Python SDK for document ingestion, indexing, and RAG |
| langextract | 39.5k | +85 | Python | Apache-2.0 | Python SDK for extracting structured data with traceable source spans |
AI Context Briefing (for Claude / Cursor / Windsurf)
Standardized architecture summary & quickstart commands ready to paste into coding agents.
curl -sL https://repoforai.com/repo/OpenSPG/KAG.md
Active README embeds unlock Hot-Tier 6h Telemetry Refresh automatically (zero pay-to-rank).
Frequently Asked Questions about KAG
How do applications connect to knowledge bases and agents?
Do I need a GPU, and what should I size for?
Can I use KAG commercially and keep the deployment private?
When should I choose KAG over vector RAG or a simpler GraphRAG pipeline?
Upstream README & Documentation
This profile focuses on independent engineering analysis and live telemetry. Read the full upstream README, changelog, and examples directly on GitHub.
Top 10 Breakout Open-Source AI Repos, Every Thursday
Signal-only digest of fast-growing AI repos, SPDX license alerts, and architecture picks. Zero spam.
Zero spam · 1-click unsubscribe · Privacy Policy