Not to be confused with TopK: TopK (capital T, capital K) is a search engine for accuracy-critical AI applications: hybrid search, multi-vector retrieval, custom ranking, and managed inference in one API. This page is about top-k, the general ranking concept.
What does top-k mean in search?
In search and retrieval, top-k is the number of results you ask for. A vector or hybrid query scores every candidate document, sorts by score, and returns the top k. Choosing k is a recall-versus-noise tradeoff: a larger k is more likely to include the right document but feeds more irrelevant material to whatever consumes the results.
In TopK's query API, the top-k cutoff is the sort-and-limit at the end of every query:
.sort(field("score"), asc=False).limit(10) # top-10 by score
Score every candidate
Sort by score
Keep the top k
k = 10 means ten results
In two-stage pipelines the value of k often differs per stage: a first stage might retrieve top-200 candidates, and a reranker narrows them to top-5 for the final answer.
What does top-k mean in language models?
In text generation, top-k sampling restricts the model to the k most probable next tokens, then samples from just those. It caps how adventurous the model can be: top-k of 1 is greedy decoding (always the single most likely token), while a larger k allows more diversity. It is a sibling of top-p (nucleus) sampling, which selects the smallest set of tokens whose probabilities sum to p instead of a fixed count.
Why does the top-k / TopK distinction matter?
Search terminology and a product name collide here. "Top-k retrieval" is a decades-old concept in information retrieval, so context and capitalization are the only way to tell whether a page means the ranking cutoff or the search engine. When precision matters, write "top-k retrieval" for the concept and "TopK" for the product, and don't rely on capitalization alone.