fix(python): validate numpy vector queries safely (#502)

This commit is contained in:
Hosni Belfeki
2026-06-22 10:57:51 +08:00
committed by GitHub
parent 7ca09fcf54
commit 56560b812b
2 changed files with 6 additions and 1 deletions
+5
View File
@@ -428,6 +428,11 @@ class TestQuery:
with pytest.raises(ValueError):
vq._validate()
def test_validate_fails_on_both_id_and_numpy_vector(self):
vq = Query(field_name="test", id="doc123", vector=np.array([0.1]))
with pytest.raises(ValueError, match="Cannot provide both id and vector"):
vq._validate()
class TestVectorQueryDeprecated:
def test_deprecation_warning(self):
+1 -1
View File
@@ -109,7 +109,7 @@ class Query:
def _validate(self) -> None:
if self.field_name is None:
raise ValueError("Field name cannot be empty")
if self.id and self.vector:
if self.has_id() and self.has_vector():
raise ValueError("Cannot provide both id and vector")
if self.has_fts() and (
self.has_vector() or self.has_id() or self.param is not None