How to build a RAG solution
Step by step from a mountain of documents to reliable RAG with Foundry and Azure AI Search, with the decision that really matters at each step.

- 01
Define what a good answer is
Collect fifty to two hundred representative questions with the answers an expert would give, including the expected sources. This is your evaluation set, your regression test for AI, which you run on every change. Without measured quality, every improvement is guesswork.
Decisionwhat does the system do when in doubt, guess or refuse? In almost every enterprise context, refusing is the right answer. - 02
Get your sources in order
Inventory the documents: owner, currency, duplicate versions. Archive what is outdated before you index.
Decisionwhich sources are authoritative? RAG on conflicting sources gives conflicting answers, no model solves that. - 03
Chunking and indexing
Chunk on document structure (headings, articles, clauses) with overlap. Index in Azure AI Search with both vectors and keywords, and turn on semantic ranking. Include metadata: source, version, publication date, audience.
Decisionchunk size. Too small loses context, too large dilutes relevance. Start around a few hundred tokens and let your evaluation set decide. - 04
Tune retrieval
Test hybrid search against your evaluation set before a model is involved: is the right piece of text in the top five results? If not, this is your problem, not the generation.
Decisionretrieval threshold. Below which score do you refuse to answer? - 05
Generation with grounding
Choose a model in Foundry and write a system prompt with three hard rules: answer only from the supplied passages, always cite the source, and say so explicitly when the information is missing.
Decisionmodel size. Start small; upgrade only when your evaluation set shows it is needed. The difference is more often in retrieval than in the model. - 06
Evaluate and log
Run your evaluation set on every change (Foundry evaluations helps with this). Retrieval, groundedness and relevance are built-in evaluators; refusal behavior is not, so you build that as a custom evaluator, which is still preview. In production, log every interaction with retrieved chunks and scores.
- 07
Manage as a product
Documents change, so indexes do too. Arrange reindexing on publication, monitor unanswered questions as a backlog and repeat the evaluation monthly. RAG is not a project with an end date; it is a product with a data chain.
The process at a glance
Click a step for its key decision
Define what a good answer is
what does the system do when in doubt, guess or refuse? In almost every enterprise context, refusing is the right answer.
Read next
Related patterns
Related use cases
Related best practices
