liveBook · Manning

Chapter 7: Retriever: Returning more relevant results

What you will learn in chapter 7 of Agent Design Patterns

Introduces the Retriever pattern as a way to search large information sources cheaply, then give an agent a small, relevant context for reasoning.

After this chapter you will be able to

What it builds on

Section by section

Introduction

Introduces the Retriever pattern as a way to search large information sources cheaply, then give an agent a small, relevant context for reasoning.

Key terms: scaling wall of context, context window, computational cost, Retriever pattern, input representation, vector embedding, cheap search, high recall, post-processing, action histories

7.1 The pain point:

This section explains why agents need to select useful information from large external sources rather than process everything in context.

Key terms: Retriever, worker IE, effective perception window, context windows, selective attention

7.2 How the Retriever pattern works

This section explains how a Retriever turns a query into a small, relevant selection from a large information pool through preparation, search, and result processing.

Key terms: Retriever, search element preparation, search execution, search result processing, vector embedding, weighted keyword vector, ColBERT, matrix of token vectors, approximate nearest neighbor (ANN), re-ranking

7.2.1 Tradeoffs

This subsection weighs the gains from retrieval-grounded context against the latency that more complex retrieval steps can add.

Key terms: Capability, Interpretability, retrieved facts, hallucination, Cost, Alignment, irrelevant tokens, curated context, latency, re-ranking

7.2.2 Implementation sketch

This subsection sketches a generic neural Retriever class and explains which parts it encapsulates, accepts as inputs, or relies on as dependencies.

Key terms: neural Retriever, query pre-processing, search execution, result post-processing, query, database, embedding, search, re-ranking, ready-to-use utility package

7.2.3 When and where to use Retriever

This section identifies three uses for Retriever: grounding generation with relevant context, recalling an agent’s past interactions, and selecting tools or agents.

Key terms: retrieval-augmented generation, RAG, Generator IE, context, long-term memory, conversation history, past observations, vector storage, semantically relevant, routing

7.2.4 How Retriever works with other patterns

This section shows how Retriever serves as a component of larger Memory and Swarm patterns.

Key terms: Retriever, Memory, Swarm, hybrid retrievers, relevant context, entry-point agents

7.3 Retriever pattern variants

The section introduces hybrid retrievers, which combine parallel search strategies to return results that either strategy might miss alone.

Key terms: hybrid retriever, parallel, fuse their results, dense neural retrieval, semantic matching, sparse retrieval, BM25, SPLADE, keyword matching

7.3.1 Resampling retriever

This section explains how a resampling retriever improves relevance by evaluating search results and trying a new query when relevance is low.

Key terms: resampling retriever, active retriever, lightweight evaluator IE, re-sampling

7.4 Illustrative Applying the Retriever pattern: use-case examples

7.4.1 Context-aware assistant

Shows how a support assistant uses retrieved documentation to ground its answers without fine-tuning the language model.

Key terms: Retriever, retrieval-augmented generation (RAG), retrieved context, grounds, knowledge base, dense retriever, cross-encoder re-ranker, high precision, context window

7.4.2 Hybrid RAG for technical support

This section shows how a hybrid Retriever combines semantic and keyword search to handle both vague technical-support descriptions and exact identifiers.

Key terms: dense retriever, keyword-based search, BM25, semantic intent, Hybrid Retriever, dense vector index, sparse keyword index, Reciprocal Rank Fusion (RRF), cross-encoder re-ranker

7.4.3 Dynamic few-shot exemplar selection

This section shows how a Retriever selects relevant examples for each task and inserts them into a few-shot prompt.

Key terms: in-context learning, static few-shot examples, Retriever pattern, dynamic few-shot prompting, training examples

7.4.4 Semantic tool selection

This section shows how the Retriever pattern selects relevant tools by matching an agent’s intent to tool descriptions and schemas without putting the entire toolkit in the prompt.

Key terms: Retriever pattern, semantic router, tool descriptions, schemas, semantic similarity, context window

7.5 Summary

The section recaps how Retriever keeps agents efficient by selecting relevant context from large data sources through a staged search pipeline and its variants.

Where this is used later

Concepts explained in this chapter

← Chapter 6: Voter: Leveraging stochasticity for improved outputs Chapter 8: Decompose-Process-Recompose: Handling large inputs with accuracy →

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.