在 VPC 网络中部署和管理索引端点

将索引部署到端点包括以下三项任务:

  1. 创建 IndexEndpoint(如有需要)或重复使用现有的 IndexEndpoint。
  2. 获取 IndexEndpoint ID。
  3. 将索引部署到 IndexEndpoint。

在 VPC 网络中创建 IndexEndpoint

如果要将 Index 部署到现有 IndexEndpoint,则可以跳过此步骤。

在使用索引响应在线向量匹配查询之前,您必须将 Index 部署到 VPC 网络对等互连网络中的 IndexEndpoint。第一步是创建 IndexEndpoint。您可以将多个索引部署到共享同一 VPC 网络的 IndexEndpoint。

gcloud

以下示例使用 gcloud ai index-endpoints create 命令。

在使用下面的命令数据之前,请先进行以下替换:

  • INDEX_ENDPOINT_NAME:索引端点的显示名称。
  • VPC_NETWORK_NAME:索引端点应与之建立对等互连的 Google Compute Engine 网络的名称。
  • LOCATION:您使用 Agent Platform 的区域。
  • PROJECT_ID:您的 Google Cloud 项目 ID。

执行以下命令:

Linux、macOS 或 Cloud Shell

gcloud ai index-endpoints create \
    --display-name=INDEX_ENDPOINT_NAME \
    --network=VPC_NETWORK_NAME \
    --region=LOCATION \
    --project=PROJECT_ID

Windows (PowerShell)

gcloud ai index-endpoints create `
    --display-name=INDEX_ENDPOINT_NAME `
    --network=VPC_NETWORK_NAME `
    --region=LOCATION `
    --project=PROJECT_ID

Windows (cmd.exe)

gcloud ai index-endpoints create ^
    --display-name=INDEX_ENDPOINT_NAME ^
    --network=VPC_NETWORK_NAME ^
    --region=LOCATION ^
    --project=PROJECT_ID

您应该会收到类似如下所示的响应:

The Google Cloud CLI tool might take a few minutes to create the IndexEndpoint.

REST

在使用任何请求数据之前,请先进行以下替换:

  • INDEX_ENDPOINT_NAME:索引端点的显示名称。
  • VPC_NETWORK_NAME:索引端点应与之建立对等互连的 Google Compute Engine 网络的名称。
  • LOCATION:您使用 Agent Platform 的区域。
  • PROJECT_ID:您的 Google Cloud 项目 ID。
  • PROJECT_NUMBER:自动生成的项目编号。

HTTP 方法和网址:

POST https://LOCATION-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/indexEndpoints

请求 JSON 正文:

{
  "display_name": "INDEX_ENDPOINT_NAME",
  "network": "VPC_NETWORK_NAME"
}

如需发送您的请求,请展开以下选项之一:

您应该收到类似以下内容的 JSON 响应:

{
  "name": "projects/PROJECT_NUMBER/locations/LOCATION/indexEndpoints/INDEX_ENDPOINT_ID/operations/OPERATION_ID",
  "metadata": {
    "@type": "type.googleapis.com/google.cloud.aiplatform.v1.CreateIndexEndpointOperationMetadata",
    "genericMetadata": {
      "createTime": "2022-01-13T04:09:56.641107Z",
      "updateTime": "2022-01-13T04:09:56.641107Z"
    }
  }
}

您可以轮询操作状态,直到响应包含 "done": true。

Terraform

以下示例使用 vertex_ai_index_endpoint Terraform 资源创建索引端点。

如需了解如何应用或移除 Terraform 配置,请参阅基本 Terraform 命令。

resource "google_vertex_ai_index_endpoint" "default" {
  display_name = "sample-endpoint"
  description  = "A sample index endpoint within a VPC network"
  region       = "us-central1"
  network      = "projects/${data.google_project.project.number}/global/networks/${google_compute_network.default.name}"
  depends_on = [
    google_service_networking_connection.default
  ]
}

resource "google_service_networking_connection" "default" {
  network                 = google_compute_network.default.id
  service                 = "servicenetworking.googleapis.com"
  reserved_peering_ranges = [google_compute_global_address.default.name]
  # Workaround to allow `terraform destroy`, see https://github.com/hashicorp/terraform-provider-google/issues/18729
  deletion_policy = "ABANDON"
}

resource "google_compute_global_address" "default" {
  name          = "sample-address"
  purpose       = "VPC_PEERING"
  address_type  = "INTERNAL"
  prefix_length = 16
  network       = google_compute_network.default.id
}

resource "google_compute_network" "default" {
  name = "sample-network"
}

data "google_project" "project" {}

# Cloud Storage bucket name must be unique
resource "random_id" "default" {
  byte_length = 8
}

# Create a Cloud Storage bucket
resource "google_storage_bucket" "bucket" {
  name                        = "vertex-ai-index-bucket-${random_id.default.hex}"
  location                    =