Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions python/tests/test_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
# limitations under the License.
from __future__ import annotations

from unittest.mock import MagicMock

import pytest
import zvec
from zvec import (
Expand Down Expand Up @@ -907,6 +909,17 @@ def test_collection_query_with_output_fields(
assert len(doc.field_names()) == 2
assert set(doc.field_names()) == {"id", "name"}

@pytest.mark.parametrize("topk", [0, -1, None, True])
def test_collection_query_rejects_invalid_topk(self, topk):
collection = Collection.__new__(Collection)
collection._querier = MagicMock()
collection._obj = MagicMock()

with pytest.raises(ValueError, match="topk must be a positive integer"):
collection.query(Query(field_name="dense", vector=[0.1]), topk=topk)

collection._querier.execute.assert_not_called()

def test_collection_query_with_topk(
self, collection_with_multiple_docs: Collection
):
Expand Down
1 change: 1 addition & 0 deletions python/zvec/model/collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,7 @@ def query(
... output_fields=["title", "url"]
... )
"""
_require_positive_integer(topk, "topk")
if vectors is not None:
warnings.warn(
"The 'vectors' parameter is deprecated and will be removed in a future version. "
Expand Down
Loading