管理搜索配置

限制

如果搜索配置中存在 facet 属性,则其映射的字段应始终与搜索条件属性中的字段匹配。这些字段应是具有相同类型、粒度和搜索策略的现有数据架构。

创建搜索配置

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
    }
  }
}

响应中仅包含两个 SearchConfigs,因为在请求中,page_size=2 字段已设置。如需查看下一页搜索配置,请在下一个请求中添加上一个响应的 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 响应:

{}