Generative AI becomes far more useful when it can work with the information a business actually owns: product manuals, policies, support tickets, internal procedures, research, and documents that change after a model was trained. Retrieval-augmented generation (RAG) is one practical way to connect that information to an AI assistant.
RAG does not retrain the underlying language model every time a file changes. Instead, an application retrieves relevant material at question time, places selected passages into the model’s context, and asks the model to answer using that evidence. The quality of the result depends as much on the search and data pipeline as it does on the model.
What is retrieval-augmented generation (RAG)?
RAG is an application pattern that combines information retrieval with a generative model. It is useful when answers need to draw on private, domain-specific, or frequently updated information that may not be part of a model’s training data.
A typical system has three stages:
- Retrieve: Search an approved knowledge collection for passages relevant to the user’s question.
- Augment: Assemble the question and selected passages into a model prompt, including source information and instructions about how to use the evidence.
- Generate: The model produces an answer, ideally with references to the retrieved sources and an explicit acknowledgement when the evidence is insufficient.
Microsoft’s RAG and indexes documentation describes this retrieve–augment–generate flow and the use of keyword, semantic, vector, and hybrid search. Google’s RAG reference architectures show how the pattern can be implemented in different cloud and application designs.
How the knowledge pipeline works
1. Prepare the source documents
Start with documents that are authoritative, current, and appropriate for the intended users. Typical sources include help-center articles, approved PDFs, product specifications, internal policies, and structured records. Identify who owns each source, how often it changes, and who is permitted to access it.
Document preparation can involve text extraction, OCR for scanned pages, removal of navigation clutter, normalization of tables, and retention of useful metadata such as document name, date, department, version, and URL. Poor extraction can make a correct source unusable to the retrieval system.
2. Split content into searchable passages
Large documents are often divided into smaller chunks so search can retrieve a relevant section instead of an entire file. There is no universally optimal chunk size. Very small chunks may lose context; very large chunks may contain unrelated material and consume more of the model’s context window.
Test chunk boundaries against the kinds of questions users actually ask. Preserve headings, section relationships, tables, page numbers, and source identifiers wherever possible. Overlapping chunks can help preserve context at boundaries, but they also increase index size and duplicate retrieved information.
3. Build an index
Many systems use embeddings—numerical representations of text—to support semantic similarity search. An index may also support traditional keyword search or hybrid retrieval that combines lexical and semantic signals. Embeddings are not the only way to retrieve information; the choice depends on the content, query patterns, latency, and operational constraints.
Keep metadata filterable. A retrieval request might need to limit results to the current product, policy version, language, department, or user’s permitted documents. A similarity score alone should not determine whether a document is relevant, current, or authorized.
4. Retrieve and rank evidence
When a question arrives, the application may normalize it, search the index, apply permissions, and optionally rerank the candidate passages. Reranking can improve the ordering of results in some workloads, but it adds computation and should be evaluated rather than enabled by assumption.
Return a manageable set of passages with their source metadata. The goal is not to send everything the search system found; it is to provide the model with enough relevant, authorized context to answer the question.
5. Generate a grounded response
The prompt should tell the model to use the supplied evidence, distinguish evidence from instructions, avoid inventing missing facts, and cite the documents it used. The application—not the model alone—should determine which documents a user is allowed to retrieve.
If the search finds nothing useful, a well-designed assistant should say that the knowledge base does not contain enough information rather than quietly switching to an ungrounded answer from general model knowledge.
RAG versus fine-tuning: which should you use?
| Need | Often a better starting point |
|---|---|
| Answers based on changing policies, manuals, or company documents | RAG |
| Source citations and traceable evidence | RAG, with citation validation |
| Consistent style, format, or specialized behavior across many examples | Fine-tuning or prompt design may help |
| Both private knowledge and a specialized response behavior | A combination, evaluated end to end |
| Simple tasks with no need for private or changing data | A direct model call may be sufficient |
RAG and fine-tuning solve different problems. RAG supplies evidence at inference time; fine-tuning changes model behavior through training. They are not mutually exclusive, and neither guarantees factual accuracy.
A practical example: a support knowledge assistant
Imagine a small company that sells several products and receives repetitive questions about installation, warranty coverage, troubleshooting, and shipping. Its knowledge assistant could index approved manuals, troubleshooting articles, and policy documents.
- A customer asks how to resolve a particular error.
- The system identifies the product and retrieves relevant troubleshooting passages.
- It filters results to current, customer-visible material.
- The model explains the steps in plain language and links to the manual section.
- If the answer requires an exception or a decision not documented in the sources, it routes the customer to a human support team.
This is an illustrative workflow, not a claim about a specific deployed company. Its advantage is that a product manual can be updated in the knowledge source without retraining the language model, provided the indexing and update process works correctly.
How to build a first RAG project: a seven-step plan
Step 1: Choose one narrow use case
Start with a task that has clear boundaries, such as answering questions about a product manual or a single department’s procedures. Avoid connecting every company data source at the beginning.
Step 2: Curate a small, approved corpus
Select a manageable set of documents. Remove duplicates, expired material, drafts, and sources that users should not access. Record document owners and refresh rules.
Step 3: Define representative questions
Build a test set from real user questions, including vague queries, questions with multiple parts, requests that have no answer in the corpus, and queries that should be blocked because the user lacks access.
Step 4: Implement retrieval before polishing generation
Test search results independently. If the right passages are not being retrieved, changing the prompt or model may not solve the underlying problem. Compare keyword, semantic, and hybrid search on the same test questions.
Step 5: Add the answer layer
Use a prompt that specifies the intended audience, evidence rules, response format, citation behavior, and how to handle uncertainty. Keep the prompt simple enough to test. Validate citations against the retrieved source IDs instead of trusting text citations that the model invents.
Step 6: Measure the system
Review whether relevant passages were retrieved, whether the answer actually uses them, whether citations point to the correct source, and whether unsupported claims appear. Measure latency, retrieval and model costs, and user feedback. For a more detailed testing approach, see our guide to evaluating AI models before deployment.
Step 7: Release gradually
Start with a limited group of users. Monitor failures, collect feedback, review source changes, and expand only when the system performs reliably on the tasks and permissions you defined.
RAG security and privacy: the controls that matter
Connecting a model to a knowledge base introduces a new trust boundary. Retrieved documents can be inaccurate, outdated, manipulated, or unauthorized. The model may also be influenced by malicious instructions embedded in source content.
- Enforce permissions before content reaches the model. Apply document- or chunk-level access controls during retrieval. Do not rely on the model to decide who is allowed to see a document.
- Treat retrieved text as data, not instructions. Delimit evidence and test for indirect prompt injection. Prompt rules alone are not a security boundary.
- Maintain provenance. Record source identifiers, versions, owners, and update history. Validate citation references.
- Protect the index. Restrict write access to ingestion services, monitor changes, and isolate tenants or classifications.
- Handle deletion and updates. Removing a source should trigger removal or refresh of its derived chunks, embeddings, and relevant cached responses.
- Validate downstream actions. If an assistant can call tools, enforce authorization independently and require confirmation for consequential actions.
- Log carefully. Track retrieval decisions and outcomes while minimizing unnecessary storage of sensitive queries, source text, and model inputs.
The OWASP RAG Security Cheat Sheet covers risks across document ingestion, embeddings, retrieval, access-control inheritance, output validation, tool invocation, caching, monitoring, and incident response. OWASP’s 2026 guidance on vector and embedding weaknesses also highlights risks that can arise from similarity search itself. The NIST Generative AI Risk Management Profile provides broader voluntary risk-management guidance.
Common RAG mistakes
- Indexing everything without verifying source quality or permissions.
- Assuming vector search always beats keyword or hybrid search.
- Choosing chunk sizes based on a tutorial instead of testing.
- Evaluating only the final answer and ignoring retrieval failures.
- Displaying citations without checking that they support the claim.
- Allowing a failed retrieval or permission check to fall back to unrestricted model knowledge.
- Leaving deleted or changed documents in indexes and caches.
- Ignoring the additional latency, embedding, search, reranking, and generation costs.
How to know whether RAG is worth it
Compare the RAG system with a simpler baseline using the same representative questions. Ask whether the system retrieves the right information, gives more useful answers, cites evidence accurately, respects permissions, and reduces the work required from people.
Track practical metrics such as retrieval hit rate on a curated test set, citation accuracy, answer completeness, unsupported-answer rate, access-control test failures, average latency, cost per completed task, and escalation rate. These measurements should be defined for the use case; there is no universal score that makes every RAG system ready for production.
Conclusion
RAG is a practical way to connect AI models to information that changes, belongs to an organization, or requires source-based answers. The technology is not simply a vector database attached to a chatbot. It is a pipeline of source preparation, indexing, retrieval, permissions, context assembly, generation, validation, and monitoring.
Begin with a small, carefully curated knowledge collection and a narrow task. Test retrieval and access control before adding more data or automation. A well-measured knowledge assistant is more valuable than a large index that produces confident but unsupported answers.
Further reading and sources
- Microsoft Foundry: Retrieval-augmented generation (RAG) and indexes
- Google Cloud: Generative AI with RAG reference architectures
- OWASP: RAG Security Cheat Sheet
- OWASP: LLM09:2026 Vector and Embedding Weaknesses
- NIST: Artificial Intelligence Risk Management Framework—Generative AI Profile (NIST AI 600-1)