Content-Length: 596486 | pFad | https://github.com/googleapis/python-aiplatform/commit/c0e7acc27e67ef1a951bb4bd97f489164dda14f9

48 feat: Add FeatureNormType to `MatchingEngineIndexConfig`. · googleapis/python-aiplatform@c0e7acc · GitHub
Skip to content

Commit c0e7acc

Browse files
vertex-sdk-botcopybara-github
authored andcommitted
feat: Add FeatureNormType to MatchingEngineIndexConfig.
PiperOrigin-RevId: 626348332
1 parent c21b7eb commit c0e7acc

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed

google/cloud/aiplatform/matching_engine/matching_engine_index.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,9 @@ def create_tree_ah_index(
434434
encryption_spec_key_name: Optional[str] = None,
435435
create_request_timeout: Optional[float] = None,
436436
shard_size: Optional[str] = None,
437+
feature_norm_type: Optional[
438+
matching_engine_index_config.FeatureNormType
439+
] = None,
437440
) -> "MatchingEngineIndex":
438441
"""Creates a MatchingEngineIndex resource that uses the tree-AH algorithm.
439442
@@ -477,6 +480,8 @@ def create_tree_ah_index(
477480
range 1-100, inclusive. The default value is 10 (means 10%) if not set.
478481
distance_measure_type (matching_engine_index_config.DistanceMeasureType):
479482
Optional. The distance measure used in nearest neighbor search.
483+
feature_norm_type (matching_engine_index_config.FeatureNormType):
484+
Optional. The feature norm type used in nearest neighbor search.
480485
description (str):
481486
Optional. The description of the Index.
482487
labels (Dict[str, str]):
@@ -552,6 +557,7 @@ def create_tree_ah_index(
552557
algorithm_config=algorithm_config,
553558
approximate_neighbors_count=approximate_neighbors_count,
554559
distance_measure_type=distance_measure_type,
560+
feature_norm_type=feature_norm_type,
555561
shard_size=shard_size,
556562
)
557563

@@ -580,6 +586,9 @@ def create_brute_force_index(
580586
distance_measure_type: Optional[
581587
matching_engine_index_config.DistanceMeasureType
582588
] = None,
589+
feature_norm_type: Optional[
590+
matching_engine_index_config.FeatureNormType
591+
] = None,
583592
description: Optional[str] = None,
584593
labels: Optional[Dict[str, str]] = None,
585594
project: Optional[str] = None,
@@ -623,6 +632,8 @@ def create_brute_force_index(
623632
Required. The number of dimensions of the input vectors.
624633
distance_measure_type (matching_engine_index_config.DistanceMeasureType):
625634
Optional. The distance measure used in nearest neighbor search.
635+
feature_norm_type (matching_engine_index_config.FeatureNormType):
636+
Optional. The feature norm type used in nearest neighbor search.
626637
description (str):
627638
Optional. The description of the Index.
628639
labels (Dict[str, str]):
@@ -695,6 +706,7 @@ def create_brute_force_index(
695706
dimensions=dimensions,
696707
algorithm_config=algorithm_config,
697708
distance_measure_type=distance_measure_type,
709+
feature_norm_type=feature_norm_type,
698710
shard_size=shard_size,
699711
)
700712

google/cloud/aiplatform/matching_engine/matching_engine_index_config.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,12 +125,15 @@ class MatchingEngineIndexConfig:
125125
independently.
126126
distance_measure_type (DistanceMeasureType):
127127
Optional. The distance measure used in nearest neighbor search.
128+
feature_norm_type (FeatureNormType):
129+
Optional. The feature norm type used in nearest neighbor search.
128130
"""
129131

130132
dimensions: int
131133
algorithm_config: AlgorithmConfig
132134
approximate_neighbors_count: Optional[int] = None
133135
distance_measure_type: Optional[DistanceMeasureType] = None
136+
feature_norm_type: Optional[FeatureNormType] = None
134137
shard_size: Optional[str] = None
135138

136139
def as_dict(self) -> Dict[str, Any]:
@@ -144,6 +147,7 @@ def as_dict(self) -> Dict[str, Any]:
144147
"algorithmConfig": self.algorithm_config.as_dict(),
145148
"approximateNeighborsCount": self.approximate_neighbors_count,
146149
"distanceMeasureType": self.distance_measure_type,
150+
"featureNormType": self.feature_norm_type,
147151
"shardSize": self.shard_size,
148152
}
149153
return res

tests/unit/aiplatform/test_matching_engine_index.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
)
5454
_TEST_CONTENTS_DELTA_URI = "gs://contents"
5555
_TEST_INDEX_DISTANCE_MEASURE_TYPE = "SQUARED_L2_DISTANCE"
56+
_TEST_INDEX_FEATURE_NORM_TYPE = "UNIT_L2_NORM"
5657

5758
_TEST_CONTENTS_DELTA_URI_UPDATE = "gs://contents_update"
5859
_TEST_IS_COMPLETE_OVERWRITE_UPDATE = True
@@ -374,6 +375,7 @@ def test_create_tree_ah_index(
374375
dimensions=_TEST_INDEX_CONFIG_DIMENSIONS,
375376
approximate_neighbors_count=_TEST_INDEX_APPROXIMATE_NEIGHBORS_COUNT,
376377
distance_measure_type=_TEST_INDEX_DISTANCE_MEASURE_TYPE,
378+
feature_norm_type=_TEST_INDEX_FEATURE_NORM_TYPE,
377379
leaf_node_embedding_count=_TEST_LEAF_NODE_EMBEDDING_COUNT,
378380
leaf_nodes_to_search_percent=_TEST_LEAF_NODES_TO_SEARCH_PERCENT,
379381
description=_TEST_INDEX_DESCRIPTION,
@@ -403,6 +405,7 @@ def test_create_tree_ah_index(
403405
"dimensions": _TEST_INDEX_CONFIG_DIMENSIONS,
404406
"approximateNeighborsCount": _TEST_INDEX_APPROXIMATE_NEIGHBORS_COUNT,
405407
"distanceMeasureType": _TEST_INDEX_DISTANCE_MEASURE_TYPE,
408+
"featureNormType": _TEST_INDEX_FEATURE_NORM_TYPE,
406409
"shardSize": shard_size,
407410
},
408411
"contentsDeltaUri": _TEST_CONTENTS_DELTA_URI,
@@ -447,6 +450,7 @@ def test_create_tree_ah_index_with_empty_index(
447450
dimensions=_TEST_INDEX_CONFIG_DIMENSIONS,
448451
approximate_neighbors_count=_TEST_INDEX_APPROXIMATE_NEIGHBORS_COUNT,
449452
distance_measure_type=_TEST_INDEX_DISTANCE_MEASURE_TYPE,
453+
feature_norm_type=_TEST_INDEX_FEATURE_NORM_TYPE,
450454
leaf_node_embedding_count=_TEST_LEAF_NODE_EMBEDDING_COUNT,
451455
leaf_nodes_to_search_percent=_TEST_LEAF_NODES_TO_SEARCH_PERCENT,
452456
description=_TEST_INDEX_DESCRIPTION,
@@ -476,6 +480,7 @@ def test_create_tree_ah_index_with_empty_index(
476480
"dimensions": _TEST_INDEX_CONFIG_DIMENSIONS,
477481
"approximateNeighborsCount": _TEST_INDEX_APPROXIMATE_NEIGHBORS_COUNT,
478482
"distanceMeasureType": _TEST_INDEX_DISTANCE_MEASURE_TYPE,
483+
"featureNormType": _TEST_INDEX_FEATURE_NORM_TYPE,
479484
"shardSize": shard_size,
480485
},
481486
},
@@ -506,6 +511,7 @@ def test_create_tree_ah_index_backward_compatibility(self, create_index_mock):
506511
dimensions=_TEST_INDEX_CONFIG_DIMENSIONS,
507512
approximate_neighbors_count=_TEST_INDEX_APPROXIMATE_NEIGHBORS_COUNT,
508513
distance_measure_type=_TEST_INDEX_DISTANCE_MEASURE_TYPE,
514+
feature_norm_type=_TEST_INDEX_FEATURE_NORM_TYPE,
509515
leaf_node_embedding_count=_TEST_LEAF_NODE_EMBEDDING_COUNT,
510516
leaf_nodes_to_search_percent=_TEST_LEAF_NODES_TO_SEARCH_PERCENT,
511517
description=_TEST_INDEX_DESCRIPTION,
@@ -527,6 +533,7 @@ def test_create_tree_ah_index_backward_compatibility(self, create_index_mock):
527533
"dimensions": _TEST_INDEX_CONFIG_DIMENSIONS,
528534
"approximateNeighborsCount": _TEST_INDEX_APPROXIMATE_NEIGHBORS_COUNT,
529535
"distanceMeasureType": _TEST_INDEX_DISTANCE_MEASURE_TYPE,
536+
"featureNormType": _TEST_INDEX_FEATURE_NORM_TYPE,
530537
"shardSize": None,
531538
},
532539
"contentsDeltaUri": _TEST_CONTENTS_DELTA_URI,
@@ -564,6 +571,7 @@ def test_create_brute_force_index(
564571
contents_delta_uri=_TEST_CONTENTS_DELTA_URI,
565572
dimensions=_TEST_INDEX_CONFIG_DIMENSIONS,
566573
distance_measure_type=_TEST_INDEX_DISTANCE_MEASURE_TYPE,
574+
feature_norm_type=_TEST_INDEX_FEATURE_NORM_TYPE,
567575
description=_TEST_INDEX_DESCRIPTION,
568576
labels=_TEST_LABELS,
569577
sync=sync,
@@ -586,6 +594,7 @@ def test_create_brute_force_index(
586594
"dimensions": _TEST_INDEX_CONFIG_DIMENSIONS,
587595
"approximateNeighborsCount": None,
588596
"distanceMeasureType": _TEST_INDEX_DISTANCE_MEASURE_TYPE,
597+
"featureNormType": _TEST_INDEX_FEATURE_NORM_TYPE,
589598
"shardSize": shard_size,
590599
},
591600
"contentsDeltaUri": _TEST_CONTENTS_DELTA_URI,
@@ -627,6 +636,7 @@ def test_create_brute_force_index_with_empty_index(
627636
display_name=_TEST_INDEX_DISPLAY_NAME,
628637
dimensions=_TEST_INDEX_CONFIG_DIMENSIONS,
629638
distance_measure_type=_TEST_INDEX_DISTANCE_MEASURE_TYPE,
639+
feature_norm_type=_TEST_INDEX_FEATURE_NORM_TYPE,
630640
description=_TEST_INDEX_DESCRIPTION,
631641
labels=_TEST_LABELS,
632642
sync=sync,
@@ -648,6 +658,7 @@ def test_create_brute_force_index_with_empty_index(
648658
"dimensions": _TEST_INDEX_CONFIG_DIMENSIONS,
649659
"approximateNeighborsCount": None,
650660
"distanceMeasureType": _TEST_INDEX_DISTANCE_MEASURE_TYPE,
661+
"featureNormType": _TEST_INDEX_FEATURE_NORM_TYPE,
651662
"shardSize": None,
652663
},
653664
},
@@ -677,6 +688,7 @@ def test_create_brute_force_index_backward_compatibility(self, create_index_mock
677688
contents_delta_uri=_TEST_CONTENTS_DELTA_URI,
678689
dimensions=_TEST_INDEX_CONFIG_DIMENSIONS,
679690
distance_measure_type=_TEST_INDEX_DISTANCE_MEASURE_TYPE,
691+
feature_norm_type=_TEST_INDEX_FEATURE_NORM_TYPE,
680692
description=_TEST_INDEX_DESCRIPTION,
681693
labels=_TEST_LABELS,
682694
)
@@ -691,6 +703,7 @@ def test_create_brute_force_index_backward_compatibility(self, create_index_mock
691703
"dimensions": _TEST_INDEX_CONFIG_DIMENSIONS,
692704
"approximateNeighborsCount": None,
693705
"distanceMeasureType": _TEST_INDEX_DISTANCE_MEASURE_TYPE,
706+
"featureNormType": _TEST_INDEX_FEATURE_NORM_TYPE,
694707
"shardSize": None,
695708
},
696709
"contentsDeltaUri": _TEST_CONTENTS_DELTA_URI,

0 commit comments

Comments
 (0)








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: https://github.com/googleapis/python-aiplatform/commit/c0e7acc27e67ef1a951bb4bd97f489164dda14f9

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy