Skip to content

Commit 67e593b

Browse files
lingyinwcopybara-github
authored andcommitted
feat: Add support for low_level_batch_size in match() for MatchingEngineIndexEndpoint private query.
PiperOrigin-RevId: 599483250
1 parent 1d9bd23 commit 67e593b

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

google/cloud/aiplatform/matching_engine/matching_engine_index_endpoint.py

+9
Original file line numberDiff line numberDiff line change
@@ -1436,6 +1436,7 @@ def match(
14361436
approx_num_neighbors: Optional[int] = None,
14371437
fraction_leaf_nodes_to_search_override: Optional[float] = None,
14381438
return_full_datapoint: bool = False,
1439+
low_level_batch_size: int = 0,
14391440
) -> List[List[MatchNeighbor]]:
14401441
"""Retrieves nearest neighbors for the given embedding queries on the
14411442
specified deployed index for private endpoint only.
@@ -1472,6 +1473,13 @@ def match(
14721473
vector values and of the nearest neighbors are returned.
14731474
Note that returning full datapoint will significantly increase the
14741475
latency and cost of the query.
1476+
low_level_batch_size (int):
1477+
Optional. Selects the optimal batch size to use for low-level
1478+
batching. Queries within each low level batch are executed
1479+
sequentially while low level batches are executed in parallel.
1480+
This field is optional, defaults to 0 if not set. A non-positive
1481+
number disables low level batching, i.e. all queries are
1482+
executed sequentially.
14751483
14761484
Returns:
14771485
List[List[MatchNeighbor]] - A list of nearest neighbors for each query.
@@ -1487,6 +1495,7 @@ def match(
14871495
match_service_pb2.BatchMatchRequest.BatchMatchRequestPerIndex()
14881496
)
14891497
batch_request_for_index.deployed_index_id = deployed_index_id
1498+
batch_request_for_index.low_level_batch_size = low_level_batch_size
14901499

14911500
# Preprocess restricts to be used for each request
14921501
restricts = []

tests/unit/aiplatform/test_matching_engine_index_endpoint.py

+3
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,7 @@
244244
_TEST_APPROX_NUM_NEIGHBORS = 2
245245
_TEST_FRACTION_LEAF_NODES_TO_SEARCH_OVERRIDE = 0.8
246246
_TEST_RETURN_FULL_DATAPOINT = True
247+
_TEST_LOW_LEVEL_BATCH_SIZE = 3
247248
_TEST_ENCRYPTION_SPEC_KEY_NAME = "kms_key_name"
248249
_TEST_PROJECT_ALLOWLIST = ["project-1", "project-2"]
249250
_TEST_PRIVATE_SERVICE_CONNECT_IP_ADDRESS = "10.128.0.5"
@@ -1061,12 +1062,14 @@ def test_private_index_endpoint_match_queries(
10611062
approx_num_neighbors=_TEST_APPROX_NUM_NEIGHBORS,
10621063
fraction_leaf_nodes_to_search_override=_TEST_FRACTION_LEAF_NODES_TO_SEARCH_OVERRIDE,
10631064
return_full_datapoint=_TEST_RETURN_FULL_DATAPOINT,
1065+
low_level_batch_size=_TEST_LOW_LEVEL_BATCH_SIZE,
10641066
)
10651067

10661068
batch_request = match_service_pb2.BatchMatchRequest(
10671069
requests=[
10681070
match_service_pb2.BatchMatchRequest.BatchMatchRequestPerIndex(
10691071
deployed_index_id=_TEST_DEPLOYED_INDEX_ID,
1072+
low_level_batch_size=_TEST_LOW_LEVEL_BATCH_SIZE,
10701073
requests=[
10711074
match_service_pb2.MatchRequest(
10721075
num_neighbors=_TEST_NUM_NEIGHBOURS,

0 commit comments

Comments
 (0)