Lesson 1 of 3 Optimizing Retrieval Performance

Understanding RAG Pipelines

This lesson explains the ingestion and query stages of retrieval-augmented generation, how Azure AI Search implements them, where failures originate, and why optimization starts with measurement.

Learning outcomes

After completing this lesson, you will be able to:

  • Describe the ingestion and query stages.
  • Describe integrated vectorization in Azure AI Search.
  • Distinguish retrieval failures from generation failures.
  • Explain why optimization uses labelled metrics.

The two stages of RAG

A RAG application has an ingestion stage and a query stage. Ingestion turns documents into searchable passages: it extracts text, splits it into chunks, generates an embedding vector for each chunk, and stores chunks, vectors and metadata in an index. At query time, the application turns the user's question into a search, retrieves the most relevant chunks, places them in the prompt as grounding data, and asks the model to answer from them.

  1. Extract

    Read text, tables and structure from PDFs, web pages and other sources.

  2. Chunk

    Split documents into passages of a chosen size and overlap.

  3. Embed

    Convert each chunk into a vector with an embedding model.

  4. Index

    Store chunks, vectors and metadata such as source, date and product.

  5. Retrieve

    Search with the question, using vectors, keywords or both, and filters.

  6. Generate

    Send the question and retrieved chunks to the model with grounding instructions.

RAG on Azure AI Search

Azure AI Search is the retrieval service most often used with Foundry. Integrated vectorization runs ingestion inside the service: an indexer reads a data source such as Blob Storage, a skillset splits documents with the Text Split skill or extracts structure with the Document Layout skill and generates embeddings with an embedding skill, and the results are written to the index. A vectorizer defined on the index embeds queries at search time with the same model.

The index defines vector fields with their dimensions and a vector search profile that names the algorithm, usually HNSW for approximate nearest neighbour search, or exhaustive k-nearest neighbours for exact results on small indexes. Foundry agents and applications query the index through a project connection, using keyless authentication.

Where RAG fails

A wrong answer from a RAG application has one of two root causes, and the fix depends on which. A retrieval failure means the right information was not among the chunks the model received. A generation failure means it was there, but the model ignored it, misread it or added unsupported claims.

FailureTypical causesTypical fixes
Relevant content not retrievedPoor chunking, weak embeddings, missed exact terms, missing filters, top-k too smallChunking, hybrid search, embedding model, filters, reranking
Irrelevant content retrievedTop-k too large, no threshold, chunks too largeLower top-k, thresholds, semantic ranking, smaller chunks
Right content, wrong answerWeak grounding instructions, too much context, conflicting passagesPrompt changes, fewer and better chunks, citations
Stale answerIndex not refreshed after source changesIndexer schedules, change detection

Most RAG quality problems are retrieval problems, which is why this skill area concentrates on retrieval. Evaluating retrieval separately from generation tells the team which half to work on.

Optimization is measurement

Retrieval settings interact: a chunk size that works well with one embedding model and top-k may work poorly with another. The reliable way to optimize is an experiment loop: a labelled evaluation set of questions with their relevant documents or answers, a baseline configuration, and one change at a time, each measured with retrieval metrics and answer metrics before the next.

  • Retrieval metrics: whether the relevant chunks appear in the results and how high, such as recall at k, NDCG and the retrieval and document retrieval evaluators.
  • Answer metrics: groundedness, relevance and response completeness of the final answers.
  • Cost and latency: tokens per request and end-to-end time, which more and larger chunks increase.
Worked example

Locating the failure

A RAG assistant for engineering manuals gives wrong torque values for some components. The team considers switching to a larger chat model. A trace of a failing request shows that the five retrieved chunks are about a similar component with a different part number, and do not contain the requested value.

This is a retrieval failure: the model answered from the passages it was given, which were about the wrong part. A larger chat model would receive the same passages. The team should improve retrieval, for example with hybrid search so that exact part numbers match, a filter on the component's product line, or chunks that keep part numbers with their specifications, and confirm with retrieval metrics on a labelled set.

Adding a stronger grounding instruction addresses generation, not retrieval. Increasing top-k to 20 might include the right chunk somewhere, but adds irrelevant context and cost. Fine-tuning the chat model would not teach it to find the right manual pages.

Check yourself

A trace shows the correct passage was retrieved, but the answer contradicts it. Is this a retrieval or a generation failure?

Show answer

A generation failure. The right information reached the model, so the fix lies in the prompt, the amount of context or the model, not in retrieval.

Exam Tips

Remember for the exam

  • Ingestion: extract, chunk, embed, index. Query: retrieve, then generate from retrieved chunks.
  • Azure AI Search integrated vectorization uses indexers, skillsets and vectorizers.
  • Separate retrieval failures from generation failures before choosing a fix.
  • Optimize one setting at a time against labelled retrieval and answer metrics.