RAG Application Architecture: A Step-by-Step Guide to Chunking, Embeddings, Retrieval, and Citations
RAGembeddingsvector databasesretrievalLLM applications

RAG Application Architecture: A Step-by-Step Guide to Chunking, Embeddings, Retrieval, and Citations

DDatawizard Editorial Team
2026-12-06
7 min read

A practical RAG architecture checklist covering chunking, embeddings, retrieval, reranking, context design, permissions, and citations.

A reliable retrieval-augmented generation (RAG) application depends less on a single prompt than on a carefully designed data and retrieval pipeline. This guide provides a reusable checklist for ingesting documents, choosing chunking strategies, generating embeddings, filtering and reranking results, constructing context, and displaying citations users can inspect.

Overview

RAG combines information retrieval with text generation. Instead of asking an LLM to answer only from its training or conversation context, the application first searches a controlled knowledge base, then supplies relevant passages to the model as context.

A typical RAG architecture looks like this:

Source documents
      |
      v
Parse, clean, classify, and split
      |
      v
Generate embeddings + store text and metadata
      |
      v
User question -> normalize -> retrieve candidates
                                      |
                                      v
                              filter and rerank
                                      |
                                      v
                         build bounded context window
                                      |
                                      v
                         LLM answer + source citations

The system has two related paths. The ingestion path prepares source material before a user asks a question. The query path interprets the question, finds useful passages, and gives the generator enough evidence to answer without overwhelming its context window.

Keep these responsibilities separate in code and monitoring. If an answer is poor, you need to determine whether the document was parsed incorrectly, the chunks were poorly formed, the embedding model missed the meaning, the search returned the wrong passages, the reranker changed the order, or the model failed to use the supplied evidence.

RAG is not a substitute for access control or application security. Apply authorization before returning documents, and treat retrieved text as untrusted input. For a deeper security checklist, see Prompt Injection in RAG Applications.

Checklist by scenario

Scenario 1: Building the ingestion pipeline

  • Define the source of truth for each document type, such as a knowledge base, file repository, database, or support system.
  • Record stable metadata: document ID, title, source URL, owner, product area, language, access scope, version, and effective date where relevant.
  • Parse formats according to their structure. Preserve headings, lists, table labels, page numbers, and section boundaries instead of flattening everything into undifferentiated text.
  • Remove repeated navigation, boilerplate footers, broken encoding, and duplicated content, but retain text that changes the meaning of a procedure or policy.
  • Choose chunk boundaries that follow meaning. A section, procedure, FAQ answer, or table row group is often a better unit than an arbitrary character range.
  • Use modest overlap only when it prevents important sentences from being separated. Excessive overlap increases storage and can cause duplicate retrieval results.
  • Store the original text alongside the embedding. Embeddings support search; they are not a replacement for the passage shown to the model or the citation shown to the user.
  • Make ingestion repeatable and idempotent. A changed document should update its prior chunks rather than create an unnoticed second copy.

Scenario 2: Choosing chunking and embeddings

There is no universal best chunk size. Begin with a chunk that is large enough to express a complete idea but small enough to avoid unrelated material. For highly structured technical documentation, heading-aware chunks may work well. For long narrative documents, paragraph groups with controlled overlap may be more practical. For code, preserve functions, classes, configuration blocks, and file paths where possible.

Test several chunking variants on a small representative corpus. Compare whether each variant retrieves the passage that directly answers a question, not merely whether the passages appear topically related. Keep the embedding model and preprocessing configuration consistent between indexing and querying.

When selecting an embedding service or model, check its input limits, supported languages, vector dimensions, versioning behavior, and operational requirements. Record the model identifier and preprocessing settings with the index so that a future migration can be reproduced and evaluated.

Scenario 3: Improving retrieval quality

  • Normalize the user query only when it improves search. Preserve product names, error codes, identifiers, and exact phrases.
  • Use metadata filters for access scope, tenant, language, product version, document status, or date when those fields are meaningful.
  • Retrieve a wider candidate set than the final context can hold, then reduce it with deduplication, relevance scoring, or a reranker.
  • Consider hybrid retrieval when users search with both natural language and exact terms such as ticket IDs, commands, SKUs, or legal clauses.
  • Keep adjacent chunks together only when the answer depends on their sequence or shared context.
  • Return a clear no-answer result when evidence is weak. A confident response from irrelevant passages is worse than a request for clarification.

Scenario 4: Constructing answers and citations

Build the prompt from explicit components: the user question, retrieved evidence, response requirements, and citation instructions. Tell the model to distinguish evidence from instructions contained inside the retrieved text. Require it to say when the supplied sources do not establish an answer.

Give every retrieved passage a stable citation label before it reaches the model, such as [S1] and [S2]. Store the source title, URL, page or section, version, and access information outside the model output so the application can render links reliably. Validate citations after generation: each cited label should exist, and the cited passage should support the associated claim.

For production work, pair this architecture with an evaluation set. The LLM application evaluation template can help organize retrieval and answer-quality test cases.

What to double-check

Chunk quality: Inspect real chunks, not just configuration values. Look for headings separated from their content, tables with missing column labels, sentences cut in half, and repeated boilerplate.

Metadata behavior: Verify that filters are applied before generation and that a user cannot retrieve content outside the intended tenant, role, region, or document version.

Context limits: Confirm the selected model's current input constraints and account for system instructions, conversation history, retrieved passages, and the expected response. Do not assume a larger context window makes unlimited retrieval useful; irrelevant evidence can reduce answer quality.

Ranking: Review the top results for exact-match questions, broad conceptual questions, ambiguous questions, and questions requiring multiple documents. Retrieval quality can vary substantially by query type.

Freshness: Define how updates, deletions, document expiration, and failed ingestion jobs propagate to the index. A visible ingestion timestamp is useful for debugging and user trust.

Observability: Log query identifiers, filter decisions, retrieved document IDs, scores, reranking results, token counts, latency, and answer status. Avoid logging sensitive content unnecessarily.

Common mistakes

  • Optimizing only the prompt: A polished system prompt cannot repair missing, malformed, or irrelevant retrieval results. Inspect the complete pipeline first.
  • Using one chunking rule for every source: Manuals, support tickets, spreadsheets, contracts, and source code have different structural needs.
  • Stuffing every match into context: More passages create noise, increase cost and latency, and make it harder for the model to identify decisive evidence. See the LLM cost optimization guide for related design considerations.
  • Ignoring exact terms: Pure semantic search may miss an error code or identifier. Test hybrid or lexical retrieval where exact matching matters.
  • Showing unsupported citations: A source link is not evidence by itself. Check that the cited passage supports the claim and that the displayed source matches the retrieved version.
  • Failing open on permissions: Apply authorization in the retrieval layer and again at the document-serving layer. Never rely on the model to hide restricted content.
  • Evaluating only final answers: Track retrieval recall, ranking quality, citation correctness, refusal or abstention behavior, latency, and cost separately.

When to revisit

Review this RAG architecture before adding a major data source, changing document formats, migrating vector databases, replacing an embedding model, altering chunk sizes, or expanding into another language or tenant. Re-run representative retrieval and citation tests after any of these changes rather than assuming compatibility.

Also revisit the design when users report answers that are outdated, technically plausible but unsupported, or based on the wrong product version. These symptoms may indicate stale indexes, weak metadata filters, poor query interpretation, insufficient reranking, or an answer prompt that does not enforce evidence boundaries.

As part of a practical maintenance cycle, review model capabilities, vector-store features, input limits, embedding options, and retrieval settings at least every six months or after a major platform release. Record the date, configuration, test set, and known limitations. This creates a baseline for comparing future changes.

Before your next deployment, use this short action list:

  1. Select a representative document sample and question set.
  2. Inspect parsed text and chunks manually.
  3. Run retrieval tests with and without metadata filters.
  4. Compare candidate retrieval with final reranked context.
  5. Verify that every answer citation resolves to supporting evidence.
  6. Test restricted documents, stale content, empty results, and ambiguous questions.
  7. Record latency, token usage, errors, and quality results before changing the configuration.

A dependable RAG application is an evaluated information pipeline with generation at the end—not simply an LLM connected to a vector database. Treat ingestion, retrieval, permissions, context construction, citations, and monitoring as separate engineering concerns, and the system will be easier to improve when your data and tools change.

Related Topics

#RAG#embeddings#vector databases#retrieval#LLM applications
D

Datawizard Editorial Team

AI Development Editors

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.