Skip to Content
RAG with Python Cookbook
book

RAG with Python Cookbook

by Dominik Polzer
April 2026
Intermediate to advanced content levelIntermediate to advanced
400 pages
3h 35m
English
O'Reilly Media, Inc.
Content preview from RAG with Python Cookbook

Chapter 4. Retrieval

Improving the retrieval step is often one of the most effective ways to boost the overall performance of a RAG system.

There is no single right or wrong approach here. As with all other machine learning use cases, you need a solid toolkit to be creative. Often, the simplest solutions are most effective.

Figure 4-1 shows several techniques you can try when fine-tuning the retrieval step of your RAG system. For each of them, you can find suitable recipes in this chapter:

Table 4-1. Retrieval enhancement techniques
Technique Description Recipe Reference

Metadata Filtering

Using metadata to filter search results based on what you know about the user

Recipe 4.1

Multi-Query Retrieval

Creating multiple versions of the same prompt to find more relevant documents

Recipe 4.3

Query Routing System

Using a query routing system to identify the best data sources or tools to use to answer the question

[Link ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Python Polars: The Definitive Guide

Python Polars: The Definitive Guide

Jeroen Janssens, Thijs Nieuwdorp
Robust Python

Robust Python

Patrick Viafore

Publisher Resources

ISBN: 9798341600553Errata Page