Your legal team gets an internal contracts assistant, and one afternoon someone asks it an ordinary question: which agreements expire in March. The assistant searches its embedding index (the kind of index that finds text with a similar meaning) and returns three contracts that discuss termination, renewal windows, and end-of-term obligations, and none of the three expires in March. One agreement that does expire that month never appears at all, because its wording reads like standard boilerplate, so the search does not rate it as close in meaning to the question and never returns it. The person asking opens the contract database by hand, finds four March expirations in under a minute, and stops trusting the assistant. Every contract in that system has its expiration date in a structured field, so a single SQL query could have returned the right answer all along.
In Retrieval: let the product look things up before it answers, you gave the product a lookup step so it could answer from your records instead of from training data. There we treated the lookup as one step, but there are several ways to look something up, each suited to a different kind of question, and the contracts assistant failed because it used a similarity search for a question that needed a database query. This chapter lists the methods and gives you a rule for choosing among them.
The retrieval methods and the questions each one handles best
Every question your product receives can be handled by one of four methods, and each works best on a different kind of question.
- Keyword search matches exact words. The index records which words appear in which documents, and the search returns the documents containing the question's words, weighted so rare terms count more than common ones. It works best on names, product codes, error strings, invoice numbers, and any question where the asker knows the exact term, such as
TLS_HANDSHAKE_TIMEOUTor "clause 14.2". It fails when people paraphrase, because "refund after cancellation" will never match a document that only says "post-termination reimbursement". - Vector search matches meanings. Vector search is also called embedding search or similarity search, and the index it searches is a vector index (or embedding index). An embedding is a list of numbers that represents the meaning of a passage, computed so that passages with similar meanings get similar numbers. The search computes an embedding for the question the same way and returns the passages whose embeddings are closest. It works on the paraphrase and concept questions where keyword search fails, and it fails on the exact terms where keyword search works, because a part number or an error string has almost no meaning to capture, so two unrelated codes can end up with nearly the same numbers.
- Hybrid search runs both and merges the two lists. Real questions often mix the two kinds, such as an exact product name and a paraphrased concept in one sentence, so running both searches and merging the results is the sensible default for any knowledge base made of prose.
- Structured lookup runs a real query. The diagram calls this a STRUCTURED QUERY. When the question is about fields (dates, owners, amounts, or statuses), the answer is stored in a database or a graph (a database that stores how records connect to each other), and the right retrieval is SQL or a graph query, not a search over prose. "Which agreements expire in March" is a filter on a date column, and a similarity search cannot answer it, which is exactly how the contracts assistant failed.
Rerankers: pay for a second pass only when it is worth the cost
The first search pass is built to be fast and to return many possible matches, so its ranking is rough. A reranker is a second, more careful pass: the fast search returns a few dozen candidates, and a slower model scores each candidate against the question and reorders them so the best ones are at the top. The first pass is designed not to miss the answer, and the reranker is designed to put the answer first.
That second pass adds a little delay and a model call to every query, so it is worth paying for only in specific conditions: when only the top three to five passages get handed to the model, when the first pass returns plausible near-misses (support macros, meaning saved reply templates, that almost apply, or near-duplicate policy versions), and when answer quality is worth a slightly slower response. It adds nothing to structured lookups, since a query over fields is already exact, and it adds little when the first pass already puts the right passage at the top.
Classify the question before you choose the index
What prevents the contracts failure is a habit, not a technology: before you pick an index, classify the questions people will send to it.
Classify the question first: send questions about exact words to keyword search, questions about meaning to embeddings, questions about fields to a real query, and questions that mix exact words and meaning to both.
The decision tree, titled CHOOSING A RETRIEVER (a retriever is the search method that finds the first set of candidate passages), covers the first-pass method only. Whether a reranker reorders the results afterward is the separate decision from the section above. The tree's four branches match the four methods, and its MIXED PROSE branch means questions that combine exact terms and paraphrase. You classify questions at two points:
- At design time. Pull a sample of the real questions your product will receive and sort each one into exact term, concept, field, mixed, or relationship. The mix tells you which indexes to build at all, and your sample may show that most of your traffic is field questions and the prose documents are a small part of the job.
- At query time. The product sorts each incoming question the same way, with a set of rules or a small, cheap classification call, and sends field questions to the database and prose questions to hybrid search.
Relationship questions, which the decision tree does not cover, are the kind that link one entity to another ("which vendors subcontract to vendors we already audited"). They need a graph query, though when they are rare, a couple of SQL joins (queries that combine records from two tables) usually handle them.
Chunking: you can only retrieve the units you indexed
Chunking is deciding how to split documents into the units (chunks) that the index stores and returns. It sounds like a technical detail, but it is a product decision.
What you index as one unit is what you can retrieve as one unit, so chunk size is a decision about what a good answer needs to quote.
Getting the size wrong hurts in either direction:
- If chunks are too small, the product returns the one clause that answers the question but not the definitions section that explains what the clause means.
- If chunks are too large, every question pulls in dozens of pages, most of them irrelevant, and they use up the window you will learn to budget in Context budgets: fit the right facts into a finite window.
The workable range runs from a paragraph to a few pages, sized by what a complete answer needs to quote, usually with a line or two of neighboring text attached so a retrieved chunk still makes sense on its own. Decide the size by reading actual answers, not by tuning settings: take your most common questions, look at what the product retrieved for each, and ask whether the chunk on screen was enough to answer from. The tools for chunk sizes, overlap (text that neighboring chunks share), and attaching neighboring text change too fast to describe here, so the specifics are in the dated Retrieval Stack Sheet.
Try it now
In this drill, which takes about 30 minutes, you collect evidence for which method should handle each kind of question about your own documents.
Pick a document set you know. Choose twenty or more documents where you can judge a result instantly, such as your product docs, a contracts folder, or a support macro library.
Write ten questions, deliberately mixed. Write three exact-term questions (a code, a person's name, a phrase you know appears verbatim), three concept questions (paraphrase the content so no distinctive words are shared), two field questions (a date, an owner, an amount), and two mixed questions that put an exact term and a concept in one sentence.
Run every question through a keyword search and an embedding search. Most vector databases offer both, and some document tools do too. Scale it down: if you have nothing set up, a free-tier vector database can embed a few dozen documents for pennies, and because the drill only compares rankings, you do not need production infrastructure.
Score each question. Note which method put the right document first, which placed it anywhere in the top five, and which missed it entirely.
Compare the results with the decision tree. Keyword search should have done best on the exact-term questions and embeddings on the concept questions, and both methods probably did badly on the two field questions. That is the main lesson of the drill: those two questions needed a database query, and no amount of search tuning would have answered them.
Chapter Summary
- Retrieval is not one method: keyword search matches exact words, vector search matches meanings, hybrid merges both lists, and structured lookup runs a real query over fields.
- Keyword search is best on names, codes, and error strings; embeddings are best on paraphrase and concept questions; each fails where the other is strong.
- Hybrid search is the sensible default for a prose knowledge base, because real questions often mix exact terms and paraphrase in one sentence.
- Send any question about fields, such as dates, owners, or amounts, to SQL or a graph query, never to similarity search.
- A reranker is a second, more careful pass that reorders the top results. Pay for it when only a few passages reach the model and the first pass returns many near-misses.
- Classify the question before choosing the index: sort it as exact term, concept, field, or relationship, and choose the method that matches.
- Chunking is a product decision, because what you index as one unit is what you can retrieve as one unit.
- Every method in this chapter searches your documents fresh for each question. What the product keeps about each user between sessions is a different kind of record, and it is the subject of Memory: decide what your product remembers.
Sources
- Robertson, S. and Zaragoza, H. (2009). The Probabilistic Relevance Framework: BM25 and Beyond. Foundations and Trends in Information Retrieval.
- Karpukhin, V. et al. (2020). Dense Passage Retrieval for Open-Domain Question Answering. EMNLP.
- Anthropic engineering blog (2024). Introducing Contextual Retrieval.
- The Retrieval Stack Sheet for current chunking, hybrid, and reranker tooling (last verified July 2026).