...
1/**
2 * Copyright 2022 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```hcl
18resource "google_storage_bucket" "bucket" {
19 name = "vertex-ai-index-test"
20 location = "us-central1"
21 uniform_bucket_level_access = true
22}
23
24# The sample data comes from the following link:
25# https://cloud.google.com/vertex-ai/docs/matching-engine/filtering#specify-namespaces-tokens
26resource "google_storage_bucket_object" "data" {
27 name = "contents/data.json"
28 bucket = google_storage_bucket.bucket.name
29 content = <<EOF
30{"id": "42", "embedding": [0.5, 1.0], "restricts": [{"namespace": "class", "allow": ["cat", "pet"]},{"namespace": "category", "allow": ["feline"]}]}
31{"id": "43", "embedding": [0.6, 1.0], "restricts": [{"namespace": "class", "allow": ["dog", "pet"]},{"namespace": "category", "allow": ["canine"]}]}
32EOF
33}
34
35resource "google_vertex_ai_index" "index" {
36 labels = {
37 foo = "bar"
38 }
39 region = "us-central1"
40 display_name = "test-index"
41 description = "index for test"
42 metadata {
43 contents_delta_uri = "gs://${google_storage_bucket.bucket.name}/contents"
44 config {
45 dimensions = 2
46 approximate_neighbors_count = 150
47 distance_measure_type = "DOT_PRODUCT_DISTANCE"
48 algorithm_config {
49 tree_ah_config {
50 leaf_node_embedding_count = 500
51 leaf_nodes_to_search_percent = 7
52 }
53 }
54 }
55 }
56 index_update_method = "BATCH_UPDATE"
57}
58```
View as plain text