SAG: a retrieval architecture that combines semantic search and relational reasoning via query-time dynamic hyperedges
SAG: a retrieval architecture that combines semantic search and relational reasoning via query-time dynamic hyperedges
What it solves
SAG addresses the limitations of traditional RAG (which relies on semantic similarity) and GraphRAG (which requires expensive offline graph construction and complex maintenance). It provides a system that can handle both semantic retrieval and relational reasoning without needing to maintain two separate systems or a global knowledge graph.
How it works
SAG introduces a new retrieval architecture based on "SQL-Retrieval Augmented Generation with Query-Time Dynamic Hyperedges."
- Indexing: Documents are parsed into chunks. For each chunk, the system extracts one "event" (the complete meaning) and multiple "entities" (lightweight index points). These are stored in relational storage alongside their vector embeddings.
- Retrieval: Instead of pre-building a global graph, SAG finds seed entities and events using semantic signals. It then uses SQL joins over shared entities to expand the search space locally at query-time, creating "dynamic hyperedges" only for the relevant data.
- Evidence: The final output is always mapped back to the original source chunks to ensure traceability and citations.
Who it’s for
- Individuals: Users who want a local-first knowledge base to organize scattered documents and chat with them using citations.
- AI Agents: Developers building agents that need a structured, searchable, and traceable knowledge base via API or Model Context Protocol (MCP).
- Developers: Those looking for a high-performance RAG engine (
zleap-sagPython package) to integrate into their own services.
Highlights
- SOTA Performance: Outperforms HippoRAG 2 on multi-hop retrieval benchmarks (HotpotQA, 2WikiMultiHopQA, MuSiQue).
- Local-First: Starts with SQLite and LanceDB, requiring no external database for initial setup.
- Traceability: Every result and citation can be traced back to the exact original chunk of text.
- Extensible Integration: Supports OpenAI-compatible chat endpoints and MCP for integration with agents like Claude Code or Codex.
- Flexible Storage: Supports multiple backends including PostgreSQL/pgvector and Elasticsearch.
Sources
- undefinedZleap-AI/SAG