Metadata-Version: 2.4
Name: apex-rag
Version: 1.0.2
Summary: A production-grade, local-first Agentic RAG library using structural document navigation.
Project-URL: Homepage, https://github.com/abinivas-17/apex-rag
Project-URL: Repository, https://github.com/abinivas-17/apex-rag
Project-URL: Issues, https://github.com/abinivas-17/apex-rag/issues
Project-URL: Documentation, https://github.com/abinivas-17/apex-rag#readme
Author: G S Abinivas
License: MIT License
        
        Copyright (c) 2026 G S ABINIVAS
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
License-File: AUTHORS.md
License-File: LICENSE
Keywords: agentic,document-search,llm,local-ai,nlp,ollama,rag,retrieval
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Science/Research
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Requires-Python: >=3.10
Requires-Dist: aiosqlite>=0.20.0
Requires-Dist: markitdown>=0.0.1a2
Requires-Dist: ollama>=0.2.0
Requires-Dist: rich>=13.7.0
Requires-Dist: sqlalchemy>=2.0.0
Provides-Extra: all
Requires-Dist: alembic>=1.13.0; extra == 'all'
Requires-Dist: asyncpg>=0.29.0; extra == 'all'
Requires-Dist: docling>=1.16.0; extra == 'all'
Requires-Dist: fastapi>=0.111.0; extra == 'all'
Requires-Dist: httpx>=0.27.0; extra == 'all'
Requires-Dist: mkdocs-material>=9.5.0; extra == 'all'
Requires-Dist: mkdocs>=1.6.0; extra == 'all'
Requires-Dist: mkdocstrings[python]>=0.25.0; extra == 'all'
Requires-Dist: mypy>=1.10.0; extra == 'all'
Requires-Dist: numpy>=1.24.0; extra == 'all'
Requires-Dist: opentelemetry-api>=1.25.0; extra == 'all'
Requires-Dist: opentelemetry-exporter-otlp-proto-grpc>=1.25.0; extra == 'all'
Requires-Dist: opentelemetry-sdk>=1.25.0; extra == 'all'
Requires-Dist: prometheus-client>=0.20.0; extra == 'all'
Requires-Dist: psycopg2-binary>=2.9.9; extra == 'all'
Requires-Dist: pydantic>=2.7.0; extra == 'all'
Requires-Dist: pytest-asyncio>=0.23.0; extra == 'all'
Requires-Dist: pytest-cov>=5.0.0; extra == 'all'
Requires-Dist: pytest>=8.2.0; extra == 'all'
Requires-Dist: python-multipart>=0.0.9; extra == 'all'
Requires-Dist: ruff>=0.4.0; extra == 'all'
Requires-Dist: sentence-transformers>=3.0.0; extra == 'all'
Requires-Dist: tox>=4.0.0; extra == 'all'
Requires-Dist: uvicorn[standard]>=0.29.0; extra == 'all'
Provides-Extra: dev
Requires-Dist: httpx>=0.27.0; extra == 'dev'
Requires-Dist: mypy>=1.10.0; extra == 'dev'
Requires-Dist: pytest-asyncio>=0.23.0; extra == 'dev'
Requires-Dist: pytest-cov>=5.0.0; extra == 'dev'
Requires-Dist: pytest>=8.2.0; extra == 'dev'
Requires-Dist: ruff>=0.4.0; extra == 'dev'
Requires-Dist: tox>=4.0.0; extra == 'dev'
Provides-Extra: docling
Requires-Dist: docling>=1.16.0; extra == 'docling'
Provides-Extra: docs
Requires-Dist: mkdocs-material>=9.5.0; extra == 'docs'
Requires-Dist: mkdocs>=1.6.0; extra == 'docs'
Requires-Dist: mkdocstrings[python]>=0.25.0; extra == 'docs'
Provides-Extra: migrations
Requires-Dist: alembic>=1.13.0; extra == 'migrations'
Provides-Extra: monitoring
Requires-Dist: prometheus-client>=0.20.0; extra == 'monitoring'
Provides-Extra: postgres
Requires-Dist: asyncpg>=0.29.0; extra == 'postgres'
Requires-Dist: psycopg2-binary>=2.9.9; extra == 'postgres'
Provides-Extra: telemetry
Requires-Dist: opentelemetry-api>=1.25.0; extra == 'telemetry'
Requires-Dist: opentelemetry-exporter-otlp-proto-grpc>=1.25.0; extra == 'telemetry'
Requires-Dist: opentelemetry-sdk>=1.25.0; extra == 'telemetry'
Provides-Extra: vectors
Requires-Dist: numpy>=1.24.0; extra == 'vectors'
Requires-Dist: sentence-transformers>=3.0.0; extra == 'vectors'
Provides-Extra: web
Requires-Dist: fastapi>=0.111.0; extra == 'web'
Requires-Dist: httpx>=0.27.0; extra == 'web'
Requires-Dist: pydantic>=2.7.0; extra == 'web'
Requires-Dist: python-multipart>=0.0.9; extra == 'web'
Requires-Dist: uvicorn[standard]>=0.29.0; extra == 'web'
Description-Content-Type: text/markdown

<p align="center">
  <img src="https://img.shields.io/badge/ApexRAG-v0.2.0--dev-6366f1?style=for-the-badge" alt="ApexRAG">
</p>

<p align="center">
  <strong>The High-Accuracy, Local-First Structural Retrieval Infrastructure.</strong><br>
  <em>Stop guessing with vectors. Start navigating with agents.</em>
</p>

## 🚀 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

```bash
pip install apex-rag
```

```python
import asyncio
from apex_rag import ApexIndex, Orchestrator
from apex_rag.enterprise.auth.models import TenantContext

async def main():
    # Setup Tenant Context
    ctx = TenantContext(tenant_id="corp-abc", user_id="user-1", roles=["admin"])
    
    async with await ApexIndex.create() as index:
        # Ingest preserving structure
        doc_id = await index.ingest("financial_report.md", tenant_id=ctx.tenant_id)
        
        # Multi-Agent Reasoning Query
        # Uses the Planner -> Navigator -> Critic loop internally
        result = await index.orchestrate_query("Compare the revenue between Q2 and Q3", doc_id)
        print(result)

asyncio.run(main())
```

## 📖 Documentation

- [Full Architecture Details](docs/ARCHITECTURE.md)
- [API Reference](docs/api/apex-index.md)

## 📄 License
MIT License.
