A developer post describes how a production Retrieval-Augmented Generation (RAG) system is optimized using measured, tunable retrieval components rather than fixed “demo defaults.” The author says production challenges include splitting legal clauses with fixed-size chunks, losing signal in overly large API-document chunks, and needing conversational overlap for support tickets. To address this, the system uses different chunking strategies by document type, such as recursive, semantic, and LLM/agentic chunking, with examples including 1024-token chunks for legal contracts (94% recall@10) and 1500-token agentic chunks for an internal wiki (97% recall@10).

On retrieval, the post describes a hybrid approach combining BM25 and vector search, then fusing results with Reciprocal Rank Fusion and applying a cross-encoder reranker as a “50→5” funnel. It also describes query transformation by expanding ambiguous user queries into multiple search queries and evaluating recall@10 improvements versus a single query. Hyperparameters are tuned using Bayesian optimization (Optuna) against a “golden set” of 200 queries with a latency/recall tradeoff.

The post reports baseline-to-optimized gains over six months: recall@10 rising from 78% to 95%, p95 retrieval latency dropping from 850ms to 320ms, hallucination rate falling from 12% to 3%, and cost/query decreasing from $0.008 to $0.005.