Skip to content

feat: make max query topk configurable#338

Open
Rm1n90 wants to merge 1 commit intoalibaba:mainfrom
Rm1n90:feat/configurable-max-query-topk
Open

feat: make max query topk configurable#338
Rm1n90 wants to merge 1 commit intoalibaba:mainfrom
Rm1n90:feat/configurable-max-query-topk

Conversation

@Rm1n90
Copy link
Copy Markdown

@Rm1n90 Rm1n90 commented Apr 14, 2026

Summary

  • Adds a max_query_topk parameter to zvec.init() so users can raise the hard topk ceiling (default 1024) when they accept the extra memory/latency tradeoff
  • Stores the configured limit in GlobalConfig and reads it in VectorQuery::validate() instead of using the hardcoded kMaxQueryTopk constant
  • Exposes the same config through the C API via zvec_config_data_{set,get}_max_query_topk()

Usage

import zvec

zvec.init(max_query_topk=4096)
results = collection.query(vq, topk=2048)  # now works
zvec_config_data_t *cfg = zvec_config_data_create();
zvec_config_data_set_max_query_topk(cfg, 4096);
zvec_initialize(cfg);

Files changed (7)

Layer File Change
C++ core src/include/zvec/db/config.h Add max_query_topk to ConfigData + accessor
C++ core src/db/common/config.cc Default value (1024) + validation
C++ core src/db/index/common/doc.cc Use configurable limit in VectorQuery::validate()
Python python/zvec/zvec.py New max_query_topk param with type/range validation
Python binding src/binding/python/model/common/python_config.cc Parse and validate from config dict
C API src/include/zvec/c_api.h Declare getter/setter
C API src/binding/c/c_api.cc Implement getter/setter

Test plan

  • Full build from source (macOS ARM64, Python 3.13)
  • Python test suite: 1009 passed, 54 skipped, 0 failures
  • Validated edge cases: float, negative, zero, bool, string all correctly rejected with clear error messages
  • Default behavior unchanged — limit stays 1024 unless explicitly overridden

🤖 Generated with Claude Code

The native engine enforces a hard topk ceiling of 1024 on
collection.query(). This adds a `max_query_topk` parameter to
zvec.init() so users can raise the limit when they accept the
extra memory/latency tradeoff.

Changes:
- Add `max_query_topk` to GlobalConfig::ConfigData with default 1024
- VectorQuery::validate() reads the limit from GlobalConfig instead
  of the hardcoded kMaxQueryTopk constant
- Expose the parameter in Python zvec.init() with type/range validation
- Parse and validate in the pybind11 config bridge
- Add C API getter/setter: zvec_config_data_{set,get}_max_query_topk()

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Apr 14, 2026

CLA assistant check
All committers have signed the CLA.

Copy link
Copy Markdown
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your free trial has ended. If you'd like to continue receiving code reviews, you can add a payment method here.

@github-actions github-actions bot assigned chinaux, Rm1n90, Cuiyus and zhourrr and unassigned chinaux, Cuiyus and zhourrr Apr 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants