From naive retrieval to agentic RAG: what works, what breaks and how to evaluate.
Why Naive RAG Breaks in Production
Retrieval-Augmented Generation (RAG) has become the de facto architecture for connecting large language models to proprietary enterprise documents. However, early prototypes built on basic vector similarity search ('Naive RAG') almost always fail when exposed to real-world documents.
Naive chunking (chopping text every 500 characters) severs semantic context across paragraphs, tables, and headers. Raw cosine similarity in vector space frequently retrieves text that sounds semantically similar but fails to answer the precise factual query.
Building enterprise-ready RAG requires advanced retrieval engineering, query transformation, hybrid ranking, and evaluation loops.
Pattern 1: Hybrid Search (Dense Vectors + Sparse BM25)
Dense embedding models are exceptional at capturing conceptual similarity, but they struggle with exact keyword matching, product SKUs, part numbers, and acronyms. Conversely, traditional sparse keyword algorithms like BM25 excel at exact matching but fail with synonyms and semantic context.
Production systems combine both techniques using Reciprocal Rank Fusion (RRF). Queries are executed concurrently against a vector database and an inverted index (e.g., Elasticsearch, OpenSearch, or Qdrant). The results are normalized and merged, delivering the highest retrieval accuracy across both conceptual and keyword-specific queries.
Pattern 2: Contextual Chunking and Parent Document Retrieval
There is an inherent tension in chunk sizing: small chunks (100–200 tokens) yield higher embedding precision for vector matching, but lack the surrounding narrative context required for the model to generate a comprehensive answer.
The Parent Document Retrieval pattern resolves this conflict. The ingestion pipeline indexes small child chunks for vector search, but stores references to their parent document sections (1,000–2,000 tokens).
When a child chunk matches the query, the retrieval engine fetches and injects the parent section into the LLM context window, ensuring the model has full contextual grounding without sacrificing search precision.
- 01Child Chunks: Embed precise 150-word propositions for high-density vector search.
- 02Parent Chunks: Retrieve full 1,000-word parent sections to provide context to the LLM.
- 03Metadata Preservation: Retain source URL, section headers, document title, and publication timestamp.
Pattern 3: Cross-Encoder Reranking
Bi-encoders (standard embedding models) evaluate queries and documents independently to generate vector coordinates, which allows for fast approximate nearest neighbor (ANN) search over millions of vectors. However, bi-encoders miss complex token-level interactions between the question and the candidate passage.
A two-stage retrieval pipeline mitigates this. The vector index retrieves the top 30 to 50 candidate passages in single-digit milliseconds. These candidates are then passed through a cross-encoder model (such as Cohere Rerank or BGE-Reranker), which performs full cross-attention between query and passage tokens.
The cross-encoder filters out semantic false positives, ensuring that only the top 3 to 5 highest-relevance passages are passed into the final LLM prompt.
Pattern 4 & 5: Query Rewriting and Self-Reflective RAG
Users frequently submit ambiguous, underspecified, or multi-part questions. Passing these raw queries directly to a vector database yields noisy retrieval results.
Query Rewriting uses a fast, lightweight model to expand the user's input into multiple search queries, resolve coreferences from chat history, and generate hypothetical document embeddings (HyDE).
In Self-Reflective RAG (Self-RAG), the model evaluates whether the retrieved documents are actually relevant to the question before attempting to generate an answer. If relevance is low, it triggers a query refinement loop or informs the user that information is unavailable, effectively eliminating ungrounded hallucinations.
- 01HyDE: Generate a hypothetical answer first, then embed that answer to retrieve matching documents.
- 02Multi-Query Expansion: Decompose complex inquiries into 3 focused sub-queries.
- 03Hallucination Verification: Verify that every factual claim in the response is directly supported by citations.
Pattern 6 & 7: Graph RAG and Automated Evaluation with Ragas
For complex domains with interconnected relationships (such as legal contracts, corporate hierarchies, or medical literature), vector search alone fails to traverse multi-hop connections. Graph RAG structures documents into knowledge graphs (entities, relationships, attributes) and combines graph traversals with vector similarity.
Finally, continuous quality assurance requires automated evaluation frameworks like Ragas or TruLens. Rather than relying on human spot-checks, production pipelines continuously benchmark four core metrics: Faithfulness (hallucination rate), Answer Relevance, Context Precision, and Context Recall.
- 01Faithfulness: Is every sentence in the response grounded in the retrieved context?
- 02Answer Relevance: Does the generated response directly address the user's initial question?
- 03Context Precision: Did the retrieval engine rank the most relevant documents at the top?
- 04Context Recall: Did the retrieved context contain all the facts needed to fully answer the question?