Lesson 1 of 3 Multi-Agent RAG and Knowledge Integration

Improving Chunking and Embedding Quality for RAG

This lesson explains chunking strategies, what determines embedding quality and how to measure both, since retrieval-augmented generation (RAG) can only be as good as the passages it retrieves.

Learning outcomes

After completing this lesson, you will be able to:

  • Compare fixed-size, structure-aware and semantic chunking.
  • Identify what determines embedding quality.
  • Measure retrieval with metrics such as recall@k and NDCG.

Chunking strategies

Chunking splits documents into units that are indexed and retrieved. Fixed-size chunking splits by a token count (for example 512 tokens with 10-25% overlap) and is simple and predictable, but can cut a table or a procedure in half. Structure-aware chunking follows the document's headings, sections, paragraphs and tables, usually after layout extraction with Azure Content Understanding or the Document Layout skill in Azure AI Search, so each chunk is a coherent unit. Semantic chunking splits where the topic changes, measured by embedding similarity between sentences.

Each chunk carries metadata: the source document, section title, page, date, access-control groups and document type. Prepending the document and section titles to the chunk text improves both keyword and vector matching, because isolated paragraphs often lack the context that names their subject.

The following diagram applies the three strategies to the same manual.

Three chunking strategies. Fixed-size chunking splits by token count with some overlap; it is simple but can cut a table or procedure in half. Structure-aware chunking follows headings, sections, paragraphs and tables after layout extraction, so each chunk is coherent. Semantic chunking splits where the topic changes, measured by embedding similarity. Each chunk carries metadata, and prepending the document and section titles improves matching.
Coherent chunks retrieve better.
Sort into groups

Which chunking strategy?

Exam skills 2.2.3

Identify the chunking strategy from each description.

Log in to try this activity Interactive activities are free with an account.

Embedding quality

An embedding model converts each chunk and each query into a vector. Embedding quality is the degree to which relevant chunks end up close to the queries they answer. It depends on the model (text-embedding-3-large generally retrieves better than text-embedding-3-small at higher cost and storage), on consistent preprocessing between indexing and querying, on chunk size (very long chunks dilute meaning) and on language and domain coverage. The same model and dimensions must be used for documents and queries; changing the model requires re-embedding the whole index.

True or false

What affects embedding quality

Exam skills 2.2.3

Check what determines whether relevant chunks land near their queries.

Log in to try this activity Interactive activities are free with an account.

Measuring retrieval

Chunking and embedding choices are compared with a labelled set of queries and the chunks that should answer them. The following table lists the usual metrics.

MetricQuestion it answers
Recall@kAre the relevant chunks among the top k results?
Precision@kWhat share of the top k results are relevant?
Mean reciprocal rank (MRR)How high does the first relevant result appear?
NDCGAre the most relevant results ranked highest, accounting for graded relevance?

Foundry's document retrieval evaluator computes such metrics from query relevance labels. Measuring retrieval separately from answer quality shows whether a poor answer comes from retrieval or from generation.

Fill in the number

Retrieval metrics

Exam skills 2.2.3 · 3.1.2

Calculate retrieval metrics for a query with 4 relevant chunks.

Log in to try this activity Interactive activities are free with an account.
Worked example

Split tables

A maintenance assistant answers questions about torque values from equipment manuals. Answers often give values for the wrong model, and inspection shows that tables are split across fixed 512-token chunks, separating column headers from rows.

Structure-aware chunking that keeps each table (or each table row with its headers) in one chunk, with the manual and model name prepended, fixes the cause. A larger embedding model or a stronger generation model would not reunite headers with their rows.

Check yourself

Why measure retrieval separately from answer quality?

Show answer

A poor answer can come from poor retrieval or from poor generation. Retrieval metrics such as recall and precision show which part failed.

Exam Tips

Remember for the exam

  • Tables and procedures split mid-way: structure-aware chunking with layout extraction.
  • Prepend document and section titles to chunks; attach filterable metadata.
  • Measure retrieval (recall, precision, MRR, NDCG) separately from answer quality.