Evaluating Retrieval Algorithms
Indexing and querying trade off against each other: a more detailed index gives more accurate retrieval, but it is slower and more memory-consuming to build.
Why Retrieval Needs Preparation
Every retrieval system has to answer a question that sounds simple: given a query, which stored items are the most relevant? The difficulty is that answering it quickly requires preparation. Before any query arrives, the system builds an index, which is a structure that organizes the stored items so that searching them later is fast. How much work goes into that structure is a choice, and that choice shapes everything that follows.
The central idea of this article is a trade-off. In retrieval systems, the more detailed the index is, the more accurate the retrieval process will be. The cost is that building the index becomes slower and more memory-consuming. Accuracy at query time is bought with effort at build time. Learning to see both sides of that exchange is what lets you choose an index that fits a real application, instead of defaulting to whichever one sounds most powerful.
Tracing a Customer Index
Picture an index of potential customers. Each entry can hold only a name, or it can hold much more: the person's company, email address, phone number, and interests. Before reading on, think about what each choice does to the people who will search this index later.
What do you think happens?
If each customer entry holds a company, email address, phone number, and interests instead of only a name, what happens to the cost of creating each entry?
Reveal answer
Each entry takes longer to create and needs more storage.
The richer entries cost more time and space to build. The payoff comes at search time: a search over rich entries is more likely to surface the right people for a campaign, because there are more attributes to match against.
Notice the two halves of the exchange. The rich entries pay off during searching, because the search has more attributes to work with. They pay during building, because every entry takes longer to create and occupies more storage. The customer example makes the trade-off visible before any algorithm name enters the picture.
The Detail Dial: Accuracy Against Build Cost
The same reasoning applies to the indexes that retrieval systems build over vector data. Extra detail in the index gives the search more structure to exploit, and that structure is what helps it find relevant results. However, the extra structure has to be constructed first, and it occupies space once it exists. A more detailed index therefore moves the system along a dial: accuracy at query time rises, while build time and memory use rise with it.
Read the diagram column by column. The simple index is cheaper to build and smaller, and its accuracy is lower. The detailed index sits on the other side of the dial: it costs more to build and occupies more memory, and in return it retrieves more accurately. The diagram does not show a single winner. It shows a balance that you have to place for each application.
HNSW and LSH at Opposite Ends
The source uses two named ANN indexes to show the trade-off in concrete form. HNSW is described as a detailed index. In general it provides high accuracy and fast query times, but it requires significant time and memory to build. LSH is described as a simpler index. It is quicker and less memory-intensive to create, but the queries it answers are slower and less accurate. The two indexes sit at opposite ends of the same dial.
Read each row across the two columns. HNSW pays at build time, with significant time and memory required, and in return answers queries quickly and accurately. LSH pays at query time, since its queries are slower and less accurate, and in return it is quicker and lighter to create. The source compares these behaviors at the level of cost and results. It does not describe how either index is constructed internally, so the comparison here stays with what each index costs and how it behaves when queried.
Following One Index Through Its Life
Trade-offs become easier to feel when you follow a single index through its life rather than comparing it at one moment. The source describes a team that maintains a catalog that changes every day. Its index goes through several phases, and each phase stresses a different metric.
A Catalog Index Across One Day
A team maintains a catalog that changes every day and uses a detailed index. Trace which costs and benefits matter in each phase of the index's life.
- 1Build the index
The index is built once. Because it is detailed, this build takes significant time and memory, so build time and index size are the metrics under stress.
- 2Query all day
The index is queried throughout the day. Here the detailed structure pays off, because queries are fast and accurate. Queries per second and the fraction of true nearest neighbors found are the metrics that matter.
- 3Catalog changes
Whenever the catalog changes, the index must be rebuilt or updated. The build cost returns, so an index that looked excellent during querying can become expensive at this point.
- 4Compare the phases
The same index scores well in the query phase and poorly in the build phase. Judging it fairly means looking at every phase, not only the one that happens to be the most visible.
The same index can look excellent in one phase and expensive in another, so an evaluation has to account for all of them.
Four Metrics for Comparing ANN Algorithms
How do you know whether an index sits at the right point on the dial? The ANN-Benchmarks website compares different ANN algorithms on multiple datasets, and it uses four main metrics that take the trade-off between indexing and querying into account. Each metric captures a different side of the picture. Together they let you judge an algorithm on what it costs to build, how fast it answers, how well it finds the true neighbors, and how much space it takes up.
| Metric | What It Measures | Side of the Picture |
|---|---|---|
| Fraction of nearest neighbors found | How many of the true nearest neighbors the index retrieves | Accuracy |
| Queries per second | How many queries the algorithm answers each second | Query throughput |
| Index build time | How long it takes to construct the index | Build cost |
| Index size | How much space the index occupies | Memory footprint |
The four ANN-Benchmarks metrics and the side of the trade-off each one captures
The first metric, the fraction of nearest neighbors found, is the one most directly tied to the detailed-versus-simple distinction, because it measures accuracy. The other three are costs or capacities: query throughput, build time, and index size. A complete comparison has to look at both sides. An algorithm that scores well on accuracy alone may still fail the build-time or storage limits of a real system.
Evaluating a RAG Pipeline at Two Levels
The same discipline of measuring what matters extends beyond the index to the whole retrieval-augmented generation pipeline. The source's summary is that the quality of a RAG system should be evaluated both component by component and end to end. Component-wise evaluation looks inside the pipeline, checking the parts that feed the final answer. End-to-end evaluation looks at the system's final outputs as a whole.
- Retrieval quality: checked inside the pipeline, to see whether the system finds the material that should feed the answer
- Embeddings: checked inside the pipeline when retrieval is embedding-based
- Final RAG outputs: checked from the outside, to see the answers the system actually produces
Both levels are needed because each can hide a problem from the other. Evaluating only the final answers can hide a weak retriever, since a good-sounding answer may come from luck or from a generator that compensates. Evaluating only the retriever can miss a generator that fails to use good retrieved material. Checking the components and the whole together gives you a picture that neither view provides alone.
Mistakes When Reading the Trade-Off
Common mistake Treating the most detailed index as automatically the best choice
What it looks likeChoosing HNSW for a catalog that is rebuilt whenever it changes, without considering the build time each rebuild requires
Why it failsThe trade-off has two sides. Accuracy at query time is bought with effort at build time, so build cost is part of the decision.
Do this insteadMatch the index to the side of the dial your application needs, and check the build phase as well as the query phase.
Common mistake Judging an algorithm on accuracy alone
Why it failsAccuracy is only one of the four ANN-Benchmarks metrics. The other three cover query throughput, build time, and index size.
Do this insteadCompare algorithms on all four metrics before deciding, since an accurate index can still break a build-time or storage limit.
Common mistake Assuming a simple index is always the inferior choice
Why it failsA simple index is quicker and lighter to build. That is the right trade when building must be cheap and the accuracy requirement is modest.
Do this insteadDecide based on the requirements of the application, not on which index sounds more powerful.
Common mistake Evaluating only the final answers of a RAG system
Why it failsGood final answers can hide a weak retriever, and the component-level checks cover retrieval quality and embeddings.
Do this insteadEvaluate component by component as well as end to end.
Choosing an Index for a Real Application
A small team runs a support knowledge base of a few hundred articles. The articles change only a few times a year, so a rebuild is rare. The team wants answers that are reliably accurate and is willing to spend time building the index once. Using the trade-off from this article, decide whether HNSW or LSH fits better, and name the metric you would check first before committing. Then consider how your answer would change if the knowledge base were rebuilt every hour.
Hints
- Start by asking which side of the dial the application needs: query quality or cheap building.
- Recall that HNSW is described as high accuracy with fast queries but significant build cost, and LSH as quicker to build but with slower, less accurate queries.
- Think about the phases of an index's life: the index is built, queried, and rebuilt or updated when the content changes.
Key Takeaways
- Indexing and querying trade off against each other: a more detailed index gives more accurate retrieval, but it is slower and more memory-consuming to build.
- HNSW is a detailed index with high accuracy and fast queries but significant build cost, while LSH is quicker and lighter to build but yields slower and less accurate queries.
- The ANN-Benchmarks comparison uses four metrics: the fraction of nearest neighbors found (accuracy), queries per second, index build time, and index size.
- A RAG system should be evaluated component by component, covering retrieval quality and embeddings, and end to end, covering the final outputs, because each level can hide problems in the other.