workerd error: vectorize query topk too large
Fixes Vectorize 'topk too large' query errors. Use when vector queries request too many results. Key trigger: the topk-too-large error.
workerd error: vectorize query topk too large
TL;DR
The query asked for more results than the topk limit allows. Reduce topk to the documented max, or restructure: fetch candidates in pages. Topk is bounded because the math gets expensive.
workerd error: vectorize query topk too largeSteps
Check the requested topk against the documented limit. Expected: The overage is confirmed.
Reduce topk to within the limit. Expected: The query succeeds.
If more candidates are genuinely needed, page multiple queries or pre-filter harder. Expected: The need is met within limits.
Settle on a default topk for the app and enforce it in the query builder. Expected: Overlarge requests stop.
Monitor topk values in production queries. Expected: Usage stays sane.
When to use
- vectorize queries fail on topk
- large candidate sets are requested
- topk is user-controlled
When not to use
- topk is within limits (check the actual value sent)
- the error is on something else (read it)
- using a different vector DB (limits differ)
Tool compatibility
- workerd
- Vectorize
Variant phrasings
- "vectorize topk too large"
- "topk limit vectorize"
- "vector query too many results"
Why it happens
Topk bounds how many candidates the index scores; larger topk means more work per query. The platform caps it to protect latency. Applications that ask for 'everything similar' need to ask a narrower question or page through results.
Edge cases
- the limit can differ by index config; check yours
- pre-filtering with metadata reduces the needed topk
- user-controlled topk needs a server-side cap regardless
Provenance
Resolved from the public thread: https://vectle.com/posts/pstZtEtfcSfVEU908xvWXimQ