In a production RAG system with a 2-second end to end latency budget for non-streaming responses, which step typically dominates and where should the optimization effort go?
Same topic, related formats. Practice these next.
Same topic, related formats. Practice these next.
In a 2s RAG budget, LLM generation eats 1.2-1.8s; embed, retrieve, rerank, and augment together fit in 200-500ms. Optimize generation, not the retrieval stack.
Imagine a 2-second relay race with five runners. Four of them sprint their legs in a fraction of a second each: looking up the question's meaning, searching the library, reordering the best books, and gluing the pages into a packet. Then the fifth runner has to read the packet out loud, word by word, before anyone gets the answer. That last runner takes more than a full second on his own. If you want the race to finish faster, there's no point yelling at the four fast runners. You speed up the one who reads out loud: hand him a shorter packet, swap him for a quicker reader, or let him start speaking the moment he has the first word. In a RAG system the slow reader is the language model generating tokens one at a time.
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example.
Everything important, quickly.
3 min: enumerate the five steps with latencies, explain why generation is autoregressive and dominant, then list the generation side optimization levers in priority order.
| RAG step | Typical latency | Scales with | Optimization headroom |
|---|---|---|---|
| Query embedding | 50-100ms | Fixed (one forward pass) | Low |
| Vector retrieval (ANN) | 50-100ms | Barely (HNSW is log ish) | Low |
| Reranking (cross-encoder) | 100-200ms | Top-k candidate count | Low-medium |
| Prompt assembly | <10ms | Negligible | None |
| LLM generation | 1.2-1.8s | Output tokens + prompt size | High |
Real products, models, and research that use this idea.
What an interviewer would ask next. Try answering before peeking at the approach.
Red flags and common mistakes that signal junior thinking. Click to expand.
Assuming the vector database is the bottleneck. Well-tuned ANN retrieval is sub-100ms even at 10M docs; token by token generation is the part measured in seconds.
The night-before-the-interview bullets. Scan these on the way to the call.
Primary sources. Skim if you want the original framing.