@@ -343,6 +343,116 @@ def test_upload_wrong_vectors():
343343 )
344344
345345
346+ def test_upsert_empty_dense_vector ():
347+ """Both clients must reject an empty dense vector on every write path.
348+
349+ An empty *sparse* vector, on the other hand, is legitimate and must stay accepted.
350+ """
351+ local_client = init_local ()
352+ remote_client = init_remote ()
353+
354+ vectors_config = {"text" : models .VectorParams (size = 2 , distance = models .Distance .COSINE )}
355+ sparse_vectors_config = {"text-sparse" : models .SparseVectorParams ()}
356+
357+ local_client .create_collection (
358+ collection_name = COLLECTION_NAME ,
359+ vectors_config = vectors_config ,
360+ sparse_vectors_config = sparse_vectors_config ,
361+ )
362+ if remote_client .collection_exists (collection_name = COLLECTION_NAME ):
363+ remote_client .delete_collection (collection_name = COLLECTION_NAME )
364+ remote_client .create_collection (
365+ collection_name = COLLECTION_NAME ,
366+ vectors_config = vectors_config ,
367+ sparse_vectors_config = sparse_vectors_config ,
368+ )
369+
370+ # a valid point to overwrite later
371+ valid_points = [models .PointStruct (id = 1 , vector = {"text" : [0.1 , 0.3 ]})]
372+ local_client .upsert (COLLECTION_NAME , valid_points )
373+ remote_client .upsert (COLLECTION_NAME , valid_points )
374+
375+ empty_points = [models .PointStruct (id = 2 , vector = {"text" : []})]
376+ overwrite_points = [models .PointStruct (id = 1 , vector = {"text" : []})]
377+ empty_batch = models .Batch (ids = [3 ], vectors = {"text" : [[]]})
378+
379+ for points in (empty_points , overwrite_points , empty_batch ):
380+ with pytest .raises (ValueError , match = "Dense vector must not be empty" ):
381+ local_client .upsert (COLLECTION_NAME , points )
382+
383+ with pytest .raises (qdrant_client .http .exceptions .UnexpectedResponse ):
384+ remote_client .upsert (COLLECTION_NAME , points )
385+
386+ empty_point_vectors = [models .PointVectors (id = 1 , vector = {"text" : []})]
387+ with pytest .raises (ValueError , match = "Dense vector must not be empty" ):
388+ local_client .update_vectors (COLLECTION_NAME , points = empty_point_vectors )
389+
390+ with pytest .raises (qdrant_client .http .exceptions .UnexpectedResponse ):
391+ remote_client .update_vectors (COLLECTION_NAME , points = empty_point_vectors )
392+
393+ # an empty sparse vector is valid input for both clients
394+ empty_sparse_points = [
395+ models .PointStruct (
396+ id = 4 , vector = {"text-sparse" : models .SparseVector (indices = [], values = [])}
397+ )
398+ ]
399+ local_client .upsert (COLLECTION_NAME , empty_sparse_points )
400+ remote_client .upsert (COLLECTION_NAME , empty_sparse_points , wait = True )
401+
402+ compare_collections (local_client , remote_client , UPLOAD_NUM_VECTORS )
403+
404+
405+ def test_rejected_empty_vector_update_leaves_point_untouched ():
406+ """A rejected update_vectors request must not change the point in any way.
407+
408+ Regression: validation used to run after `deleted_per_vector` was cleared, so rejecting
409+ an empty vector still made an absent vector's placeholder visible to search, and a valid
410+ vector supplied alongside the rejected one was written anyway.
411+ """
412+ local_client = init_local ()
413+ remote_client = init_remote ()
414+
415+ vectors_config = {
416+ "a" : models .VectorParams (size = 4 , distance = models .Distance .COSINE ),
417+ "b" : models .VectorParams (size = 4 , distance = models .Distance .COSINE ),
418+ }
419+ local_client .create_collection (COLLECTION_NAME , vectors_config = vectors_config )
420+ if remote_client .collection_exists (collection_name = COLLECTION_NAME ):
421+ remote_client .delete_collection (collection_name = COLLECTION_NAME )
422+ remote_client .create_collection (COLLECTION_NAME , vectors_config = vectors_config )
423+
424+ orig = [1.0 , 0.0 , 0.0 , 0.0 ]
425+ other = [0.0 , 1.0 , 0.0 , 0.0 ]
426+
427+ # point 1 has no "a" at all, so "a" is backed by a placeholder marked deleted
428+ absent_a = [models .PointStruct (id = 1 , vector = {"b" : orig })]
429+ local_client .upsert (COLLECTION_NAME , absent_a )
430+ remote_client .upsert (COLLECTION_NAME , absent_a , wait = True )
431+
432+ empty_a = [models .PointVectors (id = 1 , vector = {"a" : []})]
433+ with pytest .raises (ValueError , match = "Dense vector must not be empty" ):
434+ local_client .update_vectors (COLLECTION_NAME , points = empty_a )
435+ with pytest .raises (qdrant_client .http .exceptions .UnexpectedResponse ):
436+ remote_client .update_vectors (COLLECTION_NAME , points = empty_a , wait = True )
437+
438+ # "a" must still be absent for both clients, and must not be searchable
439+ for client in (local_client , remote_client ):
440+ assert "a" not in client .retrieve (COLLECTION_NAME , ids = [1 ], with_vectors = True )[0 ].vector
441+ assert client .query_points (COLLECTION_NAME , query = orig , using = "a" , limit = 5 ).points == []
442+
443+ # a valid vector supplied next to the rejected one must not be written either
444+ mixed = [models .PointVectors (id = 1 , vector = {"b" : other , "a" : []})]
445+ with pytest .raises (ValueError , match = "Dense vector must not be empty" ):
446+ local_client .update_vectors (COLLECTION_NAME , points = mixed )
447+ with pytest .raises (qdrant_client .http .exceptions .UnexpectedResponse ):
448+ remote_client .update_vectors (COLLECTION_NAME , points = mixed , wait = True )
449+
450+ for client in (local_client , remote_client ):
451+ assert client .retrieve (COLLECTION_NAME , ids = [1 ], with_vectors = True )[0 ].vector ["b" ] == orig
452+
453+ compare_collections (local_client , remote_client , UPLOAD_NUM_VECTORS )
454+
455+
346456def test_upsert_without_vector_name ():
347457 local_client = init_local ()
348458 remote_client = init_remote ()
0 commit comments