Retrieval-augmented generation looks trivial in a notebook and humbling in production. The gap is not the model. It is everything around it: chunking, retrieval quality, grounding, evaluation and guardrails. This is how we build RAG systems on Azure that survive real users, real documents and a security review.
Key takeaways
- Most RAG failures are retrieval failures. If the right passage never reaches the model, no prompt will save the answer.
- Hybrid search, combining keyword and vector retrieval with a re-ranker, is the reliable default on Azure AI Search.
- Chunk by document structure, not by a fixed character count, and keep titles and section headings with each chunk.
- Build an evaluation set from real questions before launch, and treat every regression like a bug.
- Enforce access control in the index, so users can only retrieve what they could already open.
What is retrieval-augmented generation?
Retrieval-augmented generation (RAG) is a pattern where an application first searches your own documents for passages relevant to a question, then passes those passages to a large language model to write an answer grounded in them. RAG lets a model answer from current, private data without retraining, and lets every answer cite its sources.
That last point is the business case. Answers must be traceable to source. Cite passages, show where each claim came from, and make “I don’t know” a valid, safe response. Hallucination is a product failure, not a model quirk.
What does a production RAG architecture on Azure look like?
A production RAG architecture on Azure has two pipelines. An ingestion pipeline parses documents, splits them into chunks, creates embeddings and writes them to Azure AI Search. A query pipeline retrieves the best chunks for each question, sends them with the question to an Azure OpenAI model, and returns an answer with citations.
- Sources: SharePoint libraries, Azure Blob Storage, databases and line-of-business systems.
- Parsing: Azure AI Document Intelligence for PDFs, scans, tables and forms, so layout and headings survive extraction.
- Embeddings: an Azure OpenAI embedding model, run at ingestion time for chunks and at query time for questions.
- Index: Azure AI Search, holding text, vectors and security metadata in one index.
- Orchestration: your application on Azure Kubernetes Service, App Service or Functions, which owns retrieval, prompting and logging.
- Generation: an Azure OpenAI chat model, deployed with a deployment type that matches your data residency needs.
- Networking and identity: private endpoints and managed identities between every component, with no keys in code.
For UAE organisations, deploy the search index, storage and model in the same region and check which deployment types keep processing in-country. Our guide to Azure OpenAI data residency in the UAE explains the options.
How should you chunk documents for RAG?
Chunk documents along their natural structure, such as sections, headings, clauses or table rows, rather than at a fixed number of characters. Each chunk should be small enough to be specific and large enough to make sense alone. Attach the document title, section heading and source link to every chunk, so retrieval and citations stay meaningful.
| Strategy | Works well for | Risk |
|---|---|---|
| Fixed size with overlap | Uniform prose, quick prototypes | Splits tables, clauses and lists mid-thought |
| Structure-aware (headings and sections) | Policies, manuals, contracts, procedures | Very long sections need a second split |
| Semantic splitting | Long narrative documents with weak structure | Slower ingestion; harder to debug |
| Parent and child chunks | Questions that need surrounding context | More tokens per answer, so higher cost |
| Row or record level | Tables, registers, product catalogues | Loses context unless column headers are repeated in each chunk |
Whatever you choose, test it against real questions. Chunking is a parameter to tune with evaluation data, not a decision to make once.
How do you make retrieval accurate?
Retrieval becomes accurate when you combine keyword search and vector search, then re-rank the merged results. Keyword search catches exact terms such as policy numbers and product codes. Vector search catches meaning when the wording differs. A re-ranker, such as the semantic ranker in Azure AI Search, then puts the most relevant passages first.
- Use hybrid search as the default rather than pure vector search.
- Filter before you rank: by document type, department, date or language, using metadata in the index.
- Rewrite the question for follow-up turns, so “what about Abu Dhabi?” becomes a complete query.
- Retrieve a few more chunks than you send, then trim after re-ranking to control cost.
- Keep content fresh: incremental indexing so superseded documents leave the index when they are withdrawn.
How do you evaluate a RAG system?
Evaluate a RAG system by measuring retrieval and generation separately against a fixed set of real questions with known good answers. Retrieval metrics check whether the right passages were found. Generation metrics check whether the answer is grounded in those passages, relevant and complete. Run the set on every change, like a test suite.
| What you measure | Method | What it catches |
|---|---|---|
| Retrieval recall | Did the known correct passage appear in the top results? | Chunking and search problems |
| Ranking quality | How high did the correct passage rank? | Weak re-ranking or filters |
| Groundedness | Is every claim supported by retrieved text? Scored by a judge model and spot-checked by people | Hallucination |
| Relevance and completeness | Does the answer address the full question? | Prompt and context problems |
| Refusal correctness | Does the system say “I don’t know” when the answer is not in the sources? | Overconfident answers |
| Online feedback | User ratings, edits and escalations in production | Gaps the test set missed |
Microsoft Foundry includes built-in evaluators for groundedness, relevance and similar measures. Calibrate any judge model against human ratings on a sample before you trust its scores, and add every production failure to the evaluation set so it can never quietly return.
What guardrails does enterprise RAG need?
Enterprise RAG needs guardrails at four points: who can retrieve what, what users can send, what the model can return, and what gets logged. Access control in the index is the most important, because a RAG system without security trimming lets anyone ask questions about documents they were never allowed to open.
- Security trimming: store the permitted users or groups on each chunk and filter every query by the signed-in user’s identity from Entra ID.
- Input protection: Azure AI Content Safety offers Prompt Shields to detect prompt-injection attempts, including instructions hidden inside retrieved documents.
- Output checks: content filters, groundedness checks and citation requirements before an answer is shown.
- Personal data handling: decide what may be indexed, mask what should not be, and set retention on conversation logs.
- Monitoring: track refusal rate, citation rate, latency, cost per answer and user feedback on a dashboard someone owns.
What drives the cost of a RAG system?
The main cost drivers of a RAG system are model tokens per answer, the search service tier and replica count, embedding volume at ingestion, and document parsing. Tokens usually dominate, and they are driven by how many chunks you send with each question. Cutting context from ten chunks to four can reduce cost more than changing models.
| Cost driver | What moves it | Lever |
|---|---|---|
| Generation tokens | Chunks per answer, chunk size, conversation history length, model choice | Re-rank and trim context; summarise history; route simple questions to smaller models |
| Search service | Index size, replicas for query load, partitions for storage | Right-size the tier; remove duplicate and obsolete content |
| Embeddings | Corpus size and re-indexing frequency | Incremental indexing instead of full rebuilds |
| Document parsing | Page count and OCR needs | Parse once, cache results, skip unchanged files |
| Throughput reservation | Steady high volume | Provisioned throughput only when usage is predictable |
The teams that win are the ones that made trust a feature from day one. Atronova builds production RAG and AI assistants on Azure OpenAI for regulated teams worldwide. See our AI solutions, read about data analytics for the data foundations underneath, or talk to us.
Frequently asked questions
Is RAG better than fine-tuning?
For answering questions from company documents, usually yes. RAG uses current data without retraining, cites its sources and respects document permissions. Fine-tuning suits changing a model’s style, format or behaviour on a narrow task. Many production systems use RAG alone; some combine both.
How many documents can a RAG system handle?
Azure AI Search scales to very large indexes, so the limit is rarely the document count. Quality is the harder problem: as the corpus grows, duplicates, outdated versions and conflicting documents increase. Content governance, removing superseded versions and tagging authoritative sources, matters more as the index grows.
Can RAG use documents stored in SharePoint?
Yes. SharePoint content can be indexed into Azure AI Search with permissions captured alongside each chunk, so answers respect the same access rules as the source library. Keep the index in sync as documents change, and remove withdrawn documents promptly.
How long does it take to put a RAG system into production?
A focused RAG assistant over one well-governed document set typically reaches production in 6–12 weeks. The timeline depends on the quality and format of the source documents, the complexity of permissions, the number of systems to integrate, and how demanding the evaluation bar is. Messy, duplicated content is the most common cause of delay, so content clean-up often starts before any code.