# SAG

> Open-source knowledge base app and retrieval architecture that turns documents into searchable, connected, source-traceable knowledge for people and agents.

SAG is an open-source knowledge base application from Zleap-AI, built on its own retrieval architecture that indexes documents as events and entities. Users upload documents once, then search across sources, inspect an event-entity graph, ask questions with citations, or expose the knowledge to other applications through API or MCP. It is released under the MIT License and ships as a desktop app, a Docker self-hosted stack, and a Python engine.

## What It Is

SAG is a local-first, single-user knowledge base that takes sources and documents and produces structured knowledge, search with source tracing, and cited agent answers. Documents (Markdown, text, PDF, Office and others) are normalized, chunked, embedded, and processed for event and entity extraction in the background. Every retrieval result stays connected to the original text chunk. It starts with SQLite and LanceDB and requires no external database, with a documented path to PostgreSQL/pgvector and other production backends.

## How the Retrieval Architecture Works

The README describes SAG as an original architecture that replaces both traditional RAG and GraphRAG. Each chunk becomes one semantically complete event with multiple indexing entities. At query time, SQL joins over shared entities create local dynamic hyperedges, so no global graph is pre-built or maintained. Retrieval modes include Fast (vector), Fast (multi_es_fast), and Precise (multi). The project's paper reports best results on HotpotQA, 2WikiMultiHopQA, and MuSiQue under a shared embedding and LLM configuration, according to the authors.

## Using and Integrating It

The app provides cross-source or source-scoped search, clickable citations in multi-turn agent chat, an Explore mode, and 2D/3D event-entity graph views. For integration it offers a self-hosted REST/OpenAPI API, an OpenAI-compatible chat completions endpoint, a Knowledge MCP server, a Dify external knowledge base endpoint, a DeepSeek Harness plugin, and the sag-cli tool that mounts the MCP into Codex or Claude Code. Developers can also use the zleap-sag Python package and its DataEngine API directly.

## Setup Path

Desktop installers are published for macOS (Apple Silicon) and Windows x64 and bundle the web workspace and local backend. Alternatively, docker compose brings up the web app and API locally. Embeddings are needed for indexing and vector retrieval, and an LLM is needed for event extraction and answers; the UI starts without model credentials. Password auth mode is available for remote deployments.

## Features
- Event-entity indexing with query-time dynamic hyperedges
- Document ingestion with parsing, chunking, embedding and extraction
- Cross-source and source-scoped search with multiple retrieval modes
- Source tracing back to original chunks
- Event-entity knowledge graph in 2D and 3D views
- Explore mode knowledge universe
- Agent chat with clickable citations
- OpenAI-compatible chat completions endpoint
- Knowledge MCP server and sag-cli for Codex and Claude Code
- Dify external knowledge base endpoint
- Self-hosted REST/OpenAPI API
- Python engine package zleap-sag
- MinerU and AnyDoc PDF/document parsing options
- SQLite/LanceDB default with PostgreSQL/pgvector option

## Integrations
MCP, Codex, Claude Code, DeepSeek Harness, Dify, OpenAI-compatible APIs, MinerU, AnyDoc, MarkItDown, PostgreSQL, pgvector, LanceDB, Elasticsearch, OceanBase, 302.AI, Zhipu, Alibaba Cloud Bailian

## Platforms
MACOS, WINDOWS, WEB, API, CLI, DEVELOPER_SDK

## Pricing
Open Source

## Version
1.8.11

## Links
- Website: https://zleap.com
- Documentation: https://github.com/Zleap-AI/SAG#user-guide
- Repository: https://github.com/Zleap-AI/SAG
- EveryDev.ai: https://www.everydev.ai/tools/sag
