פריסה וניהול של נקודות קצה של אינדקס ברשת VPC

פריסת אינדקס בנקודת קצה כוללת את שלוש המשימות הבאות:

  1. יוצרים IndexEndpoint חדש לפי הצורך, או משתמשים מחדש ב-IndexEndpoint קיים.
  2. מאתרים את המזהה של IndexEndpoint.
  3. פורסים את האינדקס ב-IndexEndpoint.

יוצרים IndexEndpoint ברשת ה-VPC

אם אתם פורסים Index ב-IndexEndpoint קיים, אתם יכולים לדלג על השלב הזה.

כדי להשתמש באינדקס להצגת שאילתות אונליין להתאמת וקטורים, צריך לפרוס את Index ב-IndexEndpoint בתוך רשת ה-VPC Peering. השלב הראשון הוא ליצור IndexEndpoint. אפשר לפרוס יותר מאינדקס אחד ב-IndexEndpoint שמשתף את אותה רשת VPC.

gcloud

בדוגמה הבאה משתמשים בפקודה gcloud ai index-endpoints create.

לפני השימוש בנתוני הפקודה הבאים, צריך להחליף את הנתונים הבאים:

  • ‫INDEX_ENDPOINT_NAME: השם המוצג של נקודת הקצה של האינדקס.
  • ‫VPC_NETWORK_NAME: השם של רשת Compute Engine שאליה צריך לקשר את נקודת הקצה של האינדקס.
  • ‫LOCATION: האזור שבו אתם משתמשים ב-Agent Platform.
  • ‫PROJECT_ID: מזהה הפרויקט ב- Google Cloud .

מריצים את הפקודה הבאה:

‫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: השם של רשת Compute Engine שאליה צריך לקשר את נקודת הקצה של האינדקס.
  • ‫LOCATION: האזור שבו אתם משתמשים ב-Agent Platform.
  • ‫PROJECT_ID: מזהה הפרויקט ב- Google Cloud .
  • ‫PROJECT_NUMBER: מספר הפרויקט שנוצר באופן אוטומטי.

ה-method של ה-HTTP וכתובת ה-URL:

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

בדוגמה הבאה נעשה שימוש במשאב Terraform‏ vertex_ai_index_endpoint כדי ליצור נקודת קצה של אינדקס.

כדי ללמוד איך להחיל הגדרות ב-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                    = "us-central1"
  uniform_bucket_level_access = true
}

# Create index content
resource "google_storage_bucket_object" "data" {
  name    = "contents/data.json"
  bucket  = google_storage_bucket.bucket.name
  content = <<EOF
{"id": "42", "embedding": [0.5, 1.0], "restricts": [{"namespace": "class", "allow": ["cat", "pet"]},{"namespace": "category", "allow": ["feline"]}]}
{"id": "43", "embedding": [0.6, 1.0], "restricts": [{"namespace": "class", "allow": ["dog", "pet"]},{"namespace": "category", "allow": ["canine"]}]}
EOF
}

resource "google_vertex_ai_index" "default" {
  region       = "us-central1"
  display_name = "sample-index-batch-update"
  description  = "A sample index for batch update"
  labels = {
    foo = "bar"
  }

  metadata {
    contents_delta_uri = "gs://${google_storage_bucket.bucket.name}/contents"
    config {
      dimensions                  = 2
      approximate_neighbors_count = 150
      distance_measure_type       = "DOT_PRODUCT_DISTANCE"
      algorithm_config {
        tree_ah_config {
          leaf_node_embedding_count    = 500
          leaf_nodes_to_search_percent = 7
        }
      }
    }
  }
  index_update_method = "BATCH_UPDATE"

  timeouts {
    create = "2h"
    update = "1h"
  }
}

Python

במאמר התקנת Vertex AI SDK ל-Python מוסבר איך להתקין או לעדכן את Vertex AI SDK ל-Python. מידע נוסף מופיע ב מאמרי העזרה של ה-API מבוסס-Python.

def vector_search_create_index_endpoint_vpc(
    project: str, location: str, display_name: str, network: str
) -> aiplatform.MatchingEngineIndexEndpoint:
    """Create a vector search index endpoint within a VPC network.

    Args:
        project (str): Required. Project ID
        location (str): Required. The region name
        display_name (str): Required. The index endpoint display name
        network(str): Required. The VPC network name, in the format of
            projects/{project number}/global/networks/{network name}.

    Returns:
        aiplatform.MatchingEngineIndexEndpoint - The created index endpoint.
    """
    # Initialize the Vertex AI client
    aiplatform.init(project=project, location=location)

    # Create Index Endpoint
    index_endpoint = aiplatform.MatchingEngineIndexEndpoint.create(
        display_name=display_name,
        network=network,
        description="Matching Engine VPC Index Endpoint",
    )

    return index_endpoint

המסוף

כך יוצרים נקודת קצה של אינדקס.

  1. בקטע Agent Platform במסוף Google Cloud , נכנסים לחלק Deploy and Use. בוחרים באפשרות חיפוש וקטורי.

    כניסה לדף Vector Search

  2. תוצג רשימה של האינדקסים הפעילים.
  3. בחלק העליון של הדף, לוחצים על הכרטיסייה Index endpoints. נקודות הקצה של האינדקס מוצגות.
  4. לוחצים על Create new index endpoint. החלונית Create a new index endpoint נפתחת.
  5. מזינים שם לתצוגה של נקודת הקצה של האינדקס.
  6. בשדה Region, בוחרים אזור מהתפריט הנפתח.
  7. בשדה Access, בוחרים באפשרות Private.
  8. מזינים את פרטי רשת ה-VPC המקושרת. מזינים את השם המלא של רשת Compute Engine שאליה רוצים לקשר את המשימה. הפורמט צריך להיות projects/{project_num}/global/networks/{network_id}
  9. לוחצים על יצירה.

פריסת אינדקס

gcloud

בדוגמה הזו משתמשים בפקודה gcloud ai index-endpoints deploy-index.

לפני השימוש בנתוני הפקודה הבאים, צריך להחליף את הנתונים הבאים:

  • ‫INDEX_ENDPOINT_ID: המזהה של נקודת הקצה של האינדקס.
  • ‫DEPLOYED_INDEX_ID: מחרוזת שהמשתמש ציין כדי לזהות באופן ייחודי את האינדקס שנפרס. הוא חייב להתחיל באות ויכול להכיל רק אותיות, מספרים או קווים תחתונים. הנחיות לגבי הפורמט מפורטות במאמר DeployedIndex.id.
  • DEPLOYED_INDEX_ENDPOINT_NAME: השם המוצג של נקודת הקצה של האינדקס שנפרס.
  • ‫INDEX_ID: מזהה האינדקס.
  • ‫LOCATION: האזור שבו אתם משתמשים ב-Agent Platform.
  • ‫PROJECT_ID: מזהה הפרויקט ב- Google Cloud .

מריצים את הפקודה הבאה:

‫Linux,‏ macOS או Cloud Shell

gcloud ai index-endpoints deploy-index INDEX_ENDPOINT_ID \
    --deployed-index-id=DEPLOYED_INDEX_ID \
    --display-name=DEPLOYED_INDEX_ENDPOINT_NAME \
    --index=INDEX_ID \
    --region=LOCATION \
    --project=PROJECT_ID

‏Windows (PowerShell)

gcloud ai index-endpoints deploy-index INDEX_ENDPOINT_ID `
    --deployed-index-id=DEPLOYED_INDEX_ID `
    --display-name=DEPLOYED_INDEX_ENDPOINT_NAME `
    --index=INDEX_ID `
    --region=LOCATION `
    --project=PROJECT_ID

Windows‏ (cmd.exe)

gcloud ai index-endpoints deploy-index INDEX_ENDPOINT_ID ^
    --deployed-index-id=DEPLOYED_INDEX_ID ^
    --display-name=DEPLOYED_INDEX_ENDPOINT_NAME ^
    --index=INDEX_ID ^
    --region=LOCATION ^
    --project=PROJECT_ID

אמורים לקבל תגובה שדומה לזו:

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

REST

לפני שמשתמשים בנתוני הבקשה, צריך להחליף את הנתונים הבאים:

  • ‫INDEX_ENDPOINT_ID: המזהה של נקודת הקצה של האינדקס.
  • ‫DEPLOYED_INDEX_ID: מחרוזת שהמשתמש ציין כדי לזהות באופן ייחודי את האינדקס שנפרס. הוא חייב להתחיל באות ויכול להכיל רק אותיות, מספרים או קווים תחתונים. הנחיות לגבי הפורמט מפורטות במאמר DeployedIndex.id.
  • DEPLOYED_INDEX_ENDPOINT_NAME: השם המוצג של נקודת הקצה של האינדקס שנפרס.
  • ‫INDEX_ID: מזהה האינדקס.
  • ‫LOCATION: האזור שבו אתם משתמשים ב-Agent Platform.
  • ‫PROJECT_ID: מזהה הפרויקט ב- Google Cloud .
  • ‫PROJECT_NUMBER: מספר הפרויקט שנוצר באופן אוטומטי.

ה-method של ה-HTTP וכתובת ה-URL:

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

תוכן בקשת JSON:

{
 "deployedIndex": {
   "id": "DEPLOYED_INDEX_ID",
   "index": "projects/PROJECT_ID/locations/LOCATION/indexes/INDEX_ID",
   "displayName": "DEPLOYED_INDEX_ENDPOINT_NAME"
 }
}

כדי לשלוח את הבקשה צריך להרחיב אחת מהאפשרויות הבאות:

אתם אמורים לקבל תגובת JSON שדומה לזו:

{
 "name": "projects/PROJECT_NUMBER/locations/LOCATION/indexEndpoints/INDEX_ENDPOINT_ID/operations/OPERATION_ID",
 "metadata": {
   "@type": "type.googleapis.com/google.cloud.aiplatform.v1.DeployIndexOperationMetadata",
   "genericMetadata": {
     "createTime": "2022-10-19T17:53:16.502088Z",
     "updateTime": "2022-10-19T17:53:16.502088Z"
   },
   "deployedIndexId": "DEPLOYED_INDEX_ID"
 }
}

Terraform

בדוגמה הבאה נעשה שימוש במשאב Terraform‏ vertex_ai_index_endpoint_deployed_index כדי ליצור נקודת קצה פרוסה של אינדקס.

כדי ללמוד איך להחיל הגדרות ב-Terraform או להסיר אותן, ראו פקודות בסיסיות ב-Terraform.

provider "google" {
  region = "us-central1"
}

resource "google_vertex_ai_index_endpoint_deployed_index" "default" {
  depends_on        = [google_vertex_ai_index_endpoint.default]
  index_endpoint    = google_vertex_ai_index_endpoint.default.id
  index             = google_vertex_ai_index.default.id
  deployed_index_id = "deployed_index_for_vpc"
}

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                    = "us-central1"
  uniform_bucket_level_access = true
}

# Create index content
resource "google_storage_bucket_object" "data" {
  name    = "contents/data.json"
  bucket  = google_storage_bucket.bucket.name
  content = <<EOF
{"id": "42", "embedding": [0.5, 1.0], "restricts": [{"namespace": "class", "allow": ["cat", "pet"]},{"namespace": "category", "allow": ["feline"]}]}
{"id": "43", "embedding": [0.6, 1.0], "restricts": [{"namespace": "class", "allow": ["dog", "pet"]},{"namespace": "category", "allow": ["canine"]}]}
EOF
}

resource "google_vertex_ai_index" "default" {
  region       = "us-central1"
  display_name = "sample-index-batch-update"
  description  = "A sample index for batch update"
  labels = {
    foo = "bar"
  }

  metadata {
    contents_delta_uri = "gs://${google_storage_bucket.bucket.name}/contents"
    config {
      dimensions                  = 2
      approximate_neighbors_count = 150
      distance_measure_type       = "DOT_PRODUCT_DISTANCE"
      algorithm_config {
        tree_ah_config {
          leaf_node_embedding_count    = 500
          leaf_nodes_to_search_percent = 7
        }
      }
    }
  }
  index_update_method = "BATCH_UPDATE"

  timeouts {
    create = "2h"
    update = "1h"
  }
}

Python

במאמר התקנת Vertex AI SDK ל-Python מוסבר איך להתקין או לעדכן את Vertex AI SDK ל-Python. מידע נוסף מופיע ב מאמרי העזרה של ה-API מבוסס-Python.

def vector_search_deploy_index(
    project: str,
    location: str,
    index_name: str,
    index_endpoint_name: str,
    deployed_index_id: str,
) -> None:
    """Deploy a vector search index to a vector search index endpoint.

    Args:
        project (str): Required. Project ID
        location (str): Required. The region name
        index_name (str): Required. The index to update. A fully-qualified index
          resource name or a index ID.  Example:
          "projects/123/locations/us-central1/indexes/my_index_id" or
          "my_index_id".
        index_endpoint_name (str): Required. Index endpoint to deploy the index
          to.
        deployed_index_id (str): Required. The user specified ID of the
          DeployedIndex.
    """
    # Initialize the Vertex AI client
    aiplatform.init(project=project, location=location)

    # Create the index instance from an existing index
    index = aiplatform.MatchingEngineIndex(index_name=index_name)

    # Create the index endpoint instance from an existing endpoint.
    index_endpoint = aiplatform.MatchingEngineIndexEndpoint(
        index_endpoint_name=index_endpoint_name
    )

    # Deploy Index to Endpoint
    index_endpoint = index_endpoint.deploy_index(
        index=index, deployed_index_id=deployed_index_id
    )

    print(index_endpoint.deployed_indexes)

המסוף

כדי לפרוס את האינדקס בנקודת קצה, צריך לפעול לפי ההוראות הבאות.

  1. בקטע Agent Platform במסוף Google Cloud , נכנסים לחלק Deploy and Use. בוחרים באפשרות חיפוש וקטורי.

    כניסה לדף Vector Search

  2. תוצג רשימה של האינדקסים הפעילים.
  3. בוחרים את שם האינדקס שרוצים לפרוס. דף פרטי האינדקס נפתח.
  4. בדף פרטי האינדקס, לוחצים על Deploy to endpoint. החלונית לפריסת האינדקס תיפתח.
  5. מזינים שם לתצוגה – השם הזה משמש כמזהה ואי אפשר לעדכן אותו.
  6. בתפריט הנפתח Endpoint, בוחרים את נקודת הקצה שאליה רוצים לפרוס את האינדקס. הערה: נקודת הקצה לא זמינה אם האינדקס כבר נפרס בה.
  7. אופציונלי: בשדה Machine type, בוחרים באפשרות standard או high-memory.
  8. זה שינוי אופציונלי. בוחרים באפשרות Enable autoscaling כדי לשנות באופן אוטומטי את מספר הצמתים בהתאם לדרישות של עומסי העבודה. מספר ברירת המחדל של הרפליקות הוא 2 אם ההתאמה האוטומטית לעומס מושבתת.
  9. לוחצים על Deploy כדי לפרוס את האינדקס בנקודת הקצה. הערה: הפריסה נמשכת כ-30 דקות.

הפעלת התאמה אוטומטית לעומס (autoscaling)

בחיפוש וקטורי יש תמיכה בהתאמה אוטומטית לעומס, שמאפשרת לשנות באופן אוטומטי את מספר הצמתים בהתאם לדרישות של עומסי העבודה. כשהביקוש גבוה, צמתים נוספים למאגר הצמתים, עד לגודל המקסימלי שהגדרתם. כשהביקוש נמוך, מאגר הצמתים מצטמצם לגודל המינימלי שהגדרתם. כדי לבדוק את הצמתים שבהם אתם משתמשים בפועל ואת השינויים, אתם יכולים לעקוב אחרי הרפליקות הנוכחיות.

כדי להפעיל התאמה אוטומטית לעומס, מציינים את maxReplicaCount ואת minReplicaCount כשפורסים את האינדקס:

gcloud

בדוגמה הבאה משתמשים בפקודה gcloud ai index-endpoints deploy-index.

לפני השימוש בנתוני הפקודה הבאים, צריך להחליף את הנתונים הבאים:

  • ‫INDEX_ENDPOINT_ID: המזהה של נקודת הקצה של האינדקס.
  • ‫DEPLOYED_INDEX_ID: מחרוזת שהמשתמש ציין כדי לזהות באופן ייחודי את האינדקס שנפרס. הוא חייב להתחיל באות ויכול להכיל רק אותיות, מספרים או קווים תחתונים. הנחיות לגבי הפורמט מפורטות במאמר DeployedIndex.id.
  • ‫DEPLOYED_INDEX_NAME: השם המוצג של האינדקס שנפרס.
  • ‫INDEX_ID: מזהה האינדקס.
  • ‫MIN_REPLICA_COUNT: המספר המינימלי של רפליקות של מכונות שהאינדקס שנפרס תמיד ייפרס בהן. אם מציינים ערך, הוא צריך להיות שווה ל-1 או גדול ממנו.
  • ‫MAX_REPLICA_COUNT: המספר המקסימלי של רפליקות של מכונות שאפשר לפרוס עליהן את האינדקס שנפרס.
  • ‫LOCATION: האזור שבו אתם משתמשים ב-Agent Platform.
  • ‫PROJECT_ID: מזהה הפרויקט ב- Google Cloud .

מריצים את הפקודה הבאה:

‫Linux,‏ macOS או Cloud Shell

gcloud ai index-endpoints deploy-index INDEX_ENDPOINT_ID \
    --deployed-index-id=DEPLOYED_INDEX_ID \
    --display-name=DEPLOYED_INDEX_NAME \
    --index=INDEX_ID \
    --min-replica-count=MIN_REPLICA_COUNT \
    --max-replica-count=MAX_REPLICA_COUNT \
    --region=LOCATION \
    --project=PROJECT_ID

‏Windows (PowerShell)

gcloud ai index-endpoints deploy-index INDEX_ENDPOINT_ID `
    --deployed-index-id=DEPLOYED_INDEX_ID `
    --display-name=DEPLOYED_INDEX_NAME `
    --index=INDEX_ID `
    --min-replica-count=MIN_REPLICA_COUNT `
    --max-replica-count=MAX_REPLICA_COUNT `
    --region=LOCATION `
    --project=PROJECT_ID

Windows‏ (cmd.exe)

gcloud ai index-endpoints deploy-index INDEX_ENDPOINT_ID ^
    --deployed-index-id=DEPLOYED_INDEX_ID ^
    --display-name=DEPLOYED_INDEX_NAME ^
    --index=INDEX_ID ^
    --min-replica-count=MIN_REPLICA_COUNT ^
    --max-replica-count=MAX_REPLICA_COUNT ^
    --region=LOCATION ^
    --project=PROJECT_ID

REST

לפני שמשתמשים בנתוני הבקשה, צריך להחליף את הנתונים הבאים:

  • ‫INDEX_ENDPOINT_ID: המזהה של נקודת הקצה של האינדקס.
  • ‫DEPLOYED_INDEX_ID: מחרוזת שהמשתמש ציין כדי לזהות באופן ייחודי את האינדקס שנפרס. הוא חייב להתחיל באות ויכול להכיל רק אותיות, מספרים או קווים תחתונים. הנחיות לגבי הפורמט מפורטות במאמר DeployedIndex.id.
  • ‫DEPLOYED_INDEX_NAME: השם המוצג של האינדקס שנפרס.
  • ‫INDEX_ID: מזהה האינדקס.
  • ‫MIN_REPLICA_COUNT: המספר המינימלי של רפליקות של מכונות שהאינדקס שנפרס תמיד ייפרס בהן. אם מציינים ערך, הוא צריך להיות שווה ל-1 או גדול ממנו.
  • ‫MAX_REPLICA_COUNT: המספר המקסימלי של רפליקות של מכונות שאפשר לפרוס עליהן את האינדקס שנפרס.
  • ‫LOCATION: האזור שבו אתם משתמשים ב-Agent Platform.
  • ‫PROJECT_ID: מזהה הפרויקט ב- Google Cloud .
  • ‫PROJECT_NUMBER: מספר הפרויקט שנוצר באופן אוטומטי.

ה-method של ה-HTTP וכתובת ה-URL:

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

תוכן בקשת JSON:

{
 "deployedIndex": {
   "id": "DEPLOYED_INDEX_ID",
   "index": "projects/PROJECT_NUMBER/locations/LOCATION/indexes/INDEX_ID",
   "displayName": "DEPLOYED_INDEX_NAME",
   "automaticResources": {
     "minReplicaCount": MIN_REPLICA_COUNT,
     "maxReplicaCount": MAX_REPLICA_COUNT
   }
 }
}

כדי לשלוח את הבקשה צריך להרחיב אחת מהאפשרויות הבאות:

אתם אמורים לקבל תגובת JSON שדומה לזו:

{
 "name": "projects/PROJECT_NUMBER/locations/LOCATION/indexEndpoints/INDEX_ENDPOINT_ID/operations/OPERATION_ID",
 "metadata": {
   "@type": "type.googleapis.com/google.cloud.aiplatform.v1.DeployIndexOperationMetadata",
   "genericMetadata": {
     "createTime": "2023-10-19T17:53:16.502088Z",
     "updateTime": "2023-10-19T17:53:16.502088Z"
   },
   "deployedIndexId": "DEPLOYED_INDEX_ID"
 }
}

Python

במאמר התקנת Vertex AI SDK ל-Python מוסבר איך להתקין או לעדכן את Vertex AI SDK ל-Python. מידע נוסף מופיע ב מאמרי העזרה של ה-API מבוסס-Python.

def vector_search_deploy_autoscaling_index(
    project: str,
    location: str,
    index_name: str,
    index_endpoint_name: str,
    deployed_index_id: str,
    min_replica_count: int,
    max_replica_count: int,
) -> None:
    """Deploy a vector search index to a vector search index endpoint.

    Args:
        project (str): Required. Project ID
        location (str): Required. The region name
        index_name (str): Required. The index to update. A fully-qualified index
          resource name or a index ID.  Example:
          "projects/123/locations/us-central1/indexes/my_index_id" or
          "my_index_id".
        index_endpoint_name (str): Required. Index endpoint to deploy the index
          to.
        deployed_index_id (str): Required. The user specified ID of the
          DeployedIndex.
        min_replica_count (int): Required. The minimum number of replicas to
          deploy.
        max_replica_count (int): Required. The maximum number of replicas to
          deploy.
    """
    # Initialize the Vertex AI client
    aiplatform.init(project=project, location=location)

    # Create the index instance from an existing index
    index = aiplatform.MatchingEngineIndex(index_name=index_name)

    # Create the index endpoint instance from an existing endpoint.
    index_endpoint = aiplatform.MatchingEngineIndexEndpoint(
        index_endpoint_name=index_endpoint_name
    )

    # Deploy Index to Endpoint. Specifying min and max replica counts will
    # enable autoscaling.
    index_endpoint.deploy_index(
        index=index,
        deployed_index_id=deployed_index_id,
        min_replica_count=min_replica_count,
        max_replica_count=max_replica_count,
    )

המסוף

אפשר להפעיל התאמה אוטומטית לעומס רק מהמסוף במהלך פריסת האינדקס.

  1. בקטע Agent Platform במסוף Google Cloud , נכנסים לחלק Deploy and Use. בוחרים באפשרות חיפוש וקטורי.

    כניסה לדף Vector Search

  2. תוצג רשימה של האינדקסים הפעילים.
  3. בוחרים את שם האינדקס שרוצים לפרוס. דף פרטי האינדקס נפתח.
  4. בדף פרטי האינדקס, לוחצים על Deploy to endpoint. החלונית לפריסת האינדקס תיפתח.
  5. מזינים שם לתצוגה – השם הזה משמש כמזהה ואי אפשר לעדכן אותו.
  6. בתפריט הנפתח Endpoint, בוחרים את נקודת הקצה שאליה רוצים לפרוס את האינדקס. הערה: נקודת הקצה לא זמינה אם האינדקס כבר נפרס בה.
  7. אופציונלי: בשדה Machine type, בוחרים באפשרות standard או high-memory.
  8. זה שינוי אופציונלי. בוחרים באפשרות Enable autoscaling כדי לשנות באופן אוטומטי את מספר הצמתים בהתאם לדרישות של עומסי העבודה. מספר ברירת המחדל של הרפליקות הוא 2 אם ההתאמה האוטומטית לעומס מושבתת.
  • אם גם minReplicaCount וגם maxReplicaCount לא מוגדרים, הם מוגדרים כ-2 כברירת מחדל.
  • אם רק maxReplicaCount מוגדר, minReplicaCount מוגדר כ-2 כברירת מחדל.
  • אם רק minReplicaCount מוגדר, maxReplicaCount מוגדר להיות שווה ל-minReplicaCount.

שינוי של DeployedIndex

אתם יכולים להשתמש ב-API של MutateDeployedIndex כדי לעדכן את משאבי הפריסה (לדוגמה, minReplicaCount ו-maxReplicaCount) של אינדקס שכבר נפרס.

  • המשתמשים לא יכולים לשנות את machineType אחרי פריסת האינדקס.
  • אם לא מציינים את maxReplicaCount בבקשה, DeployedIndex ימשיך להשתמש ב-maxReplicaCount הקיים.

gcloud

בדוגמה הבאה השתמשנו בפקודה gcloud ai index-endpoints mutate-deployed-index.

לפני השימוש בנתוני הפקודה הבאים, צריך להחליף את הנתונים הבאים:

  • ‫INDEX_ENDPOINT_ID: המזהה של נקודת הקצה של האינדקס.
  • ‫DEPLOYED_INDEX_ID: מחרוזת שהמשתמש ציין כדי לזהות באופן ייחודי את האינדקס שנפרס. הוא חייב להתחיל באות ויכול להכיל רק אותיות, מספרים או קווים תחתונים. הנחיות לגבי הפורמט מפורטות במאמר DeployedIndex.id.
  • ‫MIN_REPLICA_COUNT: המספר המינימלי של רפליקות של מכונות שהאינדקס שנפרס תמיד ייפרס בהן. אם מציינים ערך, הוא צריך להיות שווה ל-1 או גדול ממנו.
  • ‫MAX_REPLICA_COUNT: המספר המקסימלי של רפליקות של מכונות שאפשר לפרוס עליהן את האינדקס שנפרס.
  • ‫LOCATION: האזור שבו אתם משתמשים ב-Agent Platform.
  • ‫PROJECT_ID: מזהה הפרויקט ב- Google Cloud .

מריצים את הפקודה הבאה:

‫Linux,‏ macOS או Cloud Shell

gcloud ai index-endpoints mutate-deployed-index INDEX_ENDPOINT_ID \
    --deployed-index-id=DEPLOYED_INDEX_ID \
    --min-replica-count=MIN_REPLICA_COUNT \
    --max-replica-count=MAX_REPLICA_COUNT \
    --region=LOCATION \
    --project=PROJECT_ID

‏Windows (PowerShell)

gcloud ai index-endpoints mutate-deployed-index INDEX_ENDPOINT_ID `
    --deployed-index-id=DEPLOYED_INDEX_ID `
    --min-replica-count=MIN_REPLICA_COUNT `
    --max-replica-count=MAX_REPLICA_COUNT `
    --region=LOCATION `
    --project=PROJECT_ID

Windows‏ (cmd.exe)

gcloud ai index-endpoints mutate-deployed-index INDEX_ENDPOINT_ID ^
    --deployed-index-id=DEPLOYED_INDEX_ID ^
    --min-replica-count=MIN_REPLICA_COUNT ^
    --max-replica-count=MAX_REPLICA_COUNT ^
    --region=LOCATION ^
    --project=PROJECT_ID

REST

לפני שמשתמשים בנתוני הבקשה, צריך להחליף את הנתונים הבאים:

  • ‫INDEX_ENDPOINT_ID: המזהה של נקודת הקצה של האינדקס.
  • ‫DEPLOYED_INDEX_ID: מחרוזת שהמשתמש ציין כדי לזהות באופן ייחודי את האינדקס שנפרס. הוא חייב להתחיל באות ויכול להכיל רק אותיות, מספרים או קווים תחתונים. הנחיות לגבי הפורמט מפורטות במאמר DeployedIndex.id.
  • ‫MIN_REPLICA_COUNT: המספר המינימלי של רפליקות של מכונות שהאינדקס שנפרס תמיד ייפרס בהן. אם מציינים ערך, הוא צריך להיות שווה ל-1 או גדול ממנו.
  • ‫MAX_REPLICA_COUNT: המספר המקסימלי של רפליקות של מכונות שאפשר לפרוס עליהן את האינדקס שנפרס.
  • ‫LOCATION: האזור שבו אתם משתמשים ב-Agent Platform.
  • ‫PROJECT_ID: מזהה הפרויקט ב- Google Cloud .
  • ‫PROJECT_NUMBER: מספר הפרויקט שנוצר באופן אוטומטי.

ה-method של ה-HTTP וכתובת ה-URL:

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

תוכן בקשת JSON:

{
  "deployedIndex": {
    "id": "DEPLOYED_INDEX_ID",
    "index": "projects/PROJECT_ID/locations/LOCATION/indexes/INDEX_ID",
    "displayName": "DEPLOYED_INDEX_NAME",
    "min_replica_count": "MIN_REPLICA_COUNT",
    "max_replica_count": "MAX_REPLICA_COUNT"
  }
}

כדי לשלוח את הבקשה צריך להרחיב אחת מהאפשרויות הבאות:

אתם אמורים לקבל תגובת JSON שדומה לזו:

{
"name": "projects/PROJECT_NUMBER/locations/LOCATION/indexEndpoints/INDEX_ENDPOINT_ID/operations/OPERATION_ID",
"metadata": {
  "@type": "type.googleapis.com/google.cloud.aiplatform.v1.DeployIndexOperationMetadata",
  "genericMetadata": {
    "createTime": "2020-10-19T17:53:16.502088Z",
    "updateTime": "2020-10-19T17:53:16.502088Z"
  },
  "deployedIndexId": "DEPLOYED_INDEX_ID"
}
}

Terraform

כדי ללמוד איך להחיל הגדרות ב-Terraform או להסיר אותן, ראו פקודות בסיסיות ב-Terraform. למידע נוסף, ראו את מאמרי העזרה לספקים של Terraform.

provider "google" {
  region = "us-central1"
}

resource "google_vertex_ai_index_endpoint_deployed_index" "default" {
  depends_on        = [google_vertex_ai_index_endpoint.default]
  index_endpoint    = google_vertex_ai_index_endpoint.default.id
  index             = google_vertex_ai_index.default.id
  deployed_index_id = "deployed_index_for_mutate_vpc"
  # This example assumes the deployed index endpoint's resources configuration
  # differs from the values specified below. Terraform will mutate the deployed
  # index endpoint's resource configuration to match.
  automatic_resources {
    min_replica_count = 3
    max_replica_count = 5
  }
}

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                    = "us-central1"
  uniform_bucket_level_access = true
}

# Create index content
resource "google_storage_bucket_object" "data" {
  name    = "contents/data.json"
  bucket  = google_storage_bucket.bucket.name
  content = <<EOF
{"id": "42", "embedding": [0.5, 1.0], "restricts": [{"namespace": "class", "allow": ["cat", "pet"]},{"namespace": "category", "allow": ["feline"]}]}
{"id": "43", "embedding": [0.6, 1.0], "restricts": [{"namespace": "class", "allow": ["dog", "pet"]},{"namespace": "category", "allow": ["canine"]}]}
EOF
}

resource "google_vertex_ai_index" "default" {
  region       = "us-central1"
  display_name = "sample-index-batch-update"
  description  = "A sample index for batch update"
  labels = {
    foo = "bar"
  }

  metadata {
    contents_delta_uri = "gs://${google_storage_bucket.bucket.name}/contents"
    config {
      dimensions                  = 2
      approximate_neighbors_count = 150
      distance_measure_type       = "DOT_PRODUCT_DISTANCE"
      algorithm_config {
        tree_ah_config {
          leaf_node_embedding_count    = 500
          leaf_nodes_to_search_percent = 7
        }
      }
    }
  }
  index_update_method = "BATCH_UPDATE"

  timeouts {
    create = "2h"
    update = "1h"
  }
}

Python

במאמר התקנת Vertex AI SDK ל-Python מוסבר איך להתקין או לעדכן את Vertex AI SDK ל-Python. מידע נוסף מופיע ב מאמרי העזרה של ה-API מבוסס-Python.

def vector_search_mutate_deployed_index(
    project: str,
    location: str,
    index_endpoint_name: str,
    deployed_index_id: str,
    min_replica_count: int,
    max_replica_count: int,
) -> None:
    """Mutate the deployment resources of an already deployed index.

    Args:
        project (str): Required. Project ID
        location (str): Required. The region name
        index_endpoint_name (str): Required. Index endpoint to run the query
          against.
        deployed_index_id (str): Required. The ID of the DeployedIndex to run
          the queries against.
        min_replica_count (int): Required. The minimum number of replicas to
          deploy.
        max_replica_count (int): Required. The maximum number of replicas to
          deploy.
    """
    # Initialize the Vertex AI client
    aiplatform.init(project=project, location=location)

    # Create the index endpoint instance from an existing endpoint
    index_endpoint = aiplatform.MatchingEngineIndexEndpoint(
        index_endpoint_name=index_endpoint_name
    )

    # Mutate the deployed index
    index_endpoint.mutate_deployed_index(
        deployed_index_id=deployed_index_id,
        min_replica_count=min_replica_count,
        max_replica_count=max_replica_count,
    )

הגדרות פריסה שמשפיעות על הביצועים

הגדרות הפריסה הבאות יכולות להשפיע על זמן האחזור, הזמינות והעלות כשמשתמשים בחיפוש וקטורי. ההנחיות האלה רלוונטיות לרוב המקרים. עם זאת, תמיד כדאי להתנסות בהגדרות האישיות כדי לוודא שהן מתאימות לתרחיש לדוגמה שלכם.

הגדרה השפעה על הביצועים
סוג המכונה

בחירת החומרה משפיעה באופן ישיר על גודל השארד שנבחר. בהתאם לבחירות שלכם לגבי פיצול הנתונים בזמן יצירת האינדקס, כל סוג מכונה מציע פשרה בין ביצועים לעלות.

בדף התמחור מפורטים סוגי החומרה הזמינים והמחירים שלהם. באופן כללי, הביצועים משתפרים לפי הסדר הבא:

  • E2 standard
  • E2 highmem
  • N1 standard
  • N2D standard
מספר מינימלי של רפליקות

‫minReplicaCount שומר קיבולת מינימלית לזמינות ולזמן אחזור, כדי לוודא שלמערכת לא יהיו בעיות של התחלה קרה כשהתנועה גדלה במהירות מרמות נמוכות.

אם יש לכם עומסי עבודה שיורדים לרמות נמוכות ואז עולים במהירות לרמות גבוהות יותר, כדאי להגדיר את minReplicaCount למספר שיכול להתאים לעליות החדות הראשוניות בתנועה.

מספר הרפליקות המקסימלי ‫maxReplicaCount מאפשר בעיקר לשלוט בעלות השימוש. אתם יכולים לבחור למנוע עלייה בעלויות מעבר לסף מסוים, אבל זה עלול להגדיל את זמן האחזור ולהפחית את הזמינות.

רשימה IndexEndpoints

כדי להציג את רשימת המשאבים של IndexEndpoint ואת הפרטים של כל המכונות המשויכות של DeployedIndex, מריצים את הקוד הבא:

gcloud

בדוגמה הבאה השתמשנו בפקודה gcloud ai index-endpoints list.

לפני השימוש בנתוני הפקודה הבאים, צריך להחליף את הנתונים הבאים:

  • ‫LOCATION: האזור שבו אתם משתמשים ב-Agent Platform.
  • ‫PROJECT_ID: מזהה הפרויקט ב- Google Cloud .

מריצים את הפקודה הבאה:

‫Linux,‏ macOS או Cloud Shell

gcloud ai index-endpoints list \
    --region=LOCATION \
    --project=PROJECT_ID

‏Windows (PowerShell)

gcloud ai index-endpoints list `
    --region=LOCATION `
    --project=PROJECT_ID

Windows‏ (cmd.exe)

gcloud ai index-endpoints list ^
    --region=LOCATION ^
    --project=PROJECT_ID

REST

לפני שמשתמשים בנתוני הבקשה, צריך להחליף את הנתונים הבאים:

ה-method של ה-HTTP וכתובת ה-URL:

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

כדי לשלוח את הבקשה צריך להרחיב אחת מהאפשרויות הבאות:

אתם אמורים לקבל תגובת JSON שדומה לזו:

{
 "indexEndpoints": [
   {
     "name": "projects/PROJECT_NUMBER/locations/LOCATION/indexEndpoints/INDEX_ENDPOINT_ID",
     "displayName": "INDEX_ENDPOINT_DISPLAY_NAME",
     "deployedIndexes": [
       {
         "id": "DEPLOYED_INDEX_ID",
         "index": "projects/PROJECT_NUMBER/locations/LOCATION/indexes/INDEX_ID",
         "displayName": "DEPLOYED_INDEX_DISPLAY_NAME",
         "createTime": "2021-06-04T02:23:40.178286Z",
         "privateEndpoints": {
           "matchGrpcAddress": "GRPC_ADDRESS"
         },
         "indexSyncTime": "2022-01-13T04:22:00.151916Z",
         "automaticResources": {
           "minReplicaCount": 2,
           "maxReplicaCount": 10
         }
       }
     ],
     "etag": "AMEw9yP367UitPkLo-khZ1OQvqIK8Q0vLAzZVF7QjdZ5O3l7Zow-mzBo2l6xmiuuMljV",
     "createTime": "2021-03-17T04:47:28.460373Z",
     "updateTime": "2021-06-04T02:23:40.930513Z",
     "network": "VPC_NETWORK_NAME"
   }
 ]
}

Python

במאמר התקנת Vertex AI SDK ל-Python מוסבר איך להתקין או לעדכן את Vertex AI SDK ל-Python. מידע נוסף מופיע ב מאמרי העזרה של ה-API מבוסס-Python.

def vector_search_list_index_endpoint(
    project: str, location: str
) -> List[aiplatform.MatchingEngineIndexEndpoint]:
    """List vector search index endpoints.

    Args:
        project (str): Required. Project ID
        location (str): Required. The region name

    Returns:
        List of aiplatform.MatchingEngineIndexEndpoint
    """
    # Initialize the Vertex AI client
    aiplatform.init(project=project, location=location)

    # List Index Endpoints
    return aiplatform.MatchingEngineIndexEndpoint.list()

המסוף

כדי לראות רשימה של נקודות הקצה של האינדקס:

  1. בקטע Agent Platform במסוף Google Cloud , נכנסים לחלק Deploy and Use. בוחרים באפשרות חיפוש וקטורי.

    כניסה לדף Vector Search

  2. בחלק העליון של הדף, לוחצים על הכרטיסייה Index endpoint.
  3. כל נקודות הקצה הקיימות של האינדקס מוצגות.

למידע נוסף, תוכלו לקרוא את מאמרי העזרה של IndexEndpoint.

ביטול הפריסה של אינדקס

כדי לבטל פריסה של אינדקס, מריצים את הקוד הבא:

gcloud

בדוגמה הבאה השתמשנו בפקודה gcloud ai index-endpoints undeploy-index.

לפני השימוש בנתוני הפקודה הבאים, צריך להחליף את הנתונים הבאים:

  • ‫INDEX_ENDPOINT_ID: המזהה של נקודת הקצה של האינדקס.
  • ‫DEPLOYED_INDEX_ID: מחרוזת שהמשתמש ציין כדי לזהות באופן ייחודי את האינדקס שנפרס. הוא חייב להתחיל באות ויכול להכיל רק אותיות, מספרים או קווים תחתונים. הנחיות לגבי הפורמט מפורטות במאמר DeployedIndex.id.
  • ‫LOCATION: האזור שבו אתם משתמשים ב-Agent Platform.
  • ‫PROJECT_ID: מזהה הפרויקט ב- Google Cloud .

מריצים את הפקודה הבאה:

‫Linux,‏ macOS או Cloud Shell

gcloud ai index-endpoints undeploy-index INDEX_ENDPOINT_ID \
    --deployed-index-id=DEPLOYED_INDEX_ID \
    --region=LOCATION \
    --project=PROJECT_ID

‏Windows (PowerShell)

gcloud ai index-endpoints undeploy-index INDEX_ENDPOINT_ID `
    --deployed-index-id=DEPLOYED_INDEX_ID `
    --region=LOCATION `
    --project=PROJECT_ID

Windows‏ (cmd.exe)

gcloud ai index-endpoints undeploy-index INDEX_ENDPOINT_ID ^
    --deployed-index-id=DEPLOYED_INDEX_ID ^
    --region=LOCATION ^
    --project=PROJECT_ID

REST

לפני שמשתמשים בנתוני הבקשה, צריך להחליף את הנתונים הבאים:

  • ‫INDEX_ENDPOINT_ID: המזהה של נקודת הקצה של האינדקס.
  • ‫DEPLOYED_INDEX_ID: מחרוזת שהמשתמש ציין כדי לזהות באופן ייחודי את האינדקס שנפרס. הוא חייב להתחיל באות ויכול להכיל רק אותיות, מספרים או קווים תחתונים. הנחיות לגבי הפורמט מפורטות במאמר DeployedIndex.id.
  • ‫LOCATION: האזור שבו אתם משתמשים ב-Agent Platform.
  • ‫PROJECT_ID: מזהה הפרויקט ב- Google Cloud .
  • ‫PROJECT_NUMBER: מספר הפרויקט שנוצר באופן אוטומטי.

ה-method של ה-HTTP וכתובת ה-URL:

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

תוכן בקשת JSON:

{
 "deployed_index_id": "DEPLOYED_INDEX_ID"
}

כדי לשלוח את הבקשה צריך להרחיב אחת מהאפשרויות הבאות:

אתם אמורים לקבל תגובת JSON שדומה לזו:

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

Python

במאמר התקנת Vertex AI SDK ל-Python מוסבר איך להתקין או לעדכן את Vertex AI SDK ל-Python. מידע נוסף מופיע ב מאמרי העזרה של ה-API מבוסס-Python.

def vector_search_undeploy_index(
    project: str,
    location: str,
    index_endpoint_name: str,
    deployed_index_id: str,
) -> None:
    """Mutate the deployment resources of an already deployed index.

    Args:
        project (str): Required. Project ID
        location (str): Required. The region name
        index_endpoint_name (str): Required. Index endpoint to run the query
          against.
        deployed_index_id (str): Required. The ID of the DeployedIndex to run
          the queries against.
    """
    # Initialize the Vertex AI client
    aiplatform.init(project=project, location=location)

    # Create the index endpoint instance from an existing endpoint
    index_endpoint = aiplatform.MatchingEngineIndexEndpoint(
        index_endpoint_name=index_endpoint_name
    )

    # Undeploy the index
    index_endpoint.undeploy_index(
        deployed_index_id=deployed_index_id,
    )

המסוף

כדי לבטל פריסה של אינדקס, צריך לפעול לפי ההוראות שכאן.

  1. בקטע Agent Platform במסוף Google Cloud , נכנסים לחלק Deploy and Use. בוחרים באפשרות חיפוש וקטורי.

    כניסה ל-Vector Search

  2. תוצג רשימה של האינדקסים הפעילים.
  3. בוחרים את האינדקס שרוצים לבטל את הפריסה שלו. דף פרטי האינדקס נפתח.
  4. בקטע Deployed indexes, מזהים את נקודת הקצה של האינדקס שרוצים לבטל את הפריסה שלה.
  5. לוחצים על תפריט האפשרויות שנמצא באותה שורה של נקודת הקצה של האינדקס ובוחרים באפשרות Undeploy.
  6. נפתח מסך אישור. לוחצים על ביטול פריסה. הערה: ביטול הפריסה יכול להימשך עד 30 דקות.

מחיקת IndexEndpoint

לפני שמוחקים IndexEndpoint, צריך undeploy של כל האינדקסים שנפרסו בנקודת הקצה.

gcloud

בדוגמה הבאה משתמשים בפקודה gcloud ai index-endpoints delete.

לפני השימוש בנתוני הפקודה הבאים, צריך להחליף את הנתונים הבאים:

  • ‫INDEX_ENDPOINT_ID: המזהה של נקודת הקצה של האינדקס.
  • ‫LOCATION: האזור שבו אתם משתמשים ב-Agent Platform.
  • ‫PROJECT_ID: מזהה הפרויקט ב- Google Cloud .

מריצים את הפקודה הבאה:

‫Linux,‏ macOS או Cloud Shell

gcloud ai index-endpoints delete INDEX_ENDPOINT_ID \
    --region=LOCATION \
    --project=PROJECT_ID

‏Windows (PowerShell)

gcloud ai index-endpoints delete INDEX_ENDPOINT_ID `
    --region=LOCATION `
    --project=PROJECT_ID

Windows‏ (cmd.exe)

gcloud ai index-endpoints delete INDEX_ENDPOINT_ID ^
    --region=LOCATION ^
    --project=PROJECT_ID

REST

לפני שמשתמשים בנתוני הבקשה, צריך להחליף את הנתונים הבאים:

  • ‫INDEX_ENDPOINT_ID: המזהה של נקודת הקצה של האינדקס.
  • ‫LOCATION: האזור שבו אתם משתמשים ב-Agent Platform.
  • ‫PROJECT_ID: מזהה הפרויקט ב- Google Cloud .
  • ‫PROJECT_NUMBER: מספר הפרויקט שנוצר באופן אוטומטי.

ה-method של ה-HTTP וכתובת ה-URL:

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

כדי לשלוח את הבקשה צריך להרחיב אחת מהאפשרויות הבאות:

אתם אמורים לקבל תגובת JSON שדומה לזו:

{
 "name": "projects/PROJECT_NUMBER/locations/LOCATION/indexEndpoints/INDEX_ENDPOINT_ID/operations/OPERATION_ID",
 "metadata": {
   "@type": "type.googleapis.com/google.cloud.aiplatform.v1.DeleteOperationMetadata",
   "genericMetadata": {
     "createTime": "2022-01-13T04:36:19.142203Z",
     "updateTime": "2022-01-13T04:36:19.142203Z"
   }
 },
 "done": true,
 "response": {
   "@type": "type.googleapis.com/google.protobuf.Empty"
 }
}

Python

במאמר התקנת Vertex AI SDK ל-Python מוסבר איך להתקין או לעדכן את Vertex AI SDK ל-Python. מידע נוסף מופיע ב מאמרי העזרה של ה-API מבוסס-Python.

def vector_search_delete_index_endpoint(
    project: str, location: str, index_endpoint_name: str, force: bool = False
) -> None:
    """Delete a vector search index endpoint.

    Args:
        project (str): Required. Project ID
        location (str): Required. The region name
        index_endpoint_name (str): Required. Index endpoint to run the query
          against.
        force (bool): Required. If true, undeploy any deployed indexes on this
          endpoint before deletion.
    """
    # Initialize the Vertex AI client
    aiplatform.init(project=project, location=location)

    # Create the index endpoint instance from an existing endpoint
    index_endpoint = aiplatform.MatchingEngineIndexEndpoint(
        index_endpoint_name=index_endpoint_name
    )

    # Delete the index endpoint
    index_endpoint.delete(force=force)

המסוף

כדי למחוק נקודת קצה של אינדקס, פועלים לפי ההוראות הבאות.

  1. בקטע Agent Platform במסוף Google Cloud , נכנסים לחלק Deploy and Use. בוחרים באפשרות חיפוש וקטורי.

    כניסה ל-Vector Search

  2. בחלק העליון של הדף, לוחצים על הכרטיסייה Index endpoints.
  3. כל נקודות הקצה הקיימות של האינדקס מוצגות.
  4. לוחצים על תפריט האפשרויות שנמצא באותה שורה של נקודת הקצה של האינדקס שרוצים למחוק, ובוחרים באפשרות Delete.
  5. נפתח מסך אישור. לוחצים על Delete. נקודת הקצה של האינדקס נמחקה.