@@ -533,6 +533,68 @@ def test_vector_query_collection_group(distance_measure, expected_distance):
533533 )
534534
535535
536+ def test_vector_query_list_as_query_vector ():
537+ # Create a minimal fake GAPIC.
538+ firestore_api = mock .Mock (spec = ["run_query" ])
539+ client = make_client ()
540+ client ._firestore_api_internal = firestore_api
541+
542+ # Make a **real** collection reference as parent.
543+ parent = client .collection ("dee" )
544+ query = make_query (parent )
545+ parent_path , expected_prefix = parent ._parent_info ()
546+
547+ data = {"snooze" : 10 , "embedding" : Vector ([1.0 , 2.0 , 3.0 ])}
548+ response_pb1 = _make_query_response (
549+ name = "{}/test_doc" .format (expected_prefix ), data = data
550+ )
551+ response_pb2 = _make_query_response (
552+ name = "{}/test_doc" .format (expected_prefix ), data = data
553+ )
554+
555+ kwargs = make_retry_timeout_kwargs (retry = None , timeout = None )
556+
557+ # Execute the vector query and check the response.
558+ firestore_api .run_query .return_value = iter ([response_pb1 , response_pb2 ])
559+
560+ vector_query = query .where ("snooze" , "==" , 10 ).find_nearest (
561+ vector_field = "embedding" ,
562+ query_vector = [1.0 , 2.0 , 3.0 ],
563+ distance_measure = DistanceMeasure .EUCLIDEAN ,
564+ limit = 5 ,
565+ )
566+
567+ returned = vector_query .get (transaction = _transaction (client ), ** kwargs )
568+ assert isinstance (returned , list )
569+ assert len (returned ) == 2
570+ assert returned [0 ].to_dict () == data
571+
572+ expected_pb = _expected_pb (
573+ parent = parent ,
574+ vector_field = "embedding" ,
575+ vector = Vector ([1.0 , 2.0 , 3.0 ]),
576+ distance_type = StructuredQuery .FindNearest .DistanceMeasure .EUCLIDEAN ,
577+ limit = 5 ,
578+ )
579+ expected_pb .where = StructuredQuery .Filter (
580+ field_filter = StructuredQuery .FieldFilter (
581+ field = StructuredQuery .FieldReference (field_path = "snooze" ),
582+ op = StructuredQuery .FieldFilter .Operator .EQUAL ,
583+ value = encode_value (10 ),
584+ )
585+ )
586+
587+ firestore_api .run_query .assert_called_once_with (
588+ request = {
589+ "parent" : parent_path ,
590+ "structured_query" : expected_pb ,
591+ "transaction" : _TXN_ID ,
592+ },
593+ metadata = client ._rpc_metadata ,
594+ ** kwargs ,
595+ )
596+
597+
536598def test_query_stream_multiple_empty_response_in_stream ():
537599 from google .cloud .firestore_v1 import stream_generator
538600
0 commit comments