Problem Statement
Enterprise adoption of Generative AI faces critical production blockers: probabilistic hallucinations without source-level verification, unacceptable retrieval latency at scale, vulnerability to prompt injection attacks, and privacy leakage of sensitive PII or credentials. Standard naive RAG architectures cannot execute multi-step reasoning, lack mathematical precision, and fail to isolate cross-departmental tenant data.
Technical Architecture & Key Innovations
1. Hybrid Retrieval Engine with PGVector HNSW
Designed and built a dual-mode high-throughput retrieval system:
- PGVector HNSW Indexing: PostgreSQL 16 pgvector integration utilizing Hierarchical Navigable Small World (HNSW) graphs (
M=16, ef_construction=64) delivering sub-20ms semantic search with 2,185+ QPS throughput.
- Reciprocal Rank Fusion (RRF): Fuses dense semantic vector embeddings with sparse BM25 lexical keyword ranking, ensuring high precision for both contextual concepts and exact technical terminology.
- Resilient In-Memory Fallback: Zero-dependency SIMD/NumPy cosine similarity fallback for offline execution, unit testing, and instant development.
2. Bounded Multi-Step Autonomous Agent
Implemented a state machine orchestrator that replaces rigid linear pipelines with dynamic multi-step planning:
- Dynamic Tool Dispatch: Routes autonomously across
VectorSearchTool (semantic retrieval with RBAC scope), CalculatorTool (deterministic arithmetic & cloud sizing formulas), and CitationVerifierTool (claim-to-source provenance validation).
- Loop Prevention & Execution Latency Tracking: Enforces a bounded step limit (
max_steps) with comprehensive ToolExecutionTrace observability.
3. Two-Stage Deterministic Security Guardrails
Constructed a strict defense-in-depth perimeter surrounding LLM interactions:
- Pre-Execution Firewall: Screens incoming prompts for direct & indirect jailbreaks, obfuscated payloads (Base64, Hex, ROT13), SQL injections, shell command executions, and RBAC department violations.
- Post-Execution Sanitization & Grounding: Multi-pattern PII redactor (API keys, cloud tokens, credit cards, SSNs, emails, IPs) and sentence-level claim grounding verifier ensuring answers are 100% cited.
Key Results & Benchmarks
- 100% Test Pass Rate: 65 automated unit, integration, and UI tests running in under 4 seconds.
- 100% Adversarial Defense: Successfully intercepted and blocked 20/20 injection and privilege escalation vectors.
- 100% PII Masking: Verified complete redaction across 14/14 credential and personal identifier formats.
- Full Document AI Lifecycle: Multipart ingestion supporting Markdown, CSV, TSV, JSON Tables, and Scanned OCR with artifact remediation.
Tech Stack
Python 3.12
FastAPI
PostgreSQL 16
pgvector (HNSW)
Streamlit
SQLAlchemy (AsyncIO)
Pydantic v2
Docker Compose
GitHub Actions CI/CD
Pytest