CertPrep
Domain 3 · Lesson 3.5 · 11 min read

Selecting a Retrieval Architecture

Exam skillRetrieval Architecture Selection

Selecting among retrieval architectures (pre-built RAG pipeline, agentic search with tools, full-corpus context) based on corpus characteristics, query pattern, and latency and cost limits, and, when indexing is chosen, specifying the contextual-retrieval and fallback configuration that maximizes retrieval quality within those limits.

Choose between full-corpus context, a pre-built RAG pipeline and agentic search for a given corpus and query pattern, then configure chunking, indexing, contextual retrieval and fallbacks when an index is the answer.

What you need to know

Retrieval-augmented generation (RAG) answers questions from a body of knowledge too large, too specialized or too changeable to rely on the model's training. The pipeline has two halves:

  • Indexing (offline): collect documents, split them into chunks, compute representations, and store them in an index.
  • Answering (online): turn the question into a query, retrieve candidate chunks, optionally rerank them, and pass the best ones to Claude with instructions to answer from them and cite.

Remember lesson 1.2: retrieval is for stable knowledge. Live state comes from tools.

Choose the architecture first

The first decision is not how to chunk, but which retrieval architecture the workload needs.

ArchitectureHow it worksFits
Full-corpus contextLoad the whole knowledge base into the prompt, usually with prompt cachingA small, stable corpus (a few hundred pages at most) and questions that may need any part of it
Pre-built RAG pipelineIndex the corpus offline; retrieve the best chunks per questionA large or growing corpus, high query volume, tight latency and cost limits
Agentic search with toolsThe model searches, opens and follows references step by stepCodebases, file trees, fast-changing collections, investigative or multi-hop questions where volume is low

Corpus size, how often it changes, the query pattern and the latency and cost limits decide between them. Full context is simplest and accurate while the corpus fits; a pipeline earns its complexity at scale; agentic search always sees current data and can follow a trail, at more latency and cost per question.

Chunking: by the shape of the documents

The chunk is the unit that comes back. Choose the method by what the documents are, not by a default size.

MethodHowFits
Fixed-size with overlapEqual spans, overlapping a littleUniform, unstructured text with weak natural boundaries
SemanticSplit where the topic changesProse, where each chunk must make sense on its own
Structural (hierarchical)Follow the document's sections and subsectionsManuals, contracts, policies, where the section heading carries meaning

A common failure: a chunk loses the context that made it meaningful ("the limit is 30 days", but for which policy?). Fixes include keeping section titles and document names with each chunk, and contextual retrieval, which prepends a short, generated description of where the chunk sits in its document before indexing it.

Indexing: by how people ask

IndexMatchesFits
Dense (embeddings)Meaning, even with different wordsQuestions phrased unlike the source text
Sparse (keyword, such as BM25)Exact terms: part numbers, codes, namesQuestions that hinge on a specific identifier
HybridBoth, with results mergedMixed query patterns, which is most production traffic

Match the method to the data shape

Data shapeExamplesRetrieval method
Unstructured textManuals, policies, articles, notesChunked index: dense, sparse or hybrid
Structured recordsOrders, claims, accounts, transactionsA query or API call with filters; never embeddings over rows
Tables and metricsSales figures, KPIsSQL against the warehouse (the model can draft the query; code runs it with read-only, scoped access)
Live stateStock, status, balancesA tool call to the owning system at question time
Codebases and file treesRepositories, shared drivesAgentic search: the model lists, greps and opens files step by step

Many assistants need several of these, behind one router or exposed as several tools.

Match the method to the query pattern

Query patternWhat helps
Paraphrased, conceptual ("why does my table wobble?")Dense embeddings
Exact identifiers (codes, clause numbers, names)Keyword or hybrid search
Scoped ("in the 2025 policy wording", "for this product")Metadata filters applied before ranking
Multi-part or multi-hop ("compare the excess in the old and new wordings")Query decomposition or an agent that retrieves in several steps
High stakes, needs evidenceCitations to the retrieved passages, and quote-first answers

Improving precision

  • Metadata filters (product, version, region, date, document type) remove whole classes of wrong answers before ranking.
  • Contextual retrieval adds a short description of each chunk's place in its document before indexing, which reduces misses from context-poor chunks; combined with hybrid search it lowers retrieval failures substantially.
  • Reranking takes the top few dozen candidates and reorders them with a stronger relevance model, keeping only the best handful. It improves quality and adds latency and cost per query, so it belongs where accuracy matters more than milliseconds.
  • Query rewriting turns a conversational question into a better search query, using the conversation so far.

Fallback configuration

Retrieval sometimes returns nothing useful: no chunk scores above the threshold, or the top results disagree. Decide what happens then, before production.

  • Widen before giving up: retry with a rewritten query, drop an optional filter, or fall back from dense to keyword search for identifiers.
  • Say so when evidence is missing: answer "I could not find this in the policy library" rather than letting the model fill the gap from training data.
  • Route to a person or another source for high-stakes questions with no supporting passage.

Three trade-offs to name

Every retrieval design balances retrieval quality (does the right chunk come back?), latency (how much time retrieval adds) and maintenance (how much it costs to keep the index correct as documents change). Reranking improves quality and adds latency; finer chunking improves precision and increases index size; frequent re-indexing improves freshness and costs compute.

Keeping it fresh

Decide how changes reach the index: re-index changed documents on publish, on a schedule, or both; remove withdrawn documents; record the source version in each chunk so citations point to the right edition.

In the exam

Retrieval items give the corpus (size, structure, how often it changes), the query pattern, and latency and cost limits, then ask which architecture fits, or describe a failure and ask for the fix. Choose full-corpus context for a small stable corpus, a pipeline for large or high-volume workloads, and agentic search for codebases and investigative questions. When indexing is chosen, match chunking to document shape and indexing to query pattern, add contextual retrieval and filters for precision, and specify the fallback when nothing relevant comes back. Distractors apply one method to everything or answer without evidence.

Check your understanding

Question 1

Technicians search a manual library using exact fault codes such as "E-4417". Embedding search often returns similar-sounding but wrong codes. What fixes this?

Show answer

Answer: D. Exact identifiers are what keyword (sparse) indexes match well. A hybrid index keeps the semantic matching for other questions and recovers exact codes.

Question 2

Answers about insurance policies mix up conditions from different sections. The policies are split into fixed 400-token chunks. What is the best fix?

Show answer

Answer: C. Structured documents should be chunked along their structure, with the context that gives each chunk its meaning. Smaller fixed chunks lose even more context.

Question 3 · select 2

A team has 120 pages of reference material that rarely changes and is used on every request. Which TWO options are sound?

Show answer

Answer: A, C. A small, stable corpus may fit the context window, where caching makes it cheap. Retrieval should be added only if measurement shows a need.

Apply it: Design Hollis & Grant's product knowledge pipeline

Exercise · about 20 minCase: Hollis & Grant Home

Hollis & Grant's product-question route needs retrieval over 2,300 product manuals (PDFs with sections such as assembly, care and dimensions) and 400 help-centre articles updated weekly. Customers ask in their own words ("my table wobbles"), and sometimes quote product codes ("CV-2210-OAK").

  1. Choose chunking for each source, with a reason.
  2. Choose the index type and justify it with the query patterns.
  3. Design freshness: how revised manuals and weekly article updates reach the index, and how citations stay correct.
  4. Define two retrieval metrics you will track.
    Done when: each metric can be computed without reading every answer by hand.
Check your work
Show model answer

1. Chunking

SourceChunkingReason
Product manualsStructural: by section, with product name, product code and section path attachedAnswers depend on the section ("assembly" vs "care") and on which product
Help-centre articlesOne chunk per article, split by heading only when longArticles are short and self-contained

Contextual descriptions are generated for manual chunks so a chunk like "tighten bolts B and C" carries "Assembly, CV-2210 dining table".

2. Index. Hybrid: dense embeddings for problem descriptions in customers' words, plus keyword matching for product codes and part letters, with results merged and the top few reranked before generation.

3. Freshness. Manuals are re-indexed when the catalogue marks a product revision, removing the old version's chunks; articles are re-indexed on publish each week. Each chunk stores the document ID and version, and answers cite them, so a citation always points to the edition that was used.

4. Metrics. Recall at 5 on a labelled set of 300 real questions (is a correct chunk among the top five?), and the share of answers whose citation points to the right product, measured automatically from the product code in the question and in the cited chunk.

Key termsChunkingCitationsContextual retrievalEmbeddingHybrid searchMetadata filterPrecision and recall

Sources

Go hands-on optional, needs a Claude API key

Runnable notebooks from Anthropic's Claude Cookbook that build the patterns in this lesson.