Quick answer: Retrieval-augmented generation (RAG) is an architecture that makes a large language model answer from your own documents. It indexes content into searchable chunks, retrieves the most relevant passages for each question, and passes them to the model with instructions to answer only from that material and cite sources. RAG reduces made-up answers and keeps responses current without retraining a model.
Key takeaways
- RAG grounds a language model in your documents at question time, so no model training is required.
- Retrieval quality determines answer quality; invest in content cleanup, chunking and hybrid search.
- Enforce document permissions in the retrieval layer so users only see answers from content they can access.
- Build an evaluation set of real questions before launch and rerun it after every change.
- Start with a managed RAG service and move to a custom pipeline only when you need more control.
Language models are impressive generalists that know nothing about your organization. Ask a model about your refund policy, your HR handbook or your product's configuration options, and it will either decline or invent a plausible answer. Retrieval-augmented generation (RAG) solves this by giving the model the right information at the moment it answers. This guide explains the architecture and the decisions that make it work, as part of our AI consulting series.
What is retrieval-augmented generation?
RAG is a pattern that combines a search system with a large language model (LLM). When a user asks a question, the system retrieves relevant passages from your content and includes them in the prompt, and the model writes an answer based on those passages, ideally with citations.
RAG is the most common architecture behind internal knowledge assistants, customer support assistants and document Q&A tools because it:
- Uses your current documents without retraining a model
- Lets users verify answers through citations
- Updates instantly when documents change
- Can respect existing document permissions
How does a RAG system work?
A RAG system has two pipelines: one that prepares content ahead of time and one that answers questions in real time.
Ingestion pipeline (offline):
- Connect to sources such as SharePoint, Google Drive, a wiki, a website or a database.
- Extract text from files, including PDFs, Word documents and web pages, and preserve structure such as headings and tables.
- Chunk documents into passages of a manageable size.
- Enrich chunks with metadata such as title, source, date, department and access permissions.
- Embed each chunk into a numerical vector that captures its meaning.
- Index chunks in a search service that supports both keyword and vector search.
Query pipeline (real time):
- Understand the question, optionally rewriting it for better search.
- Retrieve candidate chunks using hybrid search, filtered by the user's permissions.
- Rerank candidates to put the most relevant passages first.
- Generate an answer with the LLM using only the top passages and clear instructions.
- Cite sources and log the interaction for evaluation.
What are the core components of a RAG architecture?
| Component | Purpose | Example options |
|---|---|---|
| Connectors | Pull content from source systems | Built-in connectors, Microsoft Graph, Google Drive API, custom jobs |
| Document parsing | Extract text, tables and structure | Cloud document AI services, open-source parsers |
| Embedding model | Convert text to vectors | Embedding models from OpenAI, Google, Cohere, Amazon and open models |
| Search index | Store and retrieve chunks | Azure AI Search, Vertex AI search services, Amazon OpenSearch Service, PostgreSQL with pgvector |
| Reranker | Reorder candidates by relevance | Managed rerank APIs or cross-encoder models |
| LLM | Generate the answer | Models available through Azure, Amazon Bedrock or Vertex AI |
| Orchestration | Glue the steps together | Application code, LangChain, LlamaIndex or cloud agent frameworks |
| Evaluation and monitoring | Measure quality and cost | Evaluation frameworks, logging and dashboards |
Cloud platforms offer managed versions of most of this stack. See the Vertex AI overview and the Azure AI services overview for platform-specific options.
How should you chunk documents?
Chunk along the document's natural structure, such as sections and headings, rather than at arbitrary character counts. Good chunking keeps related information together so retrieval returns complete answers.
- Keep chunks large enough to contain a complete idea and small enough to be specific, often a few hundred words.
- Use modest overlap between adjacent chunks so information at boundaries is not lost.
- Prepend the document title and section heading to each chunk to preserve context.
- Treat tables carefully; convert them to text that keeps row and column meaning.
- Store metadata such as effective date so outdated versions can be filtered or deprioritized.
Why use hybrid search and reranking?
Hybrid search combines keyword search, which is precise for names, codes and exact terms, with vector search, which finds passages with similar meaning even when wording differs. Together they retrieve better candidates than either alone.
A reranker then scores the top candidates against the question more carefully. Reranking is one of the most cost-effective quality improvements in RAG, because it ensures the model sees the best passages first.
How do you enforce permissions in RAG?
Enforce permissions at retrieval time, so the model never sees content the user is not allowed to access. Store access control information, such as allowed groups, with each chunk and filter search results by the signed-in user's identity.
Do not rely on prompts to hide sensitive content. If a passage reaches the model, assume it can appear in the answer. Also fix oversharing in source systems first; RAG faithfully surfaces whatever permissions allow.
How do you evaluate a RAG system?
Evaluate with a fixed set of real questions and expected answers, and rerun it after every change to chunking, models or prompts.
Build an evaluation set of 50 to 200 questions that includes:
- Common questions with clear answers in the documents
- Questions requiring information from multiple documents
- Questions the documents cannot answer, where the correct response is "I don't know"
- Questions with outdated or conflicting source material
Measure:
| Metric | What it tells you |
|---|---|
| Retrieval recall | Did the right passages appear in the results? |
| Groundedness | Is the answer supported by retrieved passages? |
| Answer correctness | Does the answer match the expected answer? |
| Citation accuracy | Do citations point to supporting sources? |
| Abstention | Does the system decline when it should? |
| Latency and cost | Is it fast and affordable enough per question? |
Automated LLM-based evaluators help at scale, but have subject-matter experts review a sample regularly.
How do you secure a RAG application?
Treat a RAG application as a system with access to sensitive data.
- Authenticate users with your identity provider and pass identity to retrieval filters.
- Defend against prompt injection, where malicious text inside a document tries to change the model's behavior. Treat retrieved content as data, not instructions, and limit what actions the system can take.
- Log questions and answers with appropriate retention and access controls.
- Use enterprise AI services with data protection terms.
- Apply rate limits and budgets to control abuse and cost.
Our API development best practices cover authentication and rate limiting for the services behind a RAG application.
Should you use a managed RAG service or build your own?
Start managed, and build custom only when you hit a limit.
| Option | Strengths | Trade-offs |
|---|---|---|
| Off-the-shelf assistant (for example Microsoft 365 Copilot) | Fast, uses existing permissions | Limited control over retrieval and behavior |
| Managed cloud RAG service | Handles ingestion, search and grounding | Less flexibility in chunking and ranking |
| Custom pipeline | Full control and optimization | More engineering and maintenance |
When does RAG become an agent?
When the system needs to take actions or choose among several tools and data sources, it becomes an agent. Many agents use RAG as one of their tools. See AI agents for business for design patterns.
How Desai InfoTech builds RAG systems
Desai InfoTech builds RAG assistants evaluation-first: we agree on a question set and success criteria with your subject-matter experts before choosing tools, then iterate until the numbers meet the bar. Contact us to discuss a knowledge assistant for your organization.
Frequently asked questions
What is the difference between RAG and fine-tuning?
RAG supplies relevant information to the model at the time of each question, so answers reflect current documents and can cite sources. Fine-tuning changes the model's weights by training it on examples, which is better for teaching a style, format or narrow task than for adding knowledge. For business question answering over documents, RAG is usually cheaper, faster to update and easier to govern.
Do we need a vector database for RAG?
You need some form of search index that supports semantic retrieval, but it does not have to be a standalone vector database. Many existing services support vector search, including Azure AI Search, Amazon OpenSearch Service, Vertex AI search services, PostgreSQL with the pgvector extension and others. For small document collections, the managed search built into your cloud platform is usually enough.
How do we stop a RAG chatbot from making things up?
Improve retrieval so the right passages are found, instruct the model to answer only from provided context and to say when the answer is not available, require citations, and test against an evaluation set that includes questions the documents cannot answer. No technique eliminates errors entirely, so keep humans reviewing high-stakes answers.
How long does it take to build a RAG assistant?
A prototype over a well-organized document set can typically be built in 2-4 weeks. A production assistant with permissions, integrations, monitoring, an evaluation process and user training typically takes 6-12 weeks. Content cleanup is often the largest variable, because outdated or contradictory documents produce poor answers regardless of technology.
Part of the AI Consulting hub.