Skip to content
Algorithms Advanced

How to Measure Recall@K

Recall@K measures how many of the true top K nearest neighbors a vector search index returns for a query. To measure it, first compute exact ground truth with a flat index or brute-force search, then run the same queries against the approximate index, compare the returned IDs, and average the overlap across all test queries. The result tells you how much retrieval quality the index preserves as you tune for lower latency, higher throughput, or lower memory use.

This guide explains what Recall@K means, how to compute ground truth with a flat index, how to design a benchmark that produces reliable results, and how to interpret recall numbers when tuning an index. By the end, you should understand how to turn Recall@K from a single metric into a practical decision tool for vector search and retrieval systems.

What Recall@K Measures

Recall@K is a retrieval quality metric for nearest neighbor search. In a vector database, a query embedding is compared against stored vectors, and the system returns the K closest results according to a distance or similarity function. Recall@K asks a simple question: among the true top K nearest neighbors, how many did the tested index actually return?

The usual calculation is: Recall@K equals the number of true top K neighbors found in the tested top K results, divided by K. If the exact top 10 neighbors are known and an approximate index returns 8 of those 10 IDs, the Recall@10 for that query is 0.8, or 80 percent. Across many queries, the benchmark reports the average Recall@K.

This metric is especially important for approximate nearest neighbor indexes. Approximate indexes avoid comparing every query to every stored vector, which makes search faster and cheaper at scale. The tradeoff is that they may miss some exact nearest neighbors. Recall@K quantifies that tradeoff in a way that can be compared across index settings.

A Simple Recall@K Example

Suppose the exact top 5 results for a query are document IDs A, B, C, D, and E. Your approximate index returns A, C, F, D, and G. The overlap is A, C, and D, so 3 of the 5 true nearest neighbors were retrieved. The Recall@5 for this query is 3 divided by 5, which equals 0.6.

The ordering of those overlapping IDs is not always considered in basic Recall@K. If the benchmark uses set overlap, A, C, and D count as found regardless of whether they appear in positions 1, 2, or 5. If ranking order matters for the application, Recall@K should be paired with another metric such as mean reciprocal rank, normalized discounted cumulative gain, or task-specific answer quality.

Once the definition is clear, the next challenge is more practical: how do you know which results are the true nearest neighbors? That is where ground truth matters. Without a reliable exact baseline, Recall@K becomes a comparison between two uncertain systems instead of a measurement of index quality.

How to Measure Recall@K: 5-step diagram — Compute ground truth, Run the same queries, Compare the IDs, Divide by K, Average across queries.
Compare the approximate index against an exact baseline, query by query.

Computing Ground Truth With a Flat Index

Ground truth is the exact top K result set for each benchmark query. In vector search, it is commonly computed with a flat index, also called an exact or brute-force index. A flat index does not use a graph, clustering layer, quantization shortcut, or other approximate structure. It compares the query vector against every candidate vector and sorts the results by the chosen distance or similarity metric.

The flat index is slower than an approximate index, especially as the dataset grows, but that slowness is the point. It gives you the most direct answer to the question: if we searched exhaustively, which K vectors would be closest? Those exact results become the benchmark target that the faster index tries to match.

To build ground truth, use the same vector embeddings, normalization rules, distance metric, and candidate pool that the approximate index will use. If the production system searches with cosine similarity over normalized vectors, the flat search should do the same. If the benchmark includes metadata filters, the exact baseline should apply the same filters before selecting the nearest neighbors.

Steps for Ground Truth Generation

  1. Select a representative set of benchmark queries. These should reflect real query patterns, not only easy or synthetic examples.
  2. Run exact search over the full eligible corpus for each query. Use the same distance metric and filtering rules that the tested index will use.
  3. Store the top K or top N exact result IDs for each query. Many teams store more than K, such as the top 100, so they can later evaluate Recall@10, Recall@20, and Recall@50 without recomputing ground truth.
  4. Record distances or similarity scores along with IDs. Distances help diagnose ties, near-ties, and cases where many candidates are almost equally close.
  5. Version the corpus, embeddings, query set, and ground truth file. Recall numbers are only comparable when the underlying data has not silently changed.

For small and medium datasets, exact search can often be run directly. For very large datasets, teams may compute ground truth in batches, use accelerated exact search, or sample a subset of the corpus for controlled experiments. The important point is that the ground truth process should be more exhaustive and less approximate than the index being evaluated.

Ground truth gives you a trusted target, but it does not make the benchmark reliable by itself. The benchmark also needs a consistent methodology so that recall, latency, and throughput are measured under conditions that resemble the system you actually plan to run.

Benchmark Methodology for Recall@K

A useful Recall@K benchmark measures quality and performance together. Looking only at recall can lead to an index configuration that is accurate but too slow. Looking only at latency can lead to a system that responds quickly while missing important neighbors. The goal is to build a repeatable process that shows the recall-latency tradeoff across index settings.

Start by fixing the inputs that should not change during a run. Use one corpus version, one embedding model or vector source, one distance metric, one query set, and one ground truth file. Then test each index configuration against those same inputs. This makes the results comparable and keeps the benchmark focused on index behavior rather than data drift or query changes.

The benchmark should report Recall@K alongside latency percentiles, queries per second, memory use, index build time, and index size when those metrics matter for the application. For production retrieval systems, p95 and p99 latency are often more useful than average latency because tail latency affects user experience and downstream generation pipelines.

Recommended Benchmark Flow

  1. Prepare the dataset and queries. Use a representative corpus and query set, including common, rare, short, long, and ambiguous queries when relevant.
  2. Compute exact ground truth. Use a flat search path and store the exact nearest neighbor IDs for each query.
  3. Build the approximate index. Record build parameters, build time, index size, and memory footprint.
  4. Warm up the system. Run enough queries before measurement to reduce cold-cache effects when your production system will normally be warm.
  5. Run the benchmark queries. Measure Recall@K by comparing approximate results with ground truth and measure latency for each query.
  6. Sweep index parameters. Test multiple settings, not just one. The useful result is usually a curve showing recall against latency or throughput.
  7. Repeat or stabilize runs. Re-run configurations when results vary, and keep hardware, thread counts, batching, and concurrency consistent.

The benchmark should match the actual retrieval path as closely as possible. If production queries include metadata filters, the benchmark should include filtered queries. If production runs hybrid retrieval, the vector-only Recall@K result is still useful, but it does not describe the full system. If production uses reranking, measure the vector index separately and then measure the full retrieval pipeline so you know where quality is gained or lost.

Common Benchmark Mistakes

One common mistake is testing on a query set that is too small or too clean. A handful of handpicked queries can make an index look better than it is. Another mistake is using different distance logic for ground truth and approximate search. For example, comparing normalized vectors in one path and unnormalized vectors in another can make recall numbers misleading.

It is also easy to hide important costs. Some benchmarks time only the internal index lookup, while others include request parsing, filtering, result assembly, network overhead, or reranking. Neither approach is automatically wrong, but the benchmark should state what is timed. Otherwise, two Recall@K and latency results may appear comparable even though they measure different parts of the system.

Once the benchmark produces stable results, the next step is interpretation. Recall@K is not a moral score where higher is always better in isolation. It is a signal that helps you choose the operating point where retrieval quality, speed, memory, and cost fit the use case.

Common Recall@K Benchmark Mistakes: Query set too small or clean, Mismatched distance logic, Hidden timing costs, Ignoring filters.
Small errors in setup make recall numbers misleading.

Interpreting Recall@K Results

Recall@K should be read in context. A Recall@10 of 0.95 means the index returns, on average, 95 percent of the exact top 10 neighbors. That may be excellent for an interactive semantic search application, acceptable for a retrieval-augmented generation system with reranking, or insufficient for a workflow where missing one nearest neighbor can create a serious downstream error.

The first interpretation question is whether the missing neighbors matter. Exact nearest neighbors are mathematically closest under the embedding model, but they are not always the most useful documents for the user task. In RAG systems, for example, a missed exact neighbor may not hurt answer quality if another retrieved passage contains the same evidence. On the other hand, low Recall@K can be a strong warning sign if the system depends on retrieving rare facts, compliance records, support tickets, or highly specific entities.

The second interpretation question is how recall changes as K changes. Recall@10, Recall@20, and Recall@50 can tell different stories. If Recall@10 is low but Recall@50 is high, the index may be finding the right neighborhood but not ranking enough exact neighbors at the very top. If both Recall@10 and Recall@50 are low, the search path may be too approximate, the index may be poorly tuned, or the query distribution may not fit the index configuration.

Reading the Recall-Latency Curve

The most useful benchmark output is often a curve rather than a table. As search effort increases, recall usually rises and latency usually rises with it. At low effort, the system is fast but misses more exact neighbors. At high effort, the system approaches exact-search quality but loses some of the speed advantage that made approximate indexing useful.

Look for the point where extra search effort produces only small recall gains. For example, moving from 0.90 to 0.95 Recall@10 may be worth a few milliseconds. Moving from 0.98 to 0.99 may be much more expensive. The right choice depends on the retrieval task, the latency budget, and how much downstream components can recover from imperfect retrieval.

A single recall number tells you what happened at one configuration. The curve tells you how the index behaves as you tune it. That behavior is what you need when deciding whether to adjust parameters, change index type, add reranking, or revisit the data model.

Using Recall@K to Tune an Index

Index tuning is the process of choosing parameters that put the system at the right point on the recall-latency curve. Different index families expose different controls, but the pattern is similar. Increasing search effort usually improves recall while increasing latency. Increasing build-time quality or graph connectivity can improve search quality, but it may also increase memory use and build time.

For graph-based indexes, tuning often involves search-time exploration parameters and build-time graph quality parameters. Higher search effort lets the query explore more candidate paths before returning results. Denser or better-built graphs may improve recall, especially for hard queries, but they can use more memory and take longer to construct.

For inverted-file or cluster-based indexes, tuning often involves how many partitions are searched for each query. Searching more partitions improves the chance of finding the exact nearest neighbors, but it also scans more candidates. For compressed indexes, such as those using quantization, recall can drop because distances are estimated with compressed representations. In those cases, reranking a larger candidate set with original vectors can sometimes recover quality.

A Practical Tuning Pattern

  1. Set a target. Choose a recall goal and latency budget based on the application, such as Recall@10 of 0.95 under a p95 latency threshold.
  2. Start with a conservative configuration. Use settings that are likely to produce high recall, even if they are slower than desired.
  3. Reduce search cost gradually. Lower search effort, candidate count, or partition coverage until recall approaches the minimum acceptable level.
  4. Test hard query segments separately. Break results down by query type, filter selectivity, document category, or embedding source to find weak spots.
  5. Check memory and build cost. A configuration that performs well at query time may still be impractical if it uses too much memory or takes too long to rebuild.
  6. Validate with downstream quality. For RAG and semantic applications, confirm that the selected Recall@K operating point supports answer quality, not just nearest-neighbor overlap.

Recall@K tuning should not stop after the first launch. Corpora change, embeddings are updated, user queries shift, and filters become more complex. A good retrieval system periodically reruns the benchmark so index settings remain appropriate for the data and workload it actually serves.

The final piece is knowing what Recall@K can and cannot tell you. It is one of the most useful metrics for index evaluation, but it is not a complete measure of search quality by itself.

Limits of Recall@K

Recall@K measures overlap with exact nearest neighbors, not whether the retrieved content fully satisfies a user. This distinction matters because embeddings are imperfect. The exact nearest neighbor under a vector distance function may be semantically close, but it may not be the best answer, the most authoritative document, or the passage with the right level of detail.

Recall@K also depends on the chosen K. A system can have strong Recall@100 and weak Recall@10, which may be a problem if the application only sends the top 10 results to a reranker or language model. Conversely, a lower Recall@10 may be acceptable if the application retrieves a larger candidate set and reranks it effectively.

Filtered search adds another complication. If a query is restricted to a narrow metadata slice, the index may have fewer valid candidates to explore. Some index structures handle filtering more efficiently than others, so filtered Recall@K should be measured separately from unfiltered Recall@K when filters are common in production.

Because of these limits, Recall@K works best as part of a metric set. Pair it with latency, throughput, memory, build cost, filter performance, reranker quality, and task-level evaluation. That combination gives a more complete picture of whether the retrieval system is fast, accurate, and useful.

FAQs

1. What is Recall@K in vector search?

Recall@K is the fraction of true top K nearest neighbors that a tested search index returns. If the exact top 10 neighbors are known and the approximate index returns 9 of them, the query has Recall@10 of 0.9. The benchmark usually averages this score across many queries.

2. Why use a flat index for ground truth?

A flat index performs exhaustive search over the candidate vectors, so it is commonly used as the exact baseline. It is slower than approximate indexes, but it avoids the shortcuts that can cause approximate search to miss nearest neighbors. That makes it useful for creating the ground truth result IDs needed to compute Recall@K.

3. Is Recall@K the same as precision?

No. Recall@K measures how many true nearest neighbors were found. Precision usually measures how many returned results are relevant. In nearest neighbor benchmarking, Recall@K is about overlap with exact top K results, while precision is more often used when relevance labels are based on human judgment or task-specific criteria.

4. What value of Recall@K is good?

There is no universal good value. A real-time search interface may accept lower recall for faster responses, while a high-stakes retrieval workflow may need very high recall. The practical goal is to choose the lowest-cost index setting that meets the quality needs of the application.

5. Should I measure Recall@10, Recall@20, or Recall@100?

Measure the K values that match how the system is used. If the application only displays 10 results, Recall@10 is important. If the retriever sends 50 candidates to a reranker, Recall@50 may be more useful. Many teams compute several K values from the same ground truth so they can understand how retrieval quality changes as the result window grows.

6. Can high Recall@K guarantee good RAG answers?

No. High Recall@K means the index is returning exact nearest neighbors, but a RAG system also depends on chunking, embeddings, metadata filters, reranking, prompt design, and the generation model. Recall@K is a strong index-level metric, but it should be paired with answer-level evaluation for RAG applications.

Takeaway

Recall@K is a practical way to measure how much nearest-neighbor quality an approximate vector index preserves compared with exact flat search. It is most useful for engineers and data teams tuning vector databases, RAG retrievers, semantic search systems, and other AI data applications where speed and retrieval quality must be balanced. By computing reliable ground truth, benchmarking with consistent methodology, and reading recall alongside latency, memory, and downstream quality, teams can tune an index for the operating point that fits their real use case.