Skip to content

Commit

Permalink
fix: do not allow insert unnamed vectors into a collection with named…
Browse files Browse the repository at this point in the history
… vectors
  • Loading branch information
joein committed Jan 12, 2024
1 parent 5c08c95 commit 1fa9c7b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
6 changes: 6 additions & 0 deletions qdrant_client/local/local_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -1073,6 +1073,12 @@ def _upsert_point(self, point: models.PointStruct) -> None:
updated_sparse_vectors[vector_name] = sort(vector)
# update point.vector with the modified values after iteration
point.vector.update(updated_sparse_vectors)
else:
vector_names = list(self.vectors.keys())
if vector_names != [""]:
raise ValueError(
f"Wrong input: Unnamed vectors are not allowed when a collection has named vectors: {vector_names}"
)

if point.id in self.ids:
self._update_point(point)
Expand Down
16 changes: 14 additions & 2 deletions tests/congruence_tests/test_updates.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ def test_upload_wrong_vectors():
local_client = init_local()
remote_client = init_remote()

vector_size = 5
vector_size = 2
wrong_vectors_collection = "test_collection"
vectors_config = {
"text": models.VectorParams(size=vector_size, distance=models.Distance.COSINE)
Expand All @@ -315,7 +315,7 @@ def test_upload_wrong_vectors():
)
remote_client.recreate_collection(
collection_name=wrong_vectors_collection,
vectors_config=models.VectorParams(size=vector_size, distance=models.Distance.COSINE),
vectors_config=vectors_config,
sparse_vectors_config=sparse_vectors_config,
)

Expand Down Expand Up @@ -358,3 +358,15 @@ def test_upload_wrong_vectors():
local_client.upload_records(
wrong_vectors_collection, records=[models.Record(id=3, vector=dense_vector)]
)

unnamed_vector = [0.1, 0.3]
with pytest.raises(qdrant_client.http.exceptions.UnexpectedResponse):
remote_client.upsert(
wrong_vectors_collection,
points=[models.PointStruct(id=1, vector=unnamed_vector)],
)
with pytest.raises(ValueError):
local_client.upsert(
wrong_vectors_collection,
points=[models.PointStruct(id=1, vector=unnamed_vector)],
)

0 comments on commit 1fa9c7b

Please sign in to comment.