From 04f2cd27d837df2c63b407832f5fa8ebe356e257 Mon Sep 17 00:00:00 2001 From: Lingyin Wu Date: Wed, 12 Jun 2024 10:28:15 -0700 Subject: [PATCH] feat: Add hybrid query example to vector search sample. FUTURE_COPYBARA_INTEGRATE_REVIEW=https://github.com/googleapis/python-aiplatform/pull/3932 from googleapis:release-please--branches--main 346f4c03f036a3a343b45723f0ba285fb5de2227 PiperOrigin-RevId: 642658354 --- .../vector_search_find_neighbors_sample.py | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/samples/model-builder/vector_search/vector_search_find_neighbors_sample.py b/samples/model-builder/vector_search/vector_search_find_neighbors_sample.py index 8afef4a82df..14154c83fff 100644 --- a/samples/model-builder/vector_search/vector_search_find_neighbors_sample.py +++ b/samples/model-builder/vector_search/vector_search_find_neighbors_sample.py @@ -55,5 +55,33 @@ def vector_search_find_neighbors( ) print(resp) + # Query hybrid datapoints, sparse-only datapoints, and dense-only datapoints. + hybrid_queries = [ + aiplatform.matching_engine.matching_engine_index_endpoint.HybridQuery( + dense_embedding=[1, 2, 3], + sparse_embedding_dimensions=[10, 20, 30], + sparse_embedding_values=[1.0, 1.0, 1.0], + rrf_ranking_alpha=0.5, + ), + aiplatform.matching_engine.matching_engine_index_endpoint.HybridQuery( + dense_embedding=[1, 2, 3], + sparse_embedding_dimensions=[10, 20, 30], + sparse_embedding_values=[0.1, 0.2, 0.3], + ), + aiplatform.matching_engine.matching_engine_index_endpoint.HybridQuery( + sparse_embedding_dimensions=[10, 20, 30], + sparse_embedding_values=[0.1, 0.2, 0.3], + ), + aiplatform.matching_engine.matching_engine_index_endpoint.HybridQuery( + dense_embedding=[1, 2, 3] + ), + ] + + hybrid_resp = my_index_endpoint.find_neighbors( + deployed_index_id=deployed_index_id, + num_neighbors=2, + return_full_datapoint=True, + queries=hybrid_queries) + print(hybrid_resp) # [END aiplatform_sdk_vector_search_find_neighbors_sample]