What actually happens in the gap between a user hitting enter and the first token of a RAG answer appearing? For most teams, the instinct is to blame the large language model. But a growing number of engineers are discovering that the retrieval side of retrieval-augmented generation carries more of the delay than they assumed, especially at high top-k settings or when reranking enters the picture. RAG retrieval latency is the time a system spends turning a user query into a ranked set of relevant passages, and understanding it is the difference between a snappy assistant and one that feels broken.
This article breaks down where that time goes, how index design shapes it, and what practical tuning actually moves the needle.
What RAG retrieval latency really measures
A RAG pipeline is a chain, and every link adds time. The chain usually looks like this: the query gets embedded into a vector, that vector is compared against a store of document embeddings, optional keyword search runs in parallel, a reranker re-scores the shortlist, the prompt is assembled, and only then does the LLM generate. Retrieval latency covers the middle steps, from embedding through reranking.
The architecture itself was formalized in the retrieval-augmented generation paper by Lewis and colleagues, which introduced the pattern of combining a retriever with a generator for knowledge-intensive tasks. That framing matters because it separates the two cost centers: the retriever’s job is fast and deterministic, while the generator’s job is slow and probabilistic.
In practice, retrieval is often a small slice of total response time when generation dominates. But flip the conditions, and the picture changes. Short answers, large top-k values, and heavy reranking can all push retrieval into the leading role. Teams that benchmark only the LLM are measuring half the system.
The stages that add milliseconds

Breaking retrieval into stages helps pinpoint where time disappears. Each stage has a different cost profile and a different fix.
Query embedding
Before any search happens, the query must be converted into a vector using the same embedding model that processed the corpus. This is usually fast for a single short query, but it is not free. Hosted embedding APIs add network round-trip time, and cold starts on serverless infrastructure can add seconds. Self-hosted embedding models avoid the network hop but consume GPU or CPU cycles that may be contended with other work.
A common mistake is assuming embedding is negligible because it is “just one query.” In a system handling hundreds of concurrent requests, embedding becomes a queue, and queue time is latency.
Vector search
This is the stage most people mean when they say retrieval latency. Exact nearest-neighbor search over millions of vectors is computationally brutal, which is why almost every production system uses approximate nearest neighbor (ANN) search instead. ANN trades a small amount of recall for a large amount of speed.
The dominant ANN structure is HNSW, or Hierarchical Navigable Small World graphs, introduced by Malkov and Yashunin. HNSW organizes vectors into a layered graph and navigates it greedily, so query time scales sub-linearly with corpus size rather than linearly. That is the whole trick: you get fast lookups at billion-vector scale, but the results are approximate, not guaranteed exact.
At larger scales, teams often reach for FAISS, the open-source similarity search library from Facebook AI Research described in the billion-scale similarity search work by Johnson, Douze, and Jégou. FAISS supports GPU acceleration and a wide menu of index types, which makes it a common baseline for benchmarking retrieval latency at scale.
Reranking
Many pipelines retrieve a wide candidate set and then re-score it with a cross-encoder reranker. The passage re-ranking work by Nogueira and Cho showed that jointly scoring query-document pairs with a transformer beats simpler similarity methods on accuracy. The catch is cost: cross-encoders must run a forward pass per candidate, so reranking 100 documents means 100 forward passes. That is why rerankers are applied to a shortlist rather than the whole corpus.
Reranking is frequently the hidden latency hog. A pipeline that retrieves in 15 milliseconds and reranks in 180 milliseconds has a reranking problem, not a vector search problem.
Prompt assembly and handoff
Stuffing retrieved passages into a prompt, truncating to fit a context window, and serializing the request to the LLM provider all take time. This stage is usually small but grows with top-k and passage length. It is also where teams accidentally double their token counts by including redundant chunks.
How index parameters control the speed-accuracy trade-off
The recall-latency trade-off is not fixed. It is a dial, and the dial has names.
For HNSW, the key parameters are M (the number of bidirectional links per node) and efSearch (the size of the dynamic candidate list during search). Raising efSearch improves recall but increases query latency, roughly linearly. Raising M improves graph connectivity and recall but costs memory and build time. The official HNSW library documentation spells out these relationships, and it is worth reading before tuning blind.
For IVF-style indexes, the equivalent dial is nprobe, the number of inverted lists scanned per query. More lists means better recall and slower queries.
Product quantization (PQ), introduced by Jégou, Douze, and Schmid, compresses vectors into compact codes so distance computations run faster and memory footprints shrink. The trade-off is accuracy: compressed vectors approximate distances, so recall drops unless you compensate elsewhere. PQ is often paired with reranking to recover quality.
| Parameter | What it controls | Latency effect | Recall effect |
|---|---|---|---|
| efSearch (HNSW) | Candidate list size at query time | Higher = slower | Higher = better |
| M (HNSW) | Graph connectivity | Higher = more memory, slower build | Higher = better |
| nprobe (IVF) | Lists scanned per query | Higher = slower | Higher = better |
| PQ subquantizers | Vector compression level | More compression = faster | More compression = worse |
The practical lesson: never tune these parameters in isolation. Tune them against a fixed recall target, and measure latency at that target.
Measuring retrieval latency without fooling yourself
Benchmarking retrieval is where good intentions go to die. A few traps catch almost everyone.
First, measuring only the mean. A 40-millisecond average sounds great until you see the p99 sitting at 900 milliseconds. Tail latency is what users feel, because the slow requests are the ones they remember. Track p50, p95, and p99 separately, and track them per stage.
Second, benchmarking on a warm cache. The first query after a deploy hits cold indexes, cold embedding models, and cold connection pools. Production traffic includes those conditions; your benchmark should too. A structured approach to measuring inference latency end to end helps here, because it forces you to instrument every hop rather than just the final response.
Third, ignoring concurrency. A single-threaded benchmark tells you nothing about behavior under load. Run tests at realistic concurrency levels, because vector search, embedding, and reranking all contend for the same hardware.
Fourth, trusting vendor numbers. Vector database vendors publish impressive latency figures, and those figures are usually real, but they are also marketing-adjacent. Hardware, dimensionality, index type, recall target, and dataset shape all move the number by an order of magnitude. Treat published benchmarks as indicative and reproduce them on your own data.
A useful discipline is to log the timing of each stage per request, then aggregate. When latency spikes, the stage breakdown tells you instantly whether to look at the index, the reranker, or the embedding service.
Practical tuning that actually works
After the measurement groundwork, a handful of changes reliably help.
- Cap top-k before reranking. Retrieve 50 candidates, rerank 20, pass 5 to the LLM. Retrieving 500 and reranking all of them is a latency disaster with marginal quality gains.
- Shrink the reranker. A smaller cross-encoder on 20 candidates often beats a large one on 100, both in latency and in end-to-end quality per millisecond.
- Cache aggressively. Embeddings for repeated queries, retrieval results for common questions, and reranker scores for stable document sets can all be cached. Hit rates on real traffic are often surprisingly high.
- Warm the indexes. Keep the vector index resident in memory and preload embedding models at startup. Cold starts are the enemy of p99.
- Separate retrieval from generation infrastructure. If embedding and vector search share a GPU with the LLM, they will starve each other under load.
- Right-size the index. HNSW memory grows with corpus size and M. If the corpus is small, a flat index may be faster and simpler.
A related discipline is reviewing who and what can touch the index. Access patterns, refresh cadence, and permission filters all affect query cost. A periodic review of access to a retrieval index catches the cases where a filter or a stale shard is quietly adding latency.
Where retrieval quality and retrieval latency intersect
Speed without relevance is pointless. A retrieval system that returns garbage in 5 milliseconds has failed. This is why latency tuning must happen alongside quality evaluation.
The two are coupled through the same parameters. Raise efSearch and you get better recall and more latency. Lower top-k and you get less latency and possibly worse answers. The only way to navigate the trade-off is to measure both sides at once, using a practical checklist for evaluating retrieval quality so that speed gains never silently degrade answer accuracy.
A useful pattern is to define a recall target first, say 90 percent of relevant documents retrieved, then optimize latency subject to that constraint. This flips the usual question from “how fast can we go” to “how fast can we go without breaking quality,” which is the question that actually matters.
Conclusion
RAG retrieval latency is rarely one number. It is a stack of small costs, from query embedding through vector search, reranking, and prompt assembly, and the biggest cost is not always where teams expect. ANN indexes like HNSW and libraries like FAISS make large-scale search fast, but they do so by trading exactness for speed, and that trade is tunable through parameters such as efSearch, M, and nprobe.
The teams that get this right share a habit: they instrument every stage, they track tail latency rather than averages, they benchmark under realistic concurrency, and they tune against a fixed quality target instead of chasing raw speed. They also resist the temptation to trust vendor benchmarks over their own measurements. None of this is glamorous, but it is what separates a RAG system that feels instant from one that makes users wait.
FAQ
What is a typical RAG retrieval latency?
There is no universal number. Retrieval time depends on corpus size, index type, dimensionality, recall target, hardware, and concurrency. A small in-memory index can answer in single-digit milliseconds, while a large distributed index with reranking can take hundreds. The honest answer is that any specific figure must come from your own benchmark on your own data, not from a general rule.
Is vector search or LLM generation the bigger latency cost?
Usually generation, but not always. When answers are long and top-k is small, the LLM dominates. When top-k is large, reranking is heavy, or the answer is short, retrieval can take the lead. The only way to know is to instrument both stages separately and compare their shares under realistic traffic.
Does approximate nearest neighbor search hurt answer quality?
It can, because ANN returns approximate results rather than exact ones. The effect depends on how aggressively you tune for speed. At moderate settings, recall loss is often small enough that reranking recovers quality. At aggressive settings, relevant documents get missed entirely, and no amount of reranking fixes a candidate set that never contained the right passage.
Why is my p99 latency so much worse than my average?
Tail latency usually comes from cold caches, garbage collection pauses, queueing under load, index rebuilds, or occasional large queries that trigger expensive reranking. Averages hide these events because most requests are fast. Tracking p95 and p99 per stage is the fastest way to find which stage is producing the outliers.
Can I reduce retrieval latency without losing accuracy?
Often yes. Caching repeated queries, capping top-k before reranking, using a smaller reranker on fewer candidates, warming indexes at startup, and separating retrieval infrastructure from generation infrastructure all reduce latency with little or no quality cost. The gains come from removing waste rather than from cutting corners on recall.
How often should retrieval latency be re-benchmarked?
Whenever the corpus grows substantially, the index type or parameters change, the embedding model is swapped, or traffic patterns shift. In practice, a quarterly benchmark plus a re-run after any major change catches most regressions. Continuous per-stage monitoring in production is better still, because it catches drift that periodic benchmarks miss.







