管理搜尋設定

限制

如果搜尋設定中有構面屬性,對應的欄位應一律與搜尋條件屬性中的欄位相符。這些欄位應為現有的資料結構定義,且類型、精細度和搜尋策略相同。

建立搜尋設定

REST

如要建立 SearchConfig 資源,請使用 projects.locations.corpora.searchConfigs.create 方法傳送 POST 要求。

以下範例說明如何建立搜尋設定,並自訂搜尋條件。

使用任何要求資料之前,請先替換以下項目:

  • REGIONALIZED_ENDPOINT:端點可能包含與 LOCATION_ID 相符的前置字串,例如 europe-west4-。進一步瞭解 地區化端點
  • PROJECT_NUMBER:您的 Google Cloud專案編號
  • LOCATION_ID:您使用 Vertex AI Vision 的區域。例如:us-central1europe-west4。請參閱可用區域
  • CORPUS_ID:目標語料庫的 ID。
  • SEARCHCONFIG:目標 SearchConfig 的名稱。
    • 在本例中,SearchConfigperson

HTTP 方法和網址:

POST https://warehouse-visionai.googleapis.com/v1/projects/PROJECT_NUMBER/locations/LOCATION_ID/corpora/CORPUS_ID/searchConfigs?search_config_id=person

JSON 要求主體:

{
   "search_criteria_property": {
     "mapped_fields": "player",
     "mapped_fields": "coach",
     "mapped_fields": "cheerleader",
  }
}

如要傳送要求,請選擇以下其中一個選項:

curl

將要求主體儲存在名為 request.json 的檔案中,然後執行下列指令:

curl -X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
"https://warehouse-visionai.googleapis.com/v1/projects/PROJECT_NUMBER/locations/LOCATION_ID/corpora/CORPUS_ID/searchConfigs?search_config_id=person"

PowerShell

將要求主體儲存在名為 request.json 的檔案中,然後執行下列指令:

$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }

Invoke-WebRequest `
-Method POST `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "https://warehouse-visionai.googleapis.com/v1/projects/PROJECT_NUMBER/locations/LOCATION_ID/corpora/CORPUS_ID/searchConfigs?search_config_id=person" | Select-Object -Expand Content

您應該會收到如下的 JSON 回應:

{
  "name": "projects/PROJECT_NUMBER/locations/LOCATION_ID/corpora/CORPUS_ID/searchConfigs/person",
  "searchCriteriaProperty":
    {
      "mappedFields": [
        "player",
        "coach",
        "cheerleader"
      ]
    }
}

更新搜尋設定

REST

如要更新 SearchConfig 資源,請使用 projects.locations.corpora.searchConfigs.patch 方法傳送 POST 要求。

以下範例說明如何建立搜尋設定,並自訂搜尋條件。

使用任何要求資料之前,請先替換以下項目:

  • REGIONALIZED_ENDPOINT:端點可能包含與 LOCATION_ID 相符的前置字串,例如 europe-west4-。進一步瞭解 地區化端點
  • PROJECT:您的 Google Cloud 專案 ID 或專案編號
  • LOCATION_ID:您使用 Vertex AI Vision 的區域。例如:us-central1europe-west4。請參閱可用區域
  • CORPUS_ID:目標語料庫的 ID。
  • SEARCHCONFIG_ID:目標 SearchConfig 的 ID。
  • "mappedFields":一或多個現有的使用者提供的註解鍵。

HTTP 方法和網址:

PATCH https://warehouse-visionai.googleapis.com/v1/projects/PROJECT_NUMBER/locations/LOCATION_ID/corpora/CORPUS_ID/searchConfigs/SEARCHCONFIG_ID

JSON 要求主體:

{
  "name": "projects/PROJECT_NUMBER/locations/LOCATION_ID/corpora/CORPUS_ID/searchConfigs/SEARCHCONFIG_ID1",
  "searchCriteriaProperty": {
    "mappedFields": "dataschema2"
  }
}

如要傳送要求,請選擇以下其中一個選項:

curl

將要求主體儲存在名為 request.json 的檔案中,然後執行下列指令:

curl -X PATCH \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
"https://warehouse-visionai.googleapis.com/v1/projects/PROJECT_NUMBER/locations/LOCATION_ID/corpora/CORPUS_ID/searchConfigs/SEARCHCONFIG_ID"

PowerShell

將要求主體儲存在名為 request.json 的檔案中,然後執行下列指令:

$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }

Invoke-WebRequest `
-Method PATCH `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "https://warehouse-visionai.googleapis.com/v1/projects/PROJECT_NUMBER/locations/LOCATION_ID/corpora/CORPUS_ID/searchConfigs/SEARCHCONFIG_ID" | Select-Object -Expand Content

您應該會收到如下的 JSON 回應:

{
  "name": "projects/PROJECT_NUMBER/locations/LOCATION_ID/corpora/CORPUS_ID/searchConfigs/SEARCHCONFIG_ID1",
  "searchCriteriaProperty": {
    "mappedFields": [
      "dataschema2"
    ]
  }
}

取得搜尋設定

以下範例說明如何擷取現有 SearchConfig,方便您在倉庫儲存的資料中搜尋人員。

REST

如要取得 SearchConfig 的詳細資料,請使用 projects.locations.corpora.searchConfigs.get 方法傳送 GET 要求。

使用任何要求資料之前,請先替換以下項目:

  • REGIONALIZED_ENDPOINT:端點可能包含與 LOCATION_ID 相符的前置字串,例如 europe-west4-。進一步瞭解 地區化端點
  • PROJECT_NUMBER:您的 Google Cloud專案編號
  • LOCATION_ID:您使用 Vertex AI Vision 的區域。例如:us-central1europe-west4。請參閱可用區域
  • CORPUS_ID:目標語料庫的 ID。
  • SEARCHCONFIG:目標 SearchConfig 的名稱。
    • 在本例中,SearchConfigperson

HTTP 方法和網址:

GET https://warehouse-visionai.googleapis.com/v1/projects/PROJECT_NUMBER/locations/LOCATION_ID/corpora/CORPUS_ID/searchConfigs/SEARCHCONFIG

如要傳送要求,請選擇以下其中一個選項:

curl

執行下列指令:

curl -X GET \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
"https://warehouse-visionai.googleapis.com/v1/projects/PROJECT_NUMBER/locations/LOCATION_ID/corpora/CORPUS_ID/searchConfigs/SEARCHCONFIG"

PowerShell

執行下列指令:

$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }

Invoke-WebRequest `
-Method GET `
-Headers $headers `
-Uri "https://warehouse-visionai.googleapis.com/v1/projects/PROJECT_NUMBER/locations/LOCATION_ID/corpora/CORPUS_ID/searchConfigs/SEARCHCONFIG" | Select-Object -Expand Content

您應該會收到如下的 JSON 回應:

{
  "name": "projects/PROJECT_NUMBER/locations/LOCATION_ID/corpora/CORPUS_ID/searchConfigs/person"
  "facet_property": {
    // Top-level facet group name.
    "display_name": "Person",
    // Each mapped_field will be displayed in the UI as a selectable value
    // under "Person".
    "mapped_fields": "player",
    // The maximum number of mapped_fields to be displayed.
    "result_size": 2,
    // The facet type is a singular value. In this case, type string.
    "bucket_type": FACET_BUCKET_TYPE_VALUE
  }
}

列出搜尋設定

以下範例說明如何列出所有先前建立的 SearchConfig 資源。

您可以在要求中設定 page_size 欄位,指定要列出的搜尋設定數量。

REST

如要列出所有搜尋設定,請使用 projects.locations.corpora.searchConfigs.list 方法傳送 GET 要求。

在本範例中,page_size 欄位設為 2,因此回應最多只會包含兩個搜尋設定。如未指定網頁大小,系統會使用預設值 25。

使用任何要求資料之前,請先替換以下項目:

  • REGIONALIZED_ENDPOINT:端點可能包含與 LOCATION_ID 相符的前置字串,例如 europe-west4-。進一步瞭解 地區化端點
  • PROJECT_NUMBER:您的 Google Cloud專案編號
  • LOCATION_ID:您使用 Vertex AI Vision 的區域。例如:us-central1europe-west4。請參閱可用區域
  • CORPUS_ID:目標語料庫的 ID。
  • PAGE_SIZE:(選用) 要傳回的結果數量。

HTTP 方法和網址:

GET https://warehouse-visionai.googleapis.com/v1/projects/PROJECT_NUMBER/locations/LOCATION_ID/corpora/CORPUS_ID/searchConfigs?page_size=2

如要傳送要求,請選擇以下其中一個選項:

curl

執行下列指令:

curl -X GET \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
"https://warehouse-visionai.googleapis.com/v1/projects/PROJECT_NUMBER/locations/LOCATION_ID/corpora/CORPUS_ID/searchConfigs?page_size=2"

PowerShell

執行下列指令:

$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }

Invoke-WebRequest `
-Method GET `
-Headers $headers `
-Uri "https://warehouse-visionai.googleapis.com/v1/projects/PROJECT_NUMBER/locations/LOCATION_ID/corpora/CORPUS_ID/searchConfigs?page_size=2" | Select-Object -Expand Content

您應該會收到如下的 JSON 回應:

{
  "next_page_token": "xyz",
  "search_configs": {
    "name": "projects/PROJECT_NUMBER/locations/LOCATION_ID/corpora/CORPUS_ID/searchConfigs/person",
    "facet_property": {
      // Top-level facet group name.
      "display_name": "Person",
      // Each mapped_field will be displayed in the console as a selectable value
      // under "Person".
      "mapped_fields": "player",
      // The maximum number of mapped_fields to be displayed.
      "result_size": 2,
      // The facet type is a singular value. In this case, type string.
      "bucket_type": FACET_BUCKET_TYPE_VALUE
    }
  },
  "search_configs": {
    "name": "projects/PROJECT_NUMBER/locations/LOCATION_ID/corpora/CORPUS_ID/searchConfigs/location",
    "facet_property": {
      // Top-level facet group name.
      "display_name": "location",
      // Each mapped_field will be displayed in the console as a selectable value
      // under "location".
      "mapped_fields": "city",
      // The maximum number of mapped_fields to be displayed.
      "result_size": 2,
      // The facet type is a singular value. In this case, type string.
      "bucket_type": FACET_BUCKET_TYPE_VALUE
    }
  }
}

由於要求中已設定 page_size=2 欄位,因此回應只包含兩個 SearchConfigs。如要查看下一頁搜尋設定,請在下一個要求中加入先前回應的 next_page_token 設定:

  • https://warehouse-visionai.googleapis.com/v1alpha/[...]/searchConfigs?page_size=2&page_token='xyz'

刪除搜尋設定

REST 和指令列

下列程式碼範例使用 projects.locations.corpora.searchConfigs.delete 方法刪除 SearchConfig。這項要求必須有 SearchConfig 才能成功。

使用任何要求資料之前,請先替換以下項目:

  • REGIONALIZED_ENDPOINT:端點可能包含與 LOCATION_ID 相符的前置字串,例如 europe-west4-。進一步瞭解 地區化端點
  • PROJECT_NUMBER:您的 Google Cloud專案編號
  • LOCATION_ID:您使用 Vertex AI Vision 的區域。例如:us-central1europe-west4。請參閱可用區域
  • CORPUS_ID:目標語料庫的 ID。
  • SEARCHCONFIG_ID:目標 SearchConfig 的 ID。

HTTP 方法和網址:

DELETE https://warehouse-visionai.googleapis.com/v1/projects/PROJECT_NUMBER/locations/LOCATION_ID/corpora/CORPUS_ID/searchConfigs/SEARCHCONFIG_ID

如要傳送要求,請選擇以下其中一個選項:

curl

執行下列指令:

curl -X DELETE \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
"https://warehouse-visionai.googleapis.com/v1/projects/PROJECT_NUMBER/locations/LOCATION_ID/corpora/CORPUS_ID/searchConfigs/SEARCHCONFIG_ID"

PowerShell

執行下列指令:

$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }

Invoke-WebRequest `
-Method DELETE `
-Headers $headers `
-Uri "https://warehouse-visionai.googleapis.com/v1/projects/PROJECT_NUMBER/locations/LOCATION_ID/corpora/CORPUS_ID/searchConfigs/SEARCHCONFIG_ID" | Select-Object -Expand Content

您應該會收到如下的 JSON 回應:

{}