Docs/What is SAG?

SAG

What is SAG?

Understand the SAG application, retrieval architecture, zleap-sag, and their relationship to Open Context.

SAG is an open-source knowledge-base application for people and Agents, as well as an original retrieval architecture with the same name. OCTX is compatible with SAG's Chunk-Event-Entity hypergraph data structure and can carry that data through the optional SAG-Structured Capability; creating, distributing, or using OCTX does not require SAG.

Why support SAG? Through an Event-Entity index and query-time dynamic hyperedges, SAG combines the semantic-retrieval strengths of traditional RAG with the relational-reasoning strengths of GraphRAG in one retrieval pipeline, without maintaining and joining two separate systems. The SAG paper reports the best result on 8 of 9 Recall@1/2/5 metrics across HotpotQA, 2WikiMultiHopQA, and MuSiQue, making it the leading overall approach in this set of public multi-hop RAG benchmarks.

In One Sentence

SAG turns distributed documents and data into searchable, connected, and traceable knowledge:

text
Sources and documents
  → parsing, chunking, and structured extraction
  → Chunks, Events, Entities, and relations
  → retrieval, source tracing, and cited Agent answers
  → reuse through APIs, MCP, or OCTX

Three Easily Confused Names

NameWhat it isRelationship to OCTX
SAG applicationThe complete knowledge-base application used directly by people. It handles knowledge import, organization, retrieval, provenance, and Agent Q&A.It can create, import, and use .octx Packages.
SAG retrieval architectureAn original retrieval method based on an Event-Entity index and query-time dynamic hyperedges. It provides semantic retrieval and relational reasoning in a single pipeline rather than joining traditional RAG and GraphRAG.It defines how SAG generates and retrieves Chunk, Event, and Entity structures, but is not a prerequisite for using OCTX.
zleap-sagThe Python engine that implements the SAG retrieval architecture, providing extraction, retrieval, and import/export adapters between .octx and SAG.It depends on the general-purpose octx package and adds import_octx() and export_octx().

How SAG Processes Knowledge

  1. Import sources such as files or web pages and parse documents into traceable source chunks.
  2. Extract semantically complete Events and Entities used for indexing and expansion from those source chunks.
  3. Store Chunks, Events, Entities, and their relations while building vector and full-text indexes.
  4. At query time, find relevant events and entities first, then construct the local associations needed for the current question through shared entities.
  5. Return original Chunks as evidence so both retrieval results and Agent answers can be traced back to the source text.

The SAG paper is titled SAG: SQL-Retrieval Augmented Generation with Query-Time Dynamic Hyperedges. See the SAG paper for the complete method.

Why SAG Appears in the Open Context Documentation

SAG produces documents, Chunks, Events, Entities, relations, and vectors. Historically, these results were usually stored only in SAG's own database and indexes; Open Context packages them as portable, verifiable assets.

The boundary between them is:

  • SAG generates, retrieves, and uses knowledge.
  • OCTX describes, packages, and validates portable context.
  • SAG-Structured Capability declares that an OCTX Package already carries complete data that can be imported directly into SAG's structural layer.

SAG can therefore produce and consume OCTX, but it is not a required part of OCTX. Other knowledge systems can adopt OCTX directly and implement their own import, export, and retrieval adapters.