|
| 1 | +/** |
| 2 | + * Copyright 2024 Google LLC |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | + |
| 18 | +# [START aiplatform_deploy_index_endpoint_sample] |
| 19 | +provider "google" { |
| 20 | + region = "us-central1" |
| 21 | +} |
| 22 | + |
| 23 | +resource "google_vertex_ai_index_endpoint_deployed_index" "default" { |
| 24 | + depends_on = [google_vertex_ai_index_endpoint.default] |
| 25 | + index_endpoint = google_vertex_ai_index_endpoint.default.id |
| 26 | + index = google_vertex_ai_index.default.id |
| 27 | + deployed_index_id = "deployed_index_id" |
| 28 | +} |
| 29 | + |
| 30 | +resource "google_vertex_ai_index_endpoint" "default" { |
| 31 | + display_name = "sample-endpoint" |
| 32 | + description = "A sample index endpoint with a public endpoint" |
| 33 | + region = "us-central1" |
| 34 | + public_endpoint_enabled = true |
| 35 | +} |
| 36 | + |
| 37 | +# Cloud Storage bucket name must be unique |
| 38 | +resource "random_id" "default" { |
| 39 | + byte_length = 8 |
| 40 | +} |
| 41 | + |
| 42 | +# Create a Cloud Storage bucket |
| 43 | +resource "google_storage_bucket" "bucket" { |
| 44 | + name = "vertex-ai-index-bucket-${random_id.default.hex}" |
| 45 | + location = "us-central1" |
| 46 | + uniform_bucket_level_access = true |
| 47 | +} |
| 48 | + |
| 49 | +# Create index content |
| 50 | +resource "google_storage_bucket_object" "data" { |
| 51 | + name = "contents/data.json" |
| 52 | + bucket = google_storage_bucket.bucket.name |
| 53 | + content = <<EOF |
| 54 | +{"id": "42", "embedding": [0.5, 1.0], "restricts": [{"namespace": "class", "allow": ["cat", "pet"]},{"namespace": "category", "allow": ["feline"]}]} |
| 55 | +{"id": "43", "embedding": [0.6, 1.0], "restricts": [{"namespace": "class", "allow": ["dog", "pet"]},{"namespace": "category", "allow": ["canine"]}]} |
| 56 | +EOF |
| 57 | +} |
| 58 | + |
| 59 | +resource "google_vertex_ai_index" "default" { |
| 60 | + region = "us-central1" |
| 61 | + display_name = "sample-index-batch-update" |
| 62 | + description = "A sample index for batch update" |
| 63 | + labels = { |
| 64 | + foo = "bar" |
| 65 | + } |
| 66 | + |
| 67 | + metadata { |
| 68 | + contents_delta_uri = "gs://${google_storage_bucket.bucket.name}/contents" |
| 69 | + config { |
| 70 | + dimensions = 2 |
| 71 | + approximate_neighbors_count = 150 |
| 72 | + distance_measure_type = "DOT_PRODUCT_DISTANCE" |
| 73 | + algorithm_config { |
| 74 | + tree_ah_config { |
| 75 | + leaf_node_embedding_count = 500 |
| 76 | + leaf_nodes_to_search_percent = 7 |
| 77 | + } |
| 78 | + } |
| 79 | + } |
| 80 | + } |
| 81 | + index_update_method = "BATCH_UPDATE" |
| 82 | + |
| 83 | + timeouts { |
| 84 | + create = "2h" |
| 85 | + update = "1h" |
| 86 | + } |
| 87 | +} |
| 88 | +# [END aiplatform_deploy_index_endpoint_sample] |
0 commit comments