Top-k (retrieval)
The number of highest-ranked search results passed on to the next step; in RAG, how many passages go into the prompt.

Top-k is the number of highest-ranked search results passed on to the next step; in RAG, how many passages go into the prompt. It is one of the few retrieval settings a non-engineer can reason about: too few passages and the answer is missing, too many and it gets buried.
A small k keeps the prompt short and cheap but risks leaving the needed passage out; a large k raises recall and adds noise, cost and latency. A common setup retrieves a wide set, for example 50, and lets a reranker keep the best few. There is no universal value. Anthropic’s Contextual Retrieval experiments compared 5, 10 and 20 chunks and found 20 worked best of those on their data, while noting that more material can also distract the model. The metric that tells you whether k is too small is context recall; the one that tells you it is too large is context precision.
The same term is used for a sampling setting in text generation, where the model picks the next token from the k most likely ones; that is a different thing, closer to temperature. When a vendor mentions top-k, ask which of the two they mean.
Sources
- Anthropic: Contextual retrieval in AI systems anthropic.com
Related terms
- Reranker: A model that rescores the top search results against the query, so the most relevant ones go to the language model first.
- Recall (AI metric): The share of all correct items that the system actually found: of everything it should have caught, how much it did.
- RAG (retrieval-augmented generation): Finding relevant documents first and putting them into the prompt, so the model answers from them.
- Context precision: A RAG retrieval metric: whether the passages relevant to the question are ranked at the top of what was retrieved.
- Context recall: A RAG retrieval metric: how much of the information needed for the correct answer was actually retrieved.
- Temperature (LLM non-determinism): A setting that controls how random a model’s word choices are; even at zero, answers can still differ between runs.
