Top-k
limit · Result count
The number of highest-ranked results a search returns, or that one stage passes to the next.
In DocSlurpGlossary entry
On this page
Top-k is how many results you ask for: the k highest-ranked passages. It appears at every stage of a retrieval pipeline. Each retriever returns its top k candidates, fusion and reranking produce a new top k, and the final top k goes to the user or into a model’s context window.
Choosing k for RAG is a trade-off. Too small, and the passage with the answer may sit at rank 6 when you kept 5. Too large, and the prompt fills with marginal passages: more tokens to pay for, more distraction, and models tend to use the middle of a long context less well (lost in the middle). Common values are 3 to 10 for a model’s context and 50 to 200 for a candidate pool that a reranker will cut down. The second number has its own name: candidate depth.
The gotcha: k is always filled
Similarity search has no built-in notion of “not relevant”, so a top-5 search returns five passages whether the corpus contains five good answers or none. An off-topic question gets five confident-looking results. Pair k with a relevance floor that drops weak matches, and treat an empty result as an answer (“the documents don’t cover this”) rather than a failure.
The opposite surprise exists too: filters, deduplication or a floor applied after the top k is chosen can return fewer than k. See metadata filtering.
In DocSlurp, limit on /v1/search accepts 1 to 100, and an omitted limit uses the project’s resultCount (8 by default).
In DocSlurp
In DocSlurp
limit on /v1/search takes 1 to 100; when omitted, the project default resultCount applies (8 unless changed). Chat accepts resultCount from 1 to 12 (core/docs/search-api.md, core/packages/shared/src/project.ts). The relevance floor can return fewer.