Lesson 4 of 7 Retrieval Augmented Generation

Optimizing Chunking and Embedding Models for Retrieval

This lesson explains an evaluation-driven process for fixing RAG systems that retrieve the wrong passages, usually because of how documents were chunked and embedded.

Learning outcomes

After completing this lesson, you will be able to:

  • Measure retrieval quality with a labelled test set.
  • Compare and optimise embedding models.
  • Optimize chunks and context.

Measuring retrieval

Retrieval cannot be improved reliably without measuring it. A retrieval test set contains realistic questions, each labelled with the passages that answer it. On that set, recall@k measures the share of questions whose relevant passage appears in the top k results; precision@k measures how many of the top k are relevant; mean reciprocal rank (MRR) rewards ranking the first relevant passage highly; and NDCG rewards good ordering of all relevant passages.

Alternatively, Amazon Bedrock retrieve-only evaluation jobs score context relevance and context coverage with an LLM judge, without labelled passages. Without such measurement, changes to chunking, embeddings or search settings are guesses.

Fill in the value

Retrieval metrics

Exam skills 2.3.10 · 2.2.9

Calculate retrieval metrics for a small test set.

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

Optimizing the embedding model

Compare embedding models on the test set, because quality varies by domain and language. Use a multilingual model for multilingual content. Higher dimensions may improve recall at more storage cost. Some models distinguish document and query input types, which must be set correctly. For specialist vocabulary, a domain-tuned embedding model hosted on SageMaker AI, or fine-tuned on question-passage pairs, can outperform general models. Any change of model requires re-embedding the corpus.

The following diagram compares recall@5 for an English-focused and a multilingual embedding model on English and Spanish questions.

Recall@5 on 300 labelled questions per language. The English-focused embedding model retrieves the right passage for 84% of English questions but only 52% of Spanish ones. Cohere Embed Multilingual raises Spanish recall to 81% with English unchanged, so a new knowledge base is built with it.
The scenario is illustrative.
Scenario questions

Improve the embeddings

Exam skills 2.2.9

Choose how to improve retrieval when the embedding model is the weak point.

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

Optimizing chunks and context

Adjust chunk size and overlap, try hierarchical or semantic chunking, improve parsing of tables and layouts, remove boilerplate (headers, footers, navigation text) that dilutes embeddings, and enrich chunks with titles or section headings so they carry context. Add metadata for filtering. The following table maps symptoms to fixes.

SymptomLikely fix
Relevant passage never retrievedBetter parsing, different chunking, better embedding model, hybrid search
Retrieved but ranked lowReranking
Passages from wrong product or periodMetadata filters
Chunks lack context to answerLarger or hierarchical chunks; add headings to chunks
Poor results in other languagesMultilingual embedding model
Boilerplate passages retrievedClean documents before chunking
Worked example

A multilingual knowledge base

A travel company's knowledge base serves English and Spanish users. Recall@5 is 0.84 for English questions but 0.52 for Spanish ones.

  • Evaluate Cohere Embed Multilingual against the current English-focused embedding model on 300 labelled questions per language.
  • Recall@5 for Spanish rises to 0.81 with the multilingual model, with English unchanged.
  • Create a new knowledge base with the multilingual model, sync, re-run the evaluation and switch the application.

Changing the generation model would not have helped, because the correct passages were not being retrieved in the first place.

Check yourself

What should be measured before changing anything in retrieval?

Show answer

Retrieval quality, for example recall@k or a Bedrock retrieve-only evaluation.

Exam Tips

Remember for the exam

  • Measure retrieval with recall@k or Bedrock retrieve-only evaluation before changing anything.
  • Changing the embedding model requires re-embedding and usually a new knowledge base.
  • Multilingual content: multilingual embedding model.
  • Clean boilerplate and add headings to chunks.
  • Change one component at a time and compare on the same test set.