Skip to content

Commit 0c36b15

Browse files
feat(vertexai): support shard_size in google_vertex_ai_index (#8293) (#15133)
Signed-off-by: Modular Magician <[email protected]>
1 parent 3f918ea commit 0c36b15

File tree

5 files changed

+45
-0
lines changed

5 files changed

+45
-0
lines changed

.changelog/8293.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
vertexai: supported`shard_size` in `google_vertex_ai_index`
3+
```

google/resource_vertex_ai_index_generated_test.go

+2
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ resource "google_vertex_ai_index" "index" {
8888
config {
8989
dimensions = 2
9090
approximate_neighbors_count = 150
91+
shard_size = "SHARD_SIZE_SMALL"
9192
distance_measure_type = "DOT_PRODUCT_DISTANCE"
9293
algorithm_config {
9394
tree_ah_config {
@@ -158,6 +159,7 @@ resource "google_vertex_ai_index" "index" {
158159
contents_delta_uri = "gs://${google_storage_bucket.bucket.name}/contents"
159160
config {
160161
dimensions = 2
162+
shard_size = "SHARD_SIZE_LARGE"
161163
distance_measure_type = "COSINE_DISTANCE"
162164
feature_norm_type = "UNIT_L2_NORM"
163165
algorithm_config {

google/resource_vertex_ai_index_test.go

+2
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ resource "google_vertex_ai_index" "index" {
9191
config {
9292
dimensions = 2
9393
approximate_neighbors_count = 150
94+
shard_size = "SHARD_SIZE_SMALL"
9495
distance_measure_type = "DOT_PRODUCT_DISTANCE"
9596
algorithm_config {
9697
tree_ah_config {
@@ -147,6 +148,7 @@ resource "google_vertex_ai_index" "index" {
147148
config {
148149
dimensions = 2
149150
approximate_neighbors_count = 150
151+
shard_size = "SHARD_SIZE_SMALL"
150152
distance_measure_type = "DOT_PRODUCT_DISTANCE"
151153
algorithm_config {
152154
tree_ah_config {

google/services/vertexai/resource_vertex_ai_index.go

+28
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,17 @@ Required if tree-AH algorithm is used.`,
165165
* NONE: No normalization type is specified.`,
166166
Default: "NONE",
167167
},
168+
"shard_size": {
169+
Type: schema.TypeString,
170+
Computed: true,
171+
Optional: true,
172+
ForceNew: true,
173+
Description: `Index data is split into equal parts to be processed. These are called "shards".
174+
The shard size must be specified when creating an index. The value must be one of the followings:
175+
* SHARD_SIZE_SMALL: Small (2GB)
176+
* SHARD_SIZE_MEDIUM: Medium (20GB)
177+
* SHARD_SIZE_LARGE: Large (50GB)`,
178+
},
168179
},
169180
},
170181
},
@@ -706,6 +717,8 @@ func flattenVertexAIIndexMetadataConfig(v interface{}, d *schema.ResourceData, c
706717
flattenVertexAIIndexMetadataConfigDimensions(original["dimensions"], d, config)
707718
transformed["approximate_neighbors_count"] =
708719
flattenVertexAIIndexMetadataConfigApproximateNeighborsCount(original["approximateNeighborsCount"], d, config)
720+
transformed["shard_size"] =
721+
flattenVertexAIIndexMetadataConfigShardSize(original["shardSize"], d, config)
709722
transformed["distance_measure_type"] =
710723
flattenVertexAIIndexMetadataConfigDistanceMeasureType(original["distanceMeasureType"], d, config)
711724
transformed["feature_norm_type"] =
@@ -748,6 +761,10 @@ func flattenVertexAIIndexMetadataConfigApproximateNeighborsCount(v interface{},
748761
return v // let terraform core handle it otherwise
749762
}
750763

764+
func flattenVertexAIIndexMetadataConfigShardSize(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
765+
return v
766+
}
767+
751768
func flattenVertexAIIndexMetadataConfigDistanceMeasureType(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
752769
return v
753770
}
@@ -983,6 +1000,13 @@ func expandVertexAIIndexMetadataConfig(v interface{}, d tpgresource.TerraformRes
9831000
transformed["approximateNeighborsCount"] = transformedApproximateNeighborsCount
9841001
}
9851002

1003+
transformedShardSize, err := expandVertexAIIndexMetadataConfigShardSize(original["shard_size"], d, config)
1004+
if err != nil {
1005+
return nil, err
1006+
} else if val := reflect.ValueOf(transformedShardSize); val.IsValid() && !tpgresource.IsEmptyValue(val) {
1007+
transformed["shardSize"] = transformedShardSize
1008+
}
1009+
9861010
transformedDistanceMeasureType, err := expandVertexAIIndexMetadataConfigDistanceMeasureType(original["distance_measure_type"], d, config)
9871011
if err != nil {
9881012
return nil, err
@@ -1015,6 +1039,10 @@ func expandVertexAIIndexMetadataConfigApproximateNeighborsCount(v interface{}, d
10151039
return v, nil
10161040
}
10171041

1042+
func expandVertexAIIndexMetadataConfigShardSize(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
1043+
return v, nil
1044+
}
1045+
10181046
func expandVertexAIIndexMetadataConfigDistanceMeasureType(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
10191047
return v, nil
10201048
}

website/docs/r/vertex_ai_index.html.markdown

+10
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ resource "google_vertex_ai_index" "index" {
5959
config {
6060
dimensions = 2
6161
approximate_neighbors_count = 150
62+
shard_size = "SHARD_SIZE_SMALL"
6263
distance_measure_type = "DOT_PRODUCT_DISTANCE"
6364
algorithm_config {
6465
tree_ah_config {
@@ -103,6 +104,7 @@ resource "google_vertex_ai_index" "index" {
103104
contents_delta_uri = "gs://${google_storage_bucket.bucket.name}/contents"
104105
config {
105106
dimensions = 2
107+
shard_size = "SHARD_SIZE_LARGE"
106108
distance_measure_type = "COSINE_DISTANCE"
107109
feature_norm_type = "UNIT_L2_NORM"
108110
algorithm_config {
@@ -189,6 +191,14 @@ The following arguments are supported:
189191
approximate search algorithm are reordered via a more expensive distance computation.
190192
Required if tree-AH algorithm is used.
191193

194+
* `shard_size` -
195+
(Optional)
196+
Index data is split into equal parts to be processed. These are called "shards".
197+
The shard size must be specified when creating an index. The value must be one of the followings:
198+
* SHARD_SIZE_SMALL: Small (2GB)
199+
* SHARD_SIZE_MEDIUM: Medium (20GB)
200+
* SHARD_SIZE_LARGE: Large (50GB)
201+
192202
* `distance_measure_type` -
193203
(Optional)
194204
The distance measure used in nearest neighbor search. The value must be one of the followings:

0 commit comments

Comments
 (0)