fix(python): validate query topk#616
Open
HosniBelfeki wants to merge 2 commits into
Open
Conversation
There was a problem hiding this comment.
Pull request overview
Adds Python-side validation for Collection.query(topk=...) to reject invalid values early (before query context construction / native execution), aligning query() behavior with existing group-by limit validation.
Changes:
- Validate
topkvia_require_positive_integer(topk, "topk")at the start ofCollection.query(). - Add a unit test to ensure invalid
topkvalues raise a clearValueErrorand do not call the executor.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| python/zvec/model/collection.py | Adds _require_positive_integer check for topk in Collection.query() before building QueryContext. |
| python/tests/test_collection.py | Adds parametrized test covering invalid topk values and asserts the executor is not invoked. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Validate
Collection.query(topk=...)before building the query context.The Python wrapper already has
_require_positive_integer()for group-by limits, but plainquery()passed invalidtopkvalues through to the executor/native layer. This change rejects0, negative values,None, and booleans with a clear Python-sideValueError.Tests
python -m ruff check python\zvec\model\collection.py python\tests\test_collection.pypython -m py_compile python\zvec\model\collection.py python\tests\test_collection.py