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

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

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

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

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

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

gcloud

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

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

  • ‫INDEX_ENDPOINT_NAME: השם המוצג של נקודת הקצה של האינדקס.
  • ‫VPC_NETWORK_NAME: השם של הרשת ב-Google 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: השם של הרשת ב-Google 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

בדוגמה הבאה נעשה שימוש במשאב 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                    = "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. מידע נוסף מופיע ב מאמרי העזרה של Python API.

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. בוחרים באפשרות חיפוש וקטורי.

    כניסה אל חיפוש וקטורי

  2. תוצג רשימה של האינדקסים הפעילים.
  3. בחלק העליון של הדף, בוחרים בכרטיסייה נקודות קצה של אינדקס. נקודות הקצה של האינדקס מוצגות.
  4. לוחצים על Create new index endpoint. החלונית Create a new index endpoint תיפתח.
  5. מזינים שם לתצוגה של נקודת הקצה של האינדקס.
  6. בשדה אזור, בוחרים אזור מהתפריט הנפתח.
  7. בשדה גישה, בוחרים באפשרות פרטי.
  8. מזינים את הפרטים של רשת ה-VPC המקבילה. מזינים את השם המלא של רשת Compute Engine שאליה צריך ליצור שותפות (peering) של העבודה. הפורמט צריך להיות 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

בדוגמה הבאה נעשה שימוש במשאב vertex_ai_index_endpoint_deployed_index 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_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. מידע נוסף מופיע ב מאמרי העזרה של Python API.

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. בוחרים באפשרות חיפוש וקטורי.

    כניסה אל חיפוש וקטורי

  2. תוצג רשימה של האינדקסים הפעילים.
  3. בוחרים את שם האינדקס שרוצים לפרוס. ייפתח דף הפרטים של האינדקס.
  4. בדף פרטי האינדקס, לוחצים על Deploy to endpoint (פריסה לנקודת קצה). החלונית של פריסת האינדקס תיפתח.
  5. מזינים שם לתצוגה – השם הזה משמש כמזהה ואי אפשר לעדכן אותו.
  6. בתפריט הנפתח Endpoint (נקודת קצה), בוחרים את נקודת הקצה שאליה רוצים לפרוס את האינדקס הזה. הערה: נקודת הקצה לא זמינה אם האינדקס כבר נפרס בה.
  7. אופציונלי: בשדה סוג המכונה, בוחרים באפשרות 'רגיל' או 'זיכרון גבוה'.
  8. זה שינוי אופציונלי. בוחרים באפשרות הפעלת התאמה אוטומטית לעומס כדי לשנות באופן אוטומטי את גודל מספר הצמתים בהתאם לדרישות של עומסי העבודה. מספר הרפליקות שמוגדר כברירת מחדל הוא 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. מידע נוסף מופיע ב מאמרי העזרה של Python API.

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. בוחרים באפשרות חיפוש וקטורי.

    כניסה אל חיפוש וקטורי

  2. תוצג רשימה של האינדקסים הפעילים.
  3. בוחרים את שם האינדקס שרוצים לפרוס. ייפתח דף הפרטים של האינדקס.
  4. בדף פרטי האינדקס, לוחצים על Deploy to endpoint (פריסה לנקודת קצה). החלונית של פריסת האינדקס תיפתח.
  5. מזינים שם לתצוגה – השם הזה משמש כמזהה ואי אפשר לעדכן אותו.
  6. בתפריט הנפתח Endpoint (נקודת קצה), בוחרים את נקודת הקצה שאליה רוצים לפרוס את האינדקס הזה. הערה: נקודת הקצה לא זמינה אם האינדקס כבר נפרס בה.
  7. אופציונלי: בשדה סוג המכונה, בוחרים באפשרות 'רגיל' או 'זיכרון גבוה'.
  8. זה שינוי אופציונלי. בוחרים באפשרות הפעלת התאמה אוטומטית לעומס כדי לשנות באופן אוטומטי את גודל מספר הצמתים בהתאם לדרישות של עומסי העבודה. מספר הרפליקות שמוגדר כברירת מחדל הוא 2 אם ההתאמה האוטומטית של קנה המידה מושבתת.
  • אם לא מגדירים את minReplicaCount וגם לא את maxReplicaCount, ברירת המחדל היא 2.
  • אם מוגדר רק maxReplicaCount, ברירת המחדל של minReplicaCount היא 2.
  • אם מוגדר רק minReplicaCount, הערך של maxReplicaCount יהיה שווה לערך של minReplicaCount.

שינוי של DeployedIndex

אפשר להשתמש ב-MutateDeployedIndex API כדי לעדכן את משאבי הפריסה (לדוגמה, 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. מידע נוסף מופיע ב מאמרי העזרה של Python API.

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
  • E2 highmem
  • N1 standard
  • ‫N2D standard
מספר העותקים המינימלי

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

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

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

רשימה IndexEndpoints

כדי להציג רשימה של משאבי IndexEndpoint ולראות את המידע של מופעי 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. מידע נוסף מופיע ב מאמרי העזרה של Python API.

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. בוחרים באפשרות חיפוש וקטורי.

    כניסה אל חיפוש וקטורי

  2. בחלק העליון של הדף, לוחצים על הכרטיסייה נקודת קצה של האינדקס.
  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. מידע נוסף מופיע ב מאמרי העזרה של Python API.

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. בוחרים באפשרות חיפוש וקטורי.

    מעבר אל חיפוש וקטורי

  2. תוצג רשימה של האינדקסים הפעילים.
  3. בוחרים את האינדקס שרוצים לבטל את הפריסה שלו. ייפתח דף הפרטים של האינדקס.
  4. בקטע Deployed indexes (אינדקסים שנפרסו), מזהים את נקודת הקצה של האינדקס שרוצים לבטל את הפריסה שלו.
  5. לוחצים על התפריט אפשרויות שנמצא באותה שורה של נקודת הקצה של האינדקס ובוחרים באפשרות ביטול הפריסה.
  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. מידע נוסף מופיע ב מאמרי העזרה של Python API.

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. בוחרים באפשרות חיפוש וקטורי.

    מעבר אל חיפוש וקטורי

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