One assistant, several ways to look things up
- Hybrid searchpolicies, manuals, contracts
- Structured queryorders, claims, metrics tables
- grep / globcode, logs, config files
- Live API callstock, account status, web
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 shape | Usually best served by | Why |
|---|---|---|
| Tables, ledgers, metrics | A 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 text | Narrow by customer, date or status before ranking by meaning |
| Long prose (policies, contracts, research) | Hybrid search with contextual chunks and reranking | Meaning and exact terms both matter (see 3.5) |
| Code, logs, config | Agentic search: grep, glob, reading files | Exact symbols, and files that reference each other |
| Live system of record | A tool that calls the system at question time | An index copy is stale the moment stock or status changes |
| Query pattern | What breaks with plain top-K vector search | Strategy that fits |
|---|---|---|
| Exact lookup by ID or name | Identifiers embed poorly | Keyword or BM25, or a direct lookup tool |
| Conceptual question | Usually works | Hybrid search + rerank |
| Count, sum, trend | Top 20 chunks cannot count 50,000 rows | Query the structured source; let it aggregate |
| Multi-hop or comparative | One query retrieves one side of the question | Break it into sub-queries and let Claude search repeatedly |
| Broad survey | One query can’t cover every angle | Start broad, then narrow; run parallel subagents |
| Freshness-critical | The index lags reality | A 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
- One passage from stable textSingle hybrid retrievalfast, cheap, cacheable
- A count, sum or trendStructured query toolthe database does the maths
- Facts that build on each otherAgentic multi-step searchClaude refines as it goes
- Many independent directionsParallel 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.
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 wrong | Do 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 chunks | Route aggregation questions to a tool that queries the database and returns the number. |
| Indexing data that changes by the minute | Fetch it with a tool when the question is asked. |
| Using one single-shot search for multi-hop or comparative questions | Let Claude search iteratively, or split the question into sub-queries. |
| Running a multi-agent search for every simple FAQ | Use 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.