A structured, metric-driven narrative for technical architecture interviews, executive presentations, and engineering portfolio reviews.
I designed and built an enterprise-grade Agentic Retrieval-Augmented Generation (RAG) platform to solve the core challenges of querying continuously changing organizational knowledge. Naive “upload document $\rightarrow$ vector search $\rightarrow$ LLM answer” pipelines fail in production: they hallucinate without verifiable citations, lack awareness of document effective dates, cannot enforce role-based access control (RBAC), and break down on multi-hop questions requiring synthesis across multiple sources. My core engineering requirements were strict: zero hallucinations via automated citation verification, temporal document version awareness, pre-retrieval SQL RBAC preventing cross-role data leakage, and a fully reproducible evaluation framework wired into CI/CD.
I documented technology selection through 8 formal Architecture Decision Records (ADRs). To eliminate operational complexity, I standardized on a unified PostgreSQL foundation with pgvector for 1024-dimensional dense embeddings (BAAI/bge-m3) and native Full-Text Search (tsvector) for lexical keyword matching. These branches run concurrently and fuse via Reciprocal Rank Fusion (RRF, $k=60$). Candidates are refined through a cross-encoder reranker (BAAI/bge-reranker-v2-m3) to isolate the top 5 high-precision evidence chunks. Rather than adopting heavy orchestration frameworks like LangGraph, I engineered a custom deterministic Python state machine with explicit transitions (START $\rightarrow$ CLASSIFY $\rightarrow$ PLAN $\rightarrow$ TOOL_CALL $\rightarrow$ RETRIEVE $\rightarrow$ RERANK $\rightarrow$ EVIDENCE_VALIDATION $\rightarrow$ GENERATION $\rightarrow$ CITATION_VALIDATION $\rightarrow$ END). Observability was integrated from day one using OpenTelemetry distributed tracing and Langfuse telemetry.
The platform’s performance was validated against a 50-item golden evaluation dataset across 6 benchmark baselines:
evals/reports/comparison.md); dense-only measured 0.886 — the hybrid win is the lexical tail (exact codes/acronyms).max_steps=4 per plan by default); measured behavior compliance 0.960 with the lowest unexpected-failure rate (0.040) of all six baselines, under hard caps (8 steps / 10 tool calls / 30 s) with sha256 argument-hash loop detection (src/agents/state.py).rag.access_matches with zero unauthorized citations in every committed eval report (CI-gated to exactly 0), and a defense stack whose regex layer flags all 10 known injection patterns by construction (unit-tested) with a judge layer behind it.evals/reports/eval-20261023-104203.json); real-pipeline economics are a design estimate from the unit-tested PRICE_TABLE — never quoted as a measurement. The evaluation harness is wired into CI as an automated quality gate (behavior ≥ 0.90, Recall@k ≥ 0.80, unauthorized citations = 0; missing metrics fail the gate).pgvector allows relational document metadata, full-text inverted indexes (tsvector), vector embeddings (vector(1024)), user permissions, and persistent memories to exist in a single transactional store. It enables pre-retrieval RBAC directly in the SQL WHERE clause, eliminating context starvation and security leakage.AgentState dataclass, hard recursion bounds (max_steps=8, max_tool_calls=10), and sub-millisecond loop detection using SHA-256 parameter hashing. Writing a clean ~290-line orchestrator plus a 96-line AgentState dataclass gave us total transparency, direct 1:1 mapping to OpenTelemetry spans, and zero vendor lock-in.[N] citation markers tied directly to chunk IDs.HALLUCINATION_DETECTED.| Engineering Metric | Measured Value | Production Context |
|---|---|---|
| Metric | Measured value | Context (mock provider unless noted) |
| Recall@k (hybrid+reranked) | 0.943 | vs 0.486 lexical-only, 0.886 dense-only — golden 50 (evals/reports/comparison.md) |
| MRR (hybrid+reranked) | 0.900 | vs 0.486 lexical-only — same report |
| Behavior compliance (agentic) | 0.960 | best of six baselines; unexpected failures 0.040 |
| Verified citation rate | 1.000 | unauthorized citations CI-gated to exactly 0 |
| Injection regex layer | 10/10 patterns | flagged by construction, unit-tested (src/security/prompt_injection.py) |
| Judge layer | blocked | implemented, requires a real provider (llm_judge_methodology.md) |
| p95 / cost (smoke) | 5 ms / $2.67e-05 | committed smoke report; real-LLM figures are design estimates |