NexaRAG — Enterprise Document Intelligence & Hybrid RAG Platform
Hybrid retrieval, context orchestration, and citation-grounded LLM synthesis for complex enterprise documents.
Problem Statement
Naive RAG architectures suffer from semantic drift, missed alphanumeric identifiers (e.g. part numbers, policy codes), hallucinated citations, and catastrophic context overflow when ingesting complex 100+ page enterprise reports.
Engineering Goals
- Sub-30ms retrieval latency combining dense semantic search and lexical exact matching.
- Zero hallucinated citations with verifiable document page and line anchors.
- Hard multi-tenant isolation and fail-closed prompt-injection defenses.
- Predictable context assembly staying within a strict 6,000-token allocation.
NexaRAG — System ArchitectureVerified Pipeline
Select any pipeline stage below to inspect verified engineering details and data flow.
Stage: Document Ingestion
Role: IngestionExtracts text, preserves headings and bounding boxes, applies token-aware recursive chunking.
Execution Pipeline & Mechanics
Intelligent Ingestion & Chunking
Documents are parsed into structure-aware blocks preserving headers, tables, and page metadata, chunked at 512 tokens with 64-token overlap.
Dual-Engine Hybrid Retrieval
Parallel execution queries pgvector (HNSW cosine similarity) and an in-memory BM25 index. Candidate ranks are fused via Reciprocal Rank Fusion (RRF).
Cross-Encoder Precision Reranking
A distilled MS-MARCO cross-encoder scores query-passage pairs jointly, promoting passages with strong factual alignment.
7-Tier Context Fusion (RAG + CAG + MAG)
Balances live retrieval, pre-computed cached facts (CAG), and conversation history (MAG) under a dynamic 6,000-token budget ceiling.
Guardrails & Grounded SSE Streaming
NeMo Guardrails validates input/output against prompt injection and secret leakage, streaming tokens with page-specific citation anchors.
Engineering Challenges & Design Decisions
Decision: BM25 + pgvector over standalone vector-only search
Rationale: Pure dense vectors frequently fail on exact codes, invoice IDs, and specific regulation names. Hybrid RRF achieved 28% higher retrieval recall in enterprise documents.
Alternative Rejected: Vector-only embedding retrieval with OpenAI text-embedding-3-small.
Decision: Local cross-encoder reranking vs reranking LLM API
Rationale: Local cross-encoder executes in ~14ms without adding external API costs or network jitter to the hot retrieval loop.
Alternative Rejected: Third-party Cohere Rerank API.
Core Architectural Highlights
NexaRAG utilizes a layered architecture separating ingestion, dual-index retrieval, cross-encoder reranking, context orchestration, and guardrailed generation. State and vectors reside in PostgreSQL 16 with pgvector, while FastAPI handles non-blocking SSE streams to the React client.
Testing & Empirical Evaluation
321 automated pytest unit, integration, and security tests covering query classification, chunk boundary integrity, RLS tenant leak prevention, and RRF rank order stability.
Security & Reliability Defenses
Key Engineering Learnings
- •RRF parameter k=60 proved resilient across variable corpus sizes without hyperparameter fine-tuning per tenant.
- •Context budget capping at 6,000 tokens prevented downstream model degradation caused by 'lost in the middle' phenomena.