Skip to main content

High-accuracy Structural RAG library using Abstract Syntax Trees (AST) for precise document navigation.

Project description

ApexRAG

The High-Accuracy, Local-First Structural Retrieval Infrastructure.
Stop guessing with vectors. Start navigating with agents.

🚀 Overview

ApexRAG has evolved from a simple RAG wrapper into a Multi-Agent, Structural Reasoning Engine built for enterprise deployments.

Traditional RAG relies on vector proximity, chopping documents into arbitrary chunks and losing crucial structural context (like section headings, table definitions, and document hierarchy), leading to hallucinations.

ApexRAG solves this by converting documents into a Universal Document AST (Abstract Syntax Tree) and using an Orchestrator of specialized LLM Agents (Planner, Navigator, Critic) to explicitly "walk" the document's structure to find exact, verifiable answers.

🏗️ The 3-Phase Architecture

Phase 1: Structural Foundation

  • Universal Document AST: Documents (PDFs, Markdown, source code) are parsed into strict hierarchical trees (ASTNode), preserving exact paragraph-to-heading relationships.
  • Deterministic Retrievers: Initial filtering uses keyword density, FTS5, and structural heading overlap to locate candidate branches without expensive LLM calls.
  • Strict Verification: A StrictLeafVerifier engine empirically checks if a found node actually answers the query, acting as a firewall against hallucination.

Phase 2: Structural Reasoning Engine

  • Multi-Agent Orchestrator: Complex queries are managed by three agents working in concert:
    • Planner Agent: Breaks down complex, multi-hop queries (e.g., "Compare Q2 and Q3 revenue") into discrete sub-queries.
    • Navigator Agent: Explores the AST tree and Semantic Map signposts to find the correct data for each sub-query.
    • Critic Agent: Evaluates the aggregated context to ensure all sub-queries were answered before synthesizing the final response.
  • Structural Retrieval Graph (SRG): Nodes can have GraphEdge relations to other nodes (e.g., REFERENCES_TABLE), enabling non-linear reasoning.

Phase 3: Enterprise Ecosystem Platform

  • Multi-Tenant RBAC: Core SQLAlchemy models (NodeData, SemanticModelData, GraphEdgeData) and FastAPI middlewares strictly enforce data isolation via tenant_id boundaries.
  • Distributed Ingestion: A DistributedIndexer protocol allows for massive horizontal scaling of document parsing using Celery or Redis queues.
  • Code Intelligence: Includes a PythonCodeParser that extracts ASTs from source code to enable structural code reasoning.
  • OpenTelemetry: Every agent action ([PLANNING], [NAVIGATING]) is wrapped in distributed traces for production monitoring.

📦 Quick Start

pip install apex-rag
export OPENAI_API_KEY="sk-..."

Zero to citation-grounded answers in 3 lines:

import asyncio
from apex_rag import ApexIndex, OpenAIProvider

async def main():
    # 1. Initialize with your preferred provider (OpenAI, Anthropic, Groq, Ollama)
    async with await ApexIndex.create(model=OpenAIProvider("gpt-4o")) as index:
        
        # 2. Ingest a document (preserves exact structural layout)
        doc_id = await index.ingest("financial_report.pdf")
        
        # 3. Query (triggers Planner -> Navigator -> Critic loop)
        answer = await index.orchestrate_query("Compare Q2 and Q3 revenue", doc_id)
        
        print(answer)
        # > "Q2 revenue was $40M, while Q3 grew to $52M. [Node ID: f3a1...]"

asyncio.run(main())

📖 Documentation

📄 License

MIT License.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

apex_rag-1.0.3.tar.gz (436.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

apex_rag-1.0.3-py3-none-any.whl (301.6 kB view details)

Uploaded Python 3

File details

Details for the file apex_rag-1.0.3.tar.gz.

File metadata

  • Download URL: apex_rag-1.0.3.tar.gz
  • Upload date:
  • Size: 436.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for apex_rag-1.0.3.tar.gz
Algorithm Hash digest
SHA256 31f4a3cf305a896da4485d046993a9063e67b30eb276b0acf8fca2cc789d8f75
MD5 bc48a45aca2e5843900b8ee69e724348
BLAKE2b-256 1e840d5157859cbb3930caa9d472332ac367ce4c86de455b57cb22663e515725

See more details on using hashes here.

Provenance

The following attestation bundles were made for apex_rag-1.0.3.tar.gz:

Publisher: ci.yml on abi6374/ApexRAG

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file apex_rag-1.0.3-py3-none-any.whl.

File metadata

  • Download URL: apex_rag-1.0.3-py3-none-any.whl
  • Upload date:
  • Size: 301.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for apex_rag-1.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 bd139a5cd9e2b35b399807405e1617b64d590fca2b690b79ba3be92a80a0890d
MD5 51c219b0882fa0daa5b1ff44a69c12e4
BLAKE2b-256 3cb16ed2730ba3bc33fcd6535fa1777e89f776c1583810865d173bb46c5c4243

See more details on using hashes here.

Provenance

The following attestation bundles were made for apex_rag-1.0.3-py3-none-any.whl:

Publisher: ci.yml on abi6374/ApexRAG

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page