Get a quote
Designveloper / Blog / AI Development / RAG Best Practices Start Before Your Model Generates An Answer

RAG Best Practices Start Before Your Model Generates An Answer

Written by Khoa Ly Reviewed by Ha Truong 14 min read August 21, 2026

Table of Contents

Reliable retrieval-augmented generation (RAG) starts before the model generates an answer. It depends on the quality and context of source data, the way the system retrieves and ranks evidence, and the controls that govern what the model may say.

This article is a decision-and-governance guide for technical leaders, not a step-by-step build tutorial. It explains how to choose chunking and retrieval strategies, ground answers, evaluate quality, and operate production RAG with clear controls.

RAG Best Practices For A Reliable Retrieval Pipeline

Reliable RAG retrieval pipeline showing source preparation, context preservation, broad retrieval, reranking, and grounded answer generation.

A reliable RAG system prepares trustworthy content, preserves context, retrieves broad candidates, reranks them, and generates only from useful evidence. Microsoft’s Azure AI Search RAG overview describes classic RAG as an architecture that can combine hybrid search and semantic ranking while also addressing content preparation, relevance, token limits, and access control.

These RAG practices apply across the entire architecture. To diagnose a weak answer, trace it back to the earliest stage where quality was lost. A stale source, detached chunk, missed exact term, or poor ranking decision can fail before the model sees useful evidence. Our RAG pipeline diagram guide provides a visual overview of ingestion, indexing, retrieval, and generation.

The following path turns the pipeline into a diagnostic tool. Start at the left and stop at the first stage that can explain the failure.

Pipeline stageBest practiceFailure preventedQuality signal
Source preparationIndex approved, current content with clear ownership.Outdated or untrusted evidence enters retrieval.Source freshness and ownership are known.
ChunkingSplit content around coherent meaning and document structure.Relevant facts become fragmented or ambiguous.Retrieved chunks answer a clear sub-question.
RetrievalUse the search mode that fits the query, often hybrid retrieval.Exact terms or semantic matches are missed.Relevant evidence appears in the candidate set.
RerankingRescore a broad candidate set before generation.Weak chunks crowd out stronger evidence.High-value chunks move toward the top.
GenerationAnswer from evidence and expose uncertainty.The model fills evidence gaps with unsupported claims.Claims map to citations or trigger abstention.

Preserve Document Context Before Embedding

RAG contextual chunk example showing document metadata, contextual summary, source identity, version, and section context before embedding.

Chunks should carry enough source context to make sense outside their original document. Useful context can include the document title, section title, source type, version, effective date, product, region, or another field that changes meaning.

An illustrative contextual header could read HR handbook | Parental leave | Policy | effective date. This is example metadata, not a reference to a real policy. The header helps retrieval distinguish the chunk from similar policy text and gives the answer layer a clearer route back to its source.

Teams can also generate a short contextual summary that situates a chunk within its parent document. Anthropic’s Contextual Retrieval research prepends concise, chunk-specific context before embedding and before building a BM25 index.

BM25 is a lexical ranking method that is useful for exact word or phrase matches. It can help when a query contains IDs, product codes, dates, names, error strings, or specialized technical terms that vector similarity may treat too broadly.

Anthropic reported a 49% reduction in top-20 retrieval failure when it combined contextual embeddings with contextual BM25, reducing the failure rate from 5.7% to 2.9% in its tests. Adding reranking increased the reduction versus the same baseline to 67%, reducing the failure rate from 5.7% to 1.9%.

Anthropic’s evaluation used 1 - recall@20 as its retrieval-failure metric and reported averages across its tested knowledge domains and configurations. These are experimental results, not a universal production guarantee.

Context enrichment also creates a new failure mode. A generated header or summary can add an interpretation that the source never made. Keep enrichment descriptive, traceable to the parent document, and separate from the original chunk text.

If the contextualizer cannot support a detail from the source, it should not invent one.

Chunk Content Around Meaning And Structure

Comparison of fixed-size, structure-aware, and semantic chunking with common RAG chunking risks such as fragmentation and duplicates.

Choose chunk boundaries around coherent meaning before tuning a target size. There is no single chunking strategy that works equally well for every corpus.

ApproachHow it worksWhen to use it
Fixed-size chunkingSplits content according to a chosen character or token length.Useful when documents are uniform and structure adds little value. Test several sizes instead of assuming one standard.
Structure-aware chunkingFollows headings, sections, paragraphs, lists, or tables when document structure defines scope.Useful for policies, contracts, product documentation, and technical guides.
Semantic chunkingSplits content when the topic or meaning changes rather than when content reaches a fixed size.Useful when topic shifts matter more than layout and added processing cost is justified by retrieval quality.

Microsoft’s structure-aware chunking guidance describes capturing headings and grouping semantically coherent paragraphs and sentences. This approach is useful when headings carry scope, such as a policy name, product version, or contract section.

Overlap is useful only when a boundary would otherwise cut an important idea in half. Too much overlap creates near-duplicates and increases the amount of text that must be embedded and indexed. It can also make repeated versions of one passage dominate retrieval.

Review four failure patterns during evaluation:

  • Chunks that are too broad.
  • Chunks that are too fragmented.
  • Duplicate chunks.
  • Chunks detached from their source context.

Anthropic also notes that chunk size, boundary, and overlap can affect retrieval performance. The right values depend on the actual corpus and should be tested against real questions.

For more advanced indexing and post-retrieval techniques, see our advanced RAG guide.

Retrieve Broadly And Rerank Before Generation

Hybrid RAG retrieval workflow combining keyword and vector search, candidate retrieval, reranking, metadata filters, and top-k selection.

Retrieval should favor recall first, then precision. The first stage gathers plausible evidence. Reranking then rescores those candidates with a stronger relevance step so the best evidence reaches generation.

Hybrid search is often useful because keyword and vector retrieval fail in different ways. Azure AI Search hybrid search runs full-text and vector queries in parallel and merges their results with Reciprocal Rank Fusion.

Keyword search can be stronger for product codes, specialized jargon, dates, names, quoted phrases, and other exact identifiers. Vector search can find conceptually similar text even when the query and source use different wording.

These differences lead to a practical retrieval choice. Match the search method to the type of evidence the query needs: use keyword retrieval for exact identifiers, vector retrieval for conceptual similarity, and hybrid retrieval with reranking when both types of evidence matter.

The table below summarizes these choices so teams can select the simplest approach that covers the product’s query behavior.

Query behaviorRecommended retrievalReason
Exact identifiers IDs, codes, dates, or formal terms determine correctness.Keyword retrievalExact strings are more important than semantic similarity.
Conceptual similarity Users and documents express the same idea differently.Vector retrievalSemantic similarity helps recover conceptually related content.
Both behaviors The application must support exact and semantic queries.Hybrid retrieval, followed by reranking.Combines lexical precision with semantic recall.

If the architecture decision goes beyond document similarity, our Vector RAG vs Graph RAG comparison explains when relationship-aware retrieval may justify a graph-based approach.

Metadata filters should narrow the search space only when the filter reflects a real constraint. Useful examples include product version, tenant, region, document type, access group, or effective date.

A wrong filter can remove the only relevant evidence. Compare filtered and unfiltered recall during evaluation before treating a filter as a reliable improvement.

Query rewriting can help with typos, terminology mismatches, and queries that use different language from the knowledge base. Microsoft’s semantic query rewriting documentation describes a preview feature that can correct spelling and expand queries with synonyms.

The same documentation warns that rewritten queries may drop exact terms, which matters for unique identifiers and product codes. Test query rewriting carefully before using it in a production-critical workflow.

Top-k is the number of retrieved candidates kept for the next stage. Do not copy a top-k value from another system.

Anthropic tested 5, 10, and 20 final chunks and found that 20 performed best among those options in its experiments. Azure hybrid search guidance also recommends specific candidate counts for some semantic-ranking flows.

Treat these as vendor-specific settings. Tune candidate count against recall, context limits, latency, cost, answer quality, and duplicate retrieval.

Reranking adds another runtime step. It can improve relevance, but reranking more candidates can increase latency and cost. Measure the full request path under realistic load and keep the extra stage only when its measured quality gain justifies the added delay and cost.

Ground RAG Answers In Evidence And Clear Boundaries

RAG grounding decision flow for enough, partial, conflicting, or missing evidence with citations, clarification, and abstention.

A grounded answer should say only what the retrieved evidence supports. Groundedness means that the answer’s claims can be traced to the retrieved evidence.

The system also needs explicit behavior for missing, conflicting, sensitive, or incomplete evidence.

Evidence stateExpected response
Enough evidenceAnswer directly and attach citations to the claims they support.
Partial evidenceAnswer the supported part and state what is missing.
Ambiguous questionAsk for clarification when different interpretations would retrieve different sources.
Conflicting sourcesSurface the disagreement and identify source authority or freshness when it can be verified.
No reliable evidenceAbstain, meaning decline to answer, or route the case to an approved fallback.

Citation presence is not enough. Review citation coverage: each material claim should have direct supporting evidence, and unsupported parts should remain visible as gaps.

A relevant page cannot support a sentence that goes beyond what the page actually says.

Protect Permission-Sensitive Knowledge

Sensitive knowledge bases need access control before evidence reaches generation. Azure AI Search’s document-level access control guidance describes security filters and identity-based permission approaches.

In Azure AI Search’s documented permission-aware flows, query-time enforcement uses permission metadata stored in the index. For chunked indexes, permission fields may need to move through index projections so that permission information remains attached to the chunks returned by retrieval.

Source-system permission changes affect retrieval only after the relevant permission metadata is synchronized through the applicable indexer, push update, or refresh process. The exact behavior depends on the data source, access-control approach, and API or feature version.

Keep The Context Set Focused

More retrieved text can improve recall, but it can also distract the model and raise cost. Keep the smallest evidence set that still covers the question.

Then test whether removing low-value chunks changes answer support, citation coverage, or usefulness.

Evaluate Retrieval And Answer Quality With Real Questions

RAG evaluation framework covering retrieval relevance, completeness, groundedness, citation quality, usefulness, latency, and failure patterns.

RAG evaluation should separate retrieval quality from answer quality. Otherwise, a polished answer can hide weak retrieval, while a good retrieved chunk can be blamed for a generation failure.

Build The Evaluation Set From Real User Needs

Build the evaluation set from real user needs. Include representative questions, ambiguous questions, sensitive questions, intentionally unanswerable questions, questions with different wording for the same intent, questions containing exact identifiers, and questions involving stale, conflicting, or restricted content.

OpenAI’s evaluation best practices recommend task-specific tests that reflect real-world distributions.

Its Q&A-over-docs example uses production data, domain-expert answers, and historical log data. The broader guidance also recommends typical, edge, and adversarial cases.

Using a single RAG evaluation scorecard makes evaluation more actionable because each metric is tied to a specific retrieval or answer-quality question. This helps teams identify the failing stage instead of changing prompts when the real problem is missing or irrelevant evidence.

The scorecard below keeps the evaluation in one place. It connects each metric to the question it answers and the practical check that can verify it, without duplicating the same evaluation layers in a second table.

MetricWhat it asksPractical check
Context recallDid retrieval find the evidence needed to answer?Check whether all required supporting passages appear in the retrieved set.
Context precisionHow much retrieved context is actually useful?Review whether irrelevant chunks crowd out useful evidence.
GroundednessAre answer claims supported by retrieved evidence?Map material claims to supporting passages.
Citation coverageAre important claims linked to direct support?Flag claims with missing, weak, or only topic-level citations.
UsefulnessDoes the supported answer complete the user’s task?Score against a task-specific rubric or human review.

OpenAI’s Q&A evaluation example gives sample thresholds for context recall, context precision, and positive user ratings. Those numbers belong to that example. Production teams should set thresholds from their own risk level, baseline, and user requirements rather than copying them as universal targets.

Keep Failure Examples Beside Aggregate Scores

A single aggregate score can hide important patterns. Slice results by source, query type, document age, language, user group, failure category, permission state, and query complexity when those dimensions matter.

Keep representative failure examples beside the averages so the team can reproduce what went wrong.

Evaluate After Meaningful Changes

Run evaluation after changes that can alter retrieval or answer behavior, including source content, chunking, embeddings, metadata filters, ranking, prompts, models, permission metadata, or index schema.

OpenAI recommends continuous evaluation and growing the test set over time. A useful regression process first tests affected cases, then broadens coverage when the change can affect shared pipeline behavior.

Practitioners who need the implementation sequence can use our step-by-step RAG build guide to connect these checks to setup, chunking, indexing, retrieval, generation, and testing.

Production Governance And RAG Implementation With Designveloper

Production RAG governance framework covering source ownership, refresh workflows, regression testing, permissions, observability, and incident response.

Production RAG needs operating rules around sources and retrieval, not only a connection between an LLM and a database.

Governance should answer four concrete questions:

  1. Who owns the source?
  2. How do changes reach the index?
  3. Who may retrieve the content?
  4. What happens when the system fails?
Governance areaOperational requirement
Source ownershipName the person or team allowed to approve, retire, and correct each knowledge source.
Refresh workflowDetect changed content, reprocess affected chunks, and verify that deleted content no longer appears.
PermissionsEnforce source-level or document-level access before generation and test denied cases.
ObservabilityRecord query transformations, retrieved sources, ranking, citations, latency, errors, and fallback behavior.
User feedbackCapture enough context to reproduce a bad answer without exposing restricted data.
Incident responseDefine how to disable a source, switch to a safer fallback, and review affected answers.
  • Refresh Only What Has Changed When Possible

Refresh does not always require rebuilding everything. Azure AI Search indexer guidance states that a normal indexer run can detect and process new or updated content when the data source supports change detection.

A full reset is used when the team wants to reprocess all documents. The exact refresh behavior depends on the data source, indexer configuration, and change-detection capability.

Production teams should also verify that deleted, restricted, or superseded content no longer appears in retrieval results.

  • Keep Permission Changes Synchronized

Permissions need the same change discipline as content. When a system uses indexed permission metadata, query-time enforcement can only reflect the state that has reached the index.

Test both successful and denied cases. A permission test suite should verify that authorized users can retrieve allowed content, unauthorized users cannot retrieve restricted content, restricted content does not appear in citations, deleted permissions are reflected after synchronization, and cached content does not bypass access controls.

  • Use Case Studies Without Overclaiming

Designveloper’s public work shows adjacent workflow capabilities without proving a specific RAG stack.

The Song Nhi case describes a conversational finance assistant that accepts short chat inputs and answers questions about recorded spending.

The Lumin case describes PDF viewing, editing, sharing, cloud access, collaboration, and digital signatures.

These public cases support conversational and document-centric workflow experience. They do not, by themselves, prove RAG architecture, LangChain, CrewAI, a specific LLM, model training, or any unverified delivery metric.

FAQs About RAG Best Practices

How Long Should A Contextual Chunk Header Be?

There is no universal ideal length. The header should identify the chunk’s source and scope without becoming a second document.

Start with decisive metadata such as the document title, section, source type, version, effective date, or product. Anthropic reports that its generated contextual text was usually 50 to 100 tokens. That range describes Anthropic’s method and experiments, not a required value for every RAG system.

Do Semantic Chunks Increase Embedding And Indexing Costs?

They can if semantic splitting increases the number of chunks or the amount of text processed.

Measure embedded tokens, index size, preprocessing time, refresh cost, retrieval quality, and duplicate retrieval together. More chunks are not automatically better.

What Does Keyword Search Add When Vector Search Already Works?

Keyword search protects exact-match cases that semantic retrieval can miss. It is especially useful for IDs, product codes, dates, names, quoted phrases, technical terms, error strings, and formal policy or contract language.

Test keyword-only, vector-only, and hybrid retrieval on the same evaluation set before assuming that vector-only retrieval is sufficient.

Can Reranking Make A RAG Application Too Slow For Real-Time Use?

Yes. Reranking adds a runtime step, so it can increase latency even when it improves relevance.

Test end-to-end response time with realistic traffic and candidate counts. Keep reranking only where the measured quality gain justifies the delay and cost for that product.

How Should Teams Test Retrieval After A Knowledge Source Changes?

Run targeted tests for the changed source first. Expand to the broader regression set when the change can affect shared chunking, embeddings, filters, ranking, permissions, or index behavior.

Start with a bounded knowledge source, a real evaluation set, access rules, and one workflow where retrieval quality can be measured.

Also published on

Share post on

Insights worth keeping.
Get them weekly.

Related Articles

name
name
What Is LangChain and Where Does It Fit in an AI Application?
What Is LangChain and Where Does It Fit in an AI Application? Published August 25, 2026
8 LangChain Use Cases For AI Products That Need More Than Prompts
8 LangChain Use Cases For AI Products That Need More Than Prompts Published August 25, 2026
How Much Does Generative AI Cost? Understanding Generative AI Pricing
How Much Does Generative AI Cost? Understanding Generative AI Pricing Published August 25, 2026
name name
Got an idea?
Realize it TODAY