Rubric
Contents — domains, guide and mocks

Matching retrieval to data and queries

CCAR-P 3.612 min read · checked 21 September 2026

Task statementApply retrieval strategies matched to data shape and query pattern

One assistant, several ways to look things up

Claude + toolspicks a method per question
  • Hybrid searchpolicies, manuals, contracts
  • Structured queryorders, claims, metrics tables
  • grep / globcode, logs, config files
  • Live API callstock, account status, web
Claude chooses among retrieval tools, each built for one kind of data. A single vector index in the middle would serve only one of these spokes well.

Two questions: what shape is the data, and what shape is the query?

Data shape is about how the information is stored. Is it rows and columns with exact values? Records with a few fields and a text body, like tickets or emails? Long prose, like policies and contracts? Code and logs, where exact identifiers matter and files point to other files? Or is it a live system of record, where any copy starts going stale as soon as you make it?

Query pattern is about what the user is asking for. An exact lookup (“order A-1042”). A conceptual question (“what is our policy on remote work abroad?”). An aggregation (“how many refunds over £500 last quarter?”). A multi-hop or comparative question (“which of our suppliers’ contracts allow termination for convenience?”). An open-ended survey (“what are competitors saying about pricing?”). Each pattern breaks a different retrieval method.

Data shapeUsually best served byWhy
Tables, ledgers, metricsA structured query tool (SQL or a filtered API)Exact values, joins and counts; the database does the arithmetic
Records with fields + text (tickets, CRM notes)Metadata filters first, then hybrid search in the textNarrow by customer, date or status before ranking by meaning
Long prose (policies, contracts, research)Hybrid search with contextual chunks and rerankingMeaning and exact terms both matter (see 3.5)
Code, logs, configAgentic search: grep, glob, reading filesExact symbols, and files that reference each other
Live system of recordA tool that calls the system at question timeAn index copy is stale the moment stock or status changes
Query patternWhat breaks with plain top-K vector searchStrategy that fits
Exact lookup by ID or nameIdentifiers embed poorlyKeyword or BM25, or a direct lookup tool
Conceptual questionUsually worksHybrid search + rerank
Count, sum, trendTop 20 chunks cannot count 50,000 rowsQuery the structured source; let it aggregate
Multi-hop or comparativeOne query retrieves one side of the questionBreak it into sub-queries and let Claude search repeatedly
Broad surveyOne query can’t cover every angleStart broad, then narrow; run parallel subagents
Freshness-criticalThe index lags realityA live tool call or web search at question time

Pre-computed retrieval versus just-in-time retrieval

Anthropic’s multi-agent research post contrasts traditional RAG’s “static retrieval” (fetch the chunks most similar to the input query, once) with multi-step search that adapts to what each result reveals. The context engineering post names the same idea just-in-time context. The agent keeps lightweight identifiers such as file paths, stored queries and links, and loads the data through tools only when it needs it. Claude Code works this way on a codebase: its built-in search tools find files by pattern and search content with regex, and it reads only the files it needs. The post also describes it using head and tail to inspect large data without loading all of it.

Two ways to get the right text in front of Claude

Pre-computed (static RAG)

  • Index built ahead of time
  • One retrieval per question, fast and predictable
  • Can go stale; needs re-indexing
  • Weak on multi-hop and exploratory questions

Just-in-time (agentic)

  • Claude writes its own searches and queries
  • Each result shapes the next search
  • Always reads the current data
  • Slower and uses more tokens per question

Neither wins everywhere. The context engineering post states the trade-off directly: runtime exploration is slower than retrieving pre-computed data. It suggests a hybrid often works best, as with Claude Code loading its CLAUDE.md up front and fetching everything else on demand. The research post shows the cost side too: agents typically use about 4× the tokens of a chat interaction, and multi-agent systems about 15×. A high-volume FAQ bot should not pay agentic prices for questions a single retrieval answers. An analyst assistant answering open-ended, multi-source questions often should.

Choosing the strategy for a question

What does answering this question need?
  • One passage from stable text
    Single hybrid retrievalfast, cheap, cacheable
  • A count, sum or trend
    Structured query toolthe database does the maths
  • Facts that build on each other
    Agentic multi-step searchClaude refines as it goes
  • Many independent directions
    Parallel subagentsbreadth-first, then synthesise

Designing the retrieval tools themselves

Once Claude decides how to retrieve, the tools you expose shape what comes back. Anthropic’s tool-writing guidance says a tool that returns every record (its example is list_contacts) wastes context. Build a search_contacts that jumps to what matters instead. The same guidance favours tools that return only relevant log lines, response_format options for concise or detailed output, and pagination, filtering and truncation with sensible defaults. Consolidating which tools to expose at all is covered in 3.1.

Two retrieval tools, each matched to its datapython
tools = [
    {   # Prose: policies and procedures -> hybrid search, returns search_result blocks
        "name": "search_policies",
        "description": "Search HR and finance policy documents by meaning or exact "
                       "term. Use for 'what is our policy on...' questions.",
        "input_schema": {"type": "object", "properties": {
            "query": {"type": "string"},
            "effective_on": {"type": "string", "description": "ISO date; defaults to today"},
        }, "required": ["query"]},
    },
    {   # Rows: expense claims -> the database aggregates, Claude never sees raw rows
        "name": "expense_stats",
        "description": "Count or total expense claims with filters. Use for "
                       "'how many' or 'how much' questions. Returns numbers, not claims.",
        "input_schema": {"type": "object", "properties": {
            "metric": {"type": "string", "enum": ["count", "sum_gbp", "avg_gbp"]},
            "department": {"type": "string"},
            "from_date": {"type": "string"}, "to_date": {"type": "string"},
            "min_amount_gbp": {"type": "number"},
        }, "required": ["metric"]},
    },
]

Notice what the second tool does not do: it does not let the model write free-form SQL against production, and it does not return raw rows for Claude to add up. A narrow, parameterised tool keeps the arithmetic in the database, keeps the context small, and gives you a clear permission boundary. Some teams do expose read-only SQL to an analyst agent. That is a separate decision about access and guardrails, and 3.2 covers it.

Adapting to harder query patterns

Multi-hop and comparative questions need more than one retrieval. “Which suppliers can terminate for convenience with under 60 days’ notice?” needs the list of supplier contracts, then the termination clause in each, then a comparison. A single top-K search returns whichever termination clauses happen to be closest in meaning, and misses the rest. Give Claude a search tool and let it loop: search, read, refine the query, search again. The Building effective agents post describes this as the augmented LLM, where the model writes its own search queries.

For broad surveys, the research post’s guidance is to start with short, broad queries, see what is there, then narrow. It warns against long, over-specific queries that return little. When a question splits into independent parts, such as the same fact for twenty companies, parallel subagents each search one part and return a condensed result. That is where a multi-agent design earns its token cost. It is a poor fit when every part depends on shared context. And when query types are distinct and predictable, a routing step that classifies the question and sends it to the right retrieval path is simpler than a fully agentic search.

Traps the wrong answers are built from

Tempting but wrongDo this instead
Putting tables, live records and prose into one vector index “so it’s all searchable”Keep structured and live data behind query tools; index only the prose.
Answering counts and totals from top-K retrieved chunksRoute aggregation questions to a tool that queries the database and returns the number.
Indexing data that changes by the minuteFetch it with a tool when the question is asked.
Using one single-shot search for multi-hop or comparative questionsLet Claude search iteratively, or split the question into sub-queries.
Running a multi-agent search for every simple FAQUse single retrieval for simple questions; save agentic and parallel search for questions that need it.

You should now be able to

  • Classify a data source by shape: structured, semi-structured, prose, code, or live.
  • Classify a question by pattern: lookup, conceptual, aggregation, multi-hop, survey, or freshness-critical.
  • Match each pairing to a retrieval method: hybrid search, structured query, agentic search, live tool call, or parallel subagents.
  • Weigh pre-computed retrieval against just-in-time retrieval on latency, cost, freshness and question complexity.
  • Design narrow, parameterised retrieval tools that return only what the model needs.

Practice questions

Original questions written for this lesson, in the exam’s style. Answer first, then open the reasoning — every option is explained, including why the wrong ones are tempting.

  1. Question 1

    A finance team’s assistant uses RAG over exported expense claims, one claim per chunk. When asked “What did Marketing spend on travel in Q2?” it gives a figure that is far too low, citing six claims.

    What is the best change?

    1. ARaise top-K from 20 to 200 so more claims are included in the sum.
    2. BRechunk the export so each chunk holds a whole month of claims.
    3. CAdd a tool that queries the claims database with filters and returns the total.
    4. DSwitch to a domain-specific finance embedding model.
    Show answer and reasoning
    1. AIncorrect. More chunks is still a sample, and it swaps undercounting for context bloat. The totals would still be unreliable.
    2. BIncorrect. Bigger chunks change what is retrieved but still leave Claude adding numbers from partial text.
    3. CCorrect. This is an aggregation over structured rows. The database should compute it, and Claude should report and explain the result.
    4. DIncorrect. Better similarity ranking does not turn retrieval into summation. The failure is the method, not the embedding.
  2. Question 2

    An engineering organisation wants an assistant that answers questions about a 4-million-line monorepo that changes hundreds of times a day. A vendor proposes nightly embedding of every file.

    Which approach best fits the data and query pattern?

    1. AAccept the proposal; embeddings are the standard way to search large corpora.
    2. BLoad the entire repository into a 1M-token context for every question.
    3. CFine-tune a model on the repository weekly so it knows the code.
    4. DGive the agent search tools such as grep, glob and file reads, and let it explore on demand.
    Show answer and reasoning
    1. AIncorrect. Nightly embeddings are stale by mid-morning, and code questions usually hinge on exact symbols that embeddings match poorly.
    2. BIncorrect. The repository is far larger than any context window, and loading it all would be slow and costly even if it fitted.
    3. CIncorrect. Fine-tuning does not give reliable recall of exact current code, and it is out of date between runs.
    4. DCorrect. Just-in-time retrieval with exact-match tools reads the current code and follows references, which is how Claude Code works on codebases.
  3. Question 3

    A consultancy’s research assistant must answer questions such as “Summarise the AI regulation stance of each of the 27 EU member states’ data protection authorities.”

    Which retrieval design fits this question pattern best?

    1. AParallel subagents, each covering some countries, feeding a lead agent.
    2. BA single top-20 vector search over a corpus of regulator publications.
    3. CA long, highly specific single query that lists all 27 countries.
    4. DA structured SQL tool over a table of regulatory stances.
    Show answer and reasoning
    1. ACorrect. This is a breadth-first question with independent parts. Parallel subagents each cover one slice with their own context, which is where multi-agent search pays off.
    2. BIncorrect. Twenty chunks cannot cover 27 authorities. Most countries would get nothing, or a passage about a different topic.
    3. CIncorrect. Anthropic’s research guidance warns that long, over-specific queries return few results. Start broad and split the work.
    4. DIncorrect. No such table exists. The information is scattered across prose publications that have to be read and summarised.
  4. Question 4

    A support bot answers 50,000 simple “how do I…” questions a day from a stable help centre. A team proposes making every question run through an agentic, multi-step search. What is the strongest objection?

    1. AAgentic search cannot use hybrid retrieval, so exact-term matches would be lost.
    2. BAgentic search costs more tokens and time per question, with no benefit for single-passage answers.
    3. CAgentic search requires fine-tuning the model on the help-centre content first.
    4. DAgentic search only works with Claude Code, not the Messages API.
    Show answer and reasoning
    1. AIncorrect. An agent can call a hybrid search tool; that is not the objection.
    2. BCorrect. Runtime exploration is slower, and agents use several times the tokens of a chat. Simple questions from stable text are exactly what one pre-computed retrieval handles well.
    3. CIncorrect. Agentic retrieval needs tools and a loop, not fine-tuning.
    4. DIncorrect. Any application can run a tool-use loop over the Messages API.

Sources

Drafted with AI assistance and checked against the sources above; expert review is in progress. Spotted an error? Tell us and it gets fixed, dated and listed on how this is written.