RAG Application Design Guide: Chunking, Retrieval, Reranking, and Evaluation
ragllm-appsvector-searchembeddingsai-evaluation

RAG Application Design Guide: Chunking, Retrieval, Reranking, and Evaluation

NNext-Gen Cloud Editorial Team
2026-11-28
6 min read

A practical RAG tutorial covering chunking, retrieval, reranking, citations, evaluation, and the checks that keep LLM apps reliable.

A reliable retrieval-augmented generation (RAG) application depends less on a single model choice than on the quality of the pipeline around it. This guide provides a reusable checklist for cleaning documents, selecting chunks, designing metadata, indexing embeddings, combining retrieval methods, reranking results, grounding answers with citations, and evaluating changes before release.

Overview

RAG connects an LLM to an external knowledge collection. At query time, the application retrieves relevant passages, places them in the model’s context, and asks the model to produce an answer grounded in those passages. This approach can improve access to changing or domain-specific information, but it does not automatically make answers accurate. Retrieval can miss the right passage, return distracting text, or expose conflicting versions of a document.

Design the system as a sequence of testable stages:

  1. Ingest: collect documents and record their source, version, permissions, and update time.
  2. Clean: remove navigation noise, duplicated text, broken encoding, and irrelevant boilerplate while preserving meaningful structure.
  3. Chunk: divide content into passages that retain enough context to answer likely questions.
  4. Index: create embeddings and store searchable text, vectors, and metadata.
  5. Retrieve: use semantic, lexical, or hybrid search to select candidate passages.
  6. Rerank: reorder candidates using a more precise relevance step when the initial result set is noisy.
  7. Generate: instruct the LLM to answer from the supplied context and handle missing evidence explicitly.
  8. Evaluate: measure retrieval and answer quality with a representative test set before changing production behavior.

Keep retrieval configuration separate from application logic where possible. Chunk size, overlap, top-k values, filters, reranking thresholds, and prompt instructions should be easy to version and compare.

Checklist by scenario

When adding a new document source

  • Identify the source of truth and define which version is authoritative.
  • Preserve headings, lists, tables, code blocks, and other structure that affects meaning.
  • Normalize dates, identifiers, and terminology only when the transformation is reversible or documented.
  • Attach metadata such as document ID, title, section, product area, language, access scope, effective date, and source URL.
  • Define how deletions, updates, and permission changes propagate to the index.
  • Run sample queries against the new source before enabling it for all users.

When choosing a chunking strategy

Start with structure-aware chunks rather than splitting every document at an arbitrary character count. A heading and its explanatory paragraphs often form a better unit than a fixed window that cuts across sections. For long technical documents, use a hierarchy: retain the document and section identifiers, then split unusually large sections into smaller passages.

  • Use smaller chunks when answers depend on precise facts and the source has clear local context.
  • Use larger chunks when meaning depends on definitions, procedures, or surrounding explanation.
  • Use limited overlap when adjacent sentences commonly complete one another; excessive overlap increases duplicate retrieval.
  • Store the parent section or document so the application can expand context when a passage is ambiguous.
  • Test chunks with real questions rather than judging them only by their length.

When configuring retrieval

ConfigurationUseful whenTrade-off to check
Semantic vector searchUsers describe concepts with words that differ from the sourceMay miss exact identifiers, codes, or rare terms
Lexical searchQueries contain names, error messages, SKUs, or exact phrasesMay struggle with paraphrases and implied meaning
Hybrid searchThe collection contains both conceptual questions and exact terminologyRequires sensible score combination and tuning
Reranked retrievalThe initial candidate set contains several plausible but uneven resultsAdds latency and another component to monitor
Metadata filteringResults must respect tenant, region, product, date, or permission boundariesAn overly narrow filter can hide the correct evidence

For an initial implementation, retrieve enough candidates to avoid losing relevant evidence, then use a reranker or a deliberate selection step to fit the model’s context budget. The right values depend on document density, query type, model behavior, and latency requirements, so treat them as experiments rather than universal defaults.

When designing citations and answers

  • Give each retrieved passage a stable source label that can be shown to the user or logged for review.
  • Tell the model to distinguish supported claims from reasonable but unsupported conclusions.
  • Require an explicit “not enough information” response when the retrieved context does not answer the question.
  • Preserve citations through formatting, streaming, and downstream transformations.
  • Do not treat the presence of a citation as proof that the cited passage supports the claim; evaluate citation entailment separately.

What to double-check

Before launch, inspect the full path from source document to final answer. A strong embedding index cannot repair text that was parsed incorrectly, and a carefully written prompt cannot compensate for a missing access filter.

Data and metadata

  • Are repeated headers, footers, menus, and cookie notices removed?
  • Are tables represented in a way that preserves row and column relationships?
  • Can every chunk be traced to its original document and location?
  • Do metadata filters enforce the same access rules as the source system?
  • Are stale or deleted documents removed from search results?

Retrieval quality

  • Does the top result contain the answer, or only a related topic?
  • Do exact-match queries work for product names, error codes, and identifiers?
  • Do paraphrased queries find the same evidence?
  • Are duplicate chunks crowding out distinct supporting passages?
  • Do filters, date constraints, and tenant boundaries behave as intended?

Evaluation

Create a small, versioned evaluation set before tuning. Include straightforward questions, ambiguous questions, questions with no answer in the collection, exact-term searches, multi-step questions, and questions affected by document version. For each example, record the expected source or acceptable evidence, not only an ideal final answer.

Evaluate at two levels. Retrieval checks whether relevant evidence appears in the candidate set. Generation checks whether the final response is faithful, complete, appropriately qualified, and correctly cited. Track latency, token usage, and failure categories alongside quality. A configuration that improves retrieval but exceeds the application’s operational limits may not be the best production choice. For related guidance, see the RAG retrieval quality troubleshooting guide and the LLM observability guide.

Common mistakes

  • Using one chunk size for every source: policy pages, support tickets, manuals, and code repositories have different structural needs.
  • Embedding raw exports: navigation, duplicated content, and formatting artifacts can dominate retrieval.
  • Relying only on vector search: exact terms and identifiers often need lexical support.
  • Sending every match to the LLM: excess context can increase cost, latency, and distraction.
  • Assuming a confident answer is a grounded answer: require evidence checks and test questions with missing information.
  • Ignoring document lifecycle: stale indexes create answers that were once correct but are no longer applicable.
  • Testing only final responses: diagnose retrieval separately so prompt, index, and generation problems are not confused.
  • Skipping adversarial testing: retrieved documents may contain instructions or untrusted text. Isolate retrieved content from system instructions and review the prompt injection defense checklist.

Reliability also depends on ordinary application engineering. Add timeouts, retries with limits, idempotent ingestion jobs, and clear fallback behavior. See the LLM API reliability patterns guide before treating retrieval as an isolated feature.

When to revisit

Revisit this RAG design before a major planning or release cycle, whenever a document source or access model changes, and after changing the embedding model, vector database, search API, reranker, context-window assumptions, or orchestration framework. Tool capabilities and model behavior evolve, so verify current limits and integration details instead of relying on an old configuration.

Run the evaluation set after every material pipeline change. Compare retrieval results, groundedness, citation accuracy, latency, and cost against the previous version. Keep a short change record covering the configuration, dataset version, evaluation results, and known regressions. If quality drops, start with the retrieval troubleshooting sequence: confirm ingestion, inspect chunks, test filters, compare lexical and semantic results, then examine reranking and generation.

For a practical launch pass, complete these actions:

  1. Freeze a representative document snapshot and evaluation set.
  2. Inspect failures by stage rather than adjusting the prompt first.
  3. Verify permissions, deletion handling, and citation links.
  4. Set budgets for retrieval calls, model tokens, latency, and retries.
  5. Release with logs that capture query, retrieved source IDs, scores or ranks, model configuration, and user feedback without exposing sensitive content unnecessarily.
  6. Schedule the next review when the workflow, tools, or underlying document collection changes.

A RAG application becomes dependable through this repeatable review loop: clean evidence, retrieve it with measurable behavior, generate only what the evidence supports, and rerun the same tests whenever the pipeline changes. Use the LLM app CI/CD checklist to make those checks part of delivery rather than a final manual exercise.

Related Topics

#rag#llm-apps#vector-search#embeddings#ai-evaluation
N

Next-Gen Cloud Editorial Team

Technical Editorial Team

Senior editor and content strategist. Writing about technology, design, and the future of digital media. Follow along for deep dives into the industry's moving parts.