Building a reliable retrieval-augmented generation (RAG) application requires more than connecting a language model to a vector database. This guide provides a reusable checklist for designing the full retrieval augmented generation architecture, from document ingestion and chunking to embeddings, search, reranking, citations, evaluation, and production operations.
Overview
RAG combines information retrieval with text generation. Instead of asking an LLM to answer entirely from its pretrained knowledge, the application first searches a controlled knowledge base and then supplies relevant content to the model as context. The model uses that context to produce an answer, ideally with clear evidence and fewer unsupported assumptions.
A typical RAG request follows this path:
- A user submits a question.
- The application cleans and transforms the question into a search query.
- An embedding model represents the query as a vector, or the system creates a keyword-based query.
- A search layer retrieves candidate passages from an indexed document collection.
- Optional filtering or reranking selects the most useful passages.
- The application builds a prompt containing instructions, the user question, and retrieved context.
- The LLM generates an answer, with citations or source references when appropriate.
- Logs and evaluation data help the team identify retrieval, prompting, or generation problems.
The most important design principle is separation of responsibilities. In a reliable system, ingestion prepares trustworthy source data, retrieval finds relevant evidence, prompting defines how the model should use that evidence, and evaluation tests whether the complete workflow works for real questions.
| Architecture choice | Best fit | Trade-off to check |
|---|---|---|
| Keyword search | Exact terms, identifiers, product codes, and policy language | May miss relevant passages that use different wording |
| Vector search | Conceptual or natural-language questions | Can return semantically similar but factually unsuitable text |
| Hybrid search | Knowledge bases containing both prose and exact terminology | Requires tuning and a clear method for combining results |
| Reranking | Applications where the first retrieval pass returns too many weak matches | Adds processing time and another model or service to operate |
| Fine-tuning | Stable behavior, formatting, or task-specific style requirements | Does not automatically replace the need for current external knowledge |
Checklist by scenario
1. Before ingesting documents
- Define the answer scope. Decide what questions the application should answer and what it should decline. A narrow scope makes retrieval quality easier to measure.
- Identify authoritative sources. Separate approved documents from drafts, duplicates, archived material, and user-generated content.
- Preserve metadata. Store fields such as title, source URL, document type, owner, version, effective date, language, and access permissions.
- Plan update handling. Give each source a stable identifier so an edited document can replace old chunks instead of creating duplicates.
- Inspect the file formats. PDFs, scanned pages, spreadsheets, slide decks, HTML, and plain text often require different extraction steps. Verify extracted text before creating embeddings.
2. While cleaning and chunking
- Remove extraction noise. Check for repeated headers, broken tables, navigation text, page numbers, and characters that distort search.
- Chunk by meaning where possible. A heading with its related paragraphs is usually more useful than an arbitrary slice that separates a question from its answer.
- Keep chunks self-contained. Include enough context for a reader to understand the passage without requiring several unrelated chunks.
- Use overlap deliberately. A small overlap can protect sentences that cross boundaries, but excessive overlap increases duplicate results and context usage.
- Record chunk provenance. Every chunk should point back to its source document and, when practical, a page, section, heading, or character range.
3. While creating the index
- Select embeddings for the actual data. Consider the languages, terminology, document length, and domain vocabulary in the knowledge base. Test candidate models with representative queries rather than choosing solely from general benchmarks.
- Keep index settings reproducible. Record the embedding model, preprocessing version, chunking rules, distance metric, and index configuration.
- Choose search by failure mode. Vector search helps with paraphrases; keyword search helps with exact identifiers. Hybrid retrieval is worth testing when both patterns matter.
- Filter before or during search when appropriate. Tenant, language, document type, date, and permission filters can prevent irrelevant or unauthorized passages from entering the candidate set.
- Consider reranking for difficult collections. A first-stage search can retrieve a broad candidate set, while a reranker assesses which passages best answer the specific question.
4. While designing the generation step
- State the evidence rule clearly. Tell the model to use retrieved context, distinguish evidence from inference, and say when the supplied material is insufficient.
- Separate instructions from retrieved text. Treat documents as data, not as trusted instructions. This helps reduce prompt injection risks from malicious or unreviewed content.
- Request useful citations. A citation should identify the source passage clearly enough for a user or reviewer to verify the answer.
- Control the output format. If the application needs JSON, a decision, or a list of fields, define the schema and validate the returned output in application code.
- Keep the context focused. More retrieved text is not automatically better. Rank and trim evidence so the model receives the passages most relevant to the question.
5. Before production release
- Create a test set containing common questions, ambiguous questions, questions with no answer, and questions that require multiple documents.
- Measure retrieval separately from answer generation. A correct answer is difficult if the necessary evidence was never retrieved.
- Test access controls with users who should and should not see particular documents.
- Log query transformations, retrieved document identifiers, scores, final context, model version, latency, and validation errors without exposing sensitive data unnecessarily.
- Define fallback behavior for empty retrieval results, unavailable services, malformed model output, and conflicting sources.
What to double-check
Chunking and context windows: Do not treat a model's maximum context length as the target amount of text to send. Large contexts can increase processing work and may bury the key evidence. Test a few chunk sizes and inspect the retrieved passages manually.
Embedding and query consistency: The same normalization assumptions should apply to indexed documents and incoming queries. If the application supports several languages, test each important language and terminology set rather than assuming equal performance.
Freshness: A RAG application can retrieve an outdated document accurately. Store effective dates and versions, define how updates are detected, and decide whether current material should outrank archived material.
Access control: Filtering results after retrieval may be too late if unauthorized content has already entered logs, prompts, caches, or intermediate services. Apply tenant and permission constraints as close to the retrieval boundary as the architecture allows.
Prompt safety: Retrieved text may contain instructions aimed at the model rather than information for the user. Review the prompt injection defense guide and treat retrieved content as untrusted input.
Evaluation design: Use both automated checks and human review. Check whether the answer is supported, whether the citation points to the right source, whether the response follows the requested format, and whether the system appropriately refuses unsupported questions. The prompt engineering evaluation framework can help organize repeatable tests.
Operational cost and latency: Count ingestion, embedding, search, reranking, and generation as separate stages. Caching stable queries, trimming unnecessary context, and setting practical limits can make the workflow easier to operate; see the AI token cost optimization guide for related techniques.
Common mistakes
Indexing everything without governance
A larger corpus can reduce answer quality when it includes duplicates, obsolete policies, or unrelated files. Start with a curated collection and expand it only when test questions reveal a genuine coverage gap.
Assuming semantic similarity means relevance
Two passages can discuss the same subject while referring to different products, dates, user groups, or exceptions. Use metadata filters, exact-match retrieval, reranking, or explicit answer checks where those distinctions matter.
Evaluating only the final prose
A fluent answer can hide a retrieval failure. Record which passages were selected and inspect whether they actually support each important statement. Separate retrieval errors from prompt and generation errors before changing the model.
Ignoring document structure
Flattening a table, heading hierarchy, or procedure into plain text can remove relationships that are essential to interpretation. Preserve structure where possible and create targeted parsing tests for complex formats.
Trusting citations without checking them
A source label is not proof that the answer is supported. Validate that citations refer to the retrieved passage and that the passage entails the claim, rather than merely mentioning a related topic.
Mixing application instructions with source content
When system instructions, user requests, and retrieved documents are blended together, it becomes harder to control behavior and investigate failures. Keep these layers distinct in the prompt and in application logs.
When to revisit
Review the RAG application whenever the knowledge base, user questions, or underlying AI development tools change. A useful maintenance cycle includes the following checks:
- Before a major content or planning cycle: remove superseded files, verify effective dates, and run representative questions against the refreshed index.
- When source formats change: compare extracted text with the original documents before rebuilding embeddings.
- When users report wrong answers: trace the complete request to determine whether the issue came from missing data, poor chunking, weak retrieval, incorrect ranking, or unsupported generation.
- When changing models or providers: rerun the same evaluation set. Model context handling, output formatting, latency, and citation behavior may differ.
- When permissions or tenants change: test isolation explicitly, including cached results, conversation history, logs, and fallback responses.
- On a scheduled review: sample successful and unsuccessful answers, inspect retrieval coverage, and update the test set with newly discovered edge cases.
Use this final deployment checklist before each significant release: confirm source ownership, validate extraction, document chunking and embedding settings, test keyword and vector retrieval, verify filters, inspect citations, run adversarial prompt tests, measure latency and failures, and record a rollback plan. For connected automation, also review scheduling and retry behavior in the cron expressions guide. Treat RAG as an evolving application rather than a one-time index build: when the inputs, tools, or user expectations change, repeat the checks that protect relevance, security, and trust.