跟进搜索

本页介绍了 Vertex AI Search 中的跟进搜索功能,并介绍了如何使用 API 调用实现此功能。

如果您想向搜索微件添加带跟进的搜索功能,请参阅为搜索微件配置结果

搜索并跟进适用于包含非结构化数据网站的搜索应用。

搜索并跟进功能不适用于 Vertex AI 客服应用。Vertex AI 客服应用使用可与最终用户就内容进行对话的客服。如需详细了解 Vertex AI Agent,请参阅 Vertex AI Agent 简介

跟进搜索简介

搜索跟进功能基于生成式 AI 模型。带跟进搜索与常规非结构化数据搜索不同,因为带跟进搜索会考虑同一搜索会话中的先前查询。

跟进搜索支持以下操作:

  • 自然语言查询处理:处理和理解人类语言输入,识别查询背后的意图,并返回相关结果。

  • 情境感知:它可以理解之前互动的情境,并提供情境感知型回答。

  • 多轮对话:用户可以提出后续问题并获得相关回答。

跟进搜索示例

以下是跟进搜索的示例。假设您想了解墨西哥的度假信息:

  • :一年中什么时候去墨西哥度假最合适?

  • 搜索并跟进:在墨西哥度假的最佳时间是从 11 月到 4 月的旱季。

  • :汇率是多少?

  • 搜索并跟进:1 美元约等于 17.65 墨西哥比索。

  • :12 月的平均温度是多少?

  • 搜索并跟进:平均温度介于 70-78°F 之间。 坎昆的平均温度约为 77°F。

如果使用常规搜索,系统就无法回答“汇率是多少?”这个问题,因为常规搜索无法知道您想要的是墨西哥汇率。同样,常规搜索不会保留上下文,因此无法为您提供墨西哥的温度。

对话简介

在搜索和跟进中,对话由用户提供的文本查询和 Vertex AI Search 提供的回答组成。

这些查询和响应对有时也称为消息。在上面的示例中,第二条消息由“汇率是多少?”和“1 美元大约相当于 17.65 墨西哥比索”组成。

对话会存储在存储非结构化数据的数据存储区中。在数据存储区中,对话由对话资源表示。除了包含询问和回复消息之外,对话资源还包含:

  • 唯一名称(对话 ID)。

  • 状态(进行中或已完成)。

  • 用户伪 ID,即用于跟踪用户的访问者 ID。可以通过编程方式进行分配。

  • 开始时间和结束时间。

准备工作

请确保您满足以下前提条件。具体要求因您所用的应用类型而异。

存储对话和获取回复

您可以使用命令行或客户端库生成搜索回答,并存储包含跟进问题的搜索对话。

REST

如需使用命令行创建对话并根据用户的输入生成回答,请按以下步骤操作:

  1. 指定您要存储对话记录的数据存储区:

    curl -X POST \
    -H "Authorization: Bearer $(gcloud auth print-access-token)" \
    -H "Content-Type: application/json" \
    "https://discoveryengine.googleapis.com/v1/projects/PROJECT_ID/locations/global/collections/default_collection/dataStores/DATA_STORE_ID/conversations" \
    -d '{
      "user_pseudo_id": "USER_PSEUDO_ID"
    }'
    
    • PROJECT_ID:您的 Google Cloud 项目的项目编号或 ID

    • DATA_STORE_ID:与您的应用关联的数据存储区的 ID。

    • USER_PSEUDO_ID:这是用于跟踪搜索访问者的唯一标识符。例如,您可以使用 HTTP Cookie 来实现此功能,HTTP Cookie 可唯一标识单个设备上的访问者。

    点击查看 POST 命令的示例响应。

    {
      "name": "projects/12345/locations/global/collections/default_collection/dataStores/my-data-store_4321/conversations/11078281986791420687",
      "state": "IN_PROGRESS",
      "userPseudoId": "test_id",
      "startTime": "2023-08-15T20:08:12.094639Z"
    }
  2. 生成搜索回答,并将其添加到数据存储区中新的或现有的对话中:

    curl -X POST \
    -H "Authorization: Bearer $(gcloud auth print-access-token)" \
    -H "Content-Type: application/json" \
    "https://discoveryengine.googleapis.com/v1/projects/PROJECT_ID/locations/global/collections/default_collection/dataStores/DATA_STORE_ID/conversations/CONVERSATION_ID:converse" \
    -d '{
      "query": { "input": "FREE_TEXT"},
      "filter": "FILTER"
    }'
    
    • PROJECT_ID:您的 Google Cloud 项目的项目编号或 ID

    • DATA_STORE_ID:与您的应用关联的数据存储区的 ID。

    • CONVERSATION_ID:对话的唯一 ID,例如 123456。对于包含跟进问题的搜索对话,请在每轮对话中使用相同的对话 ID。

    • FREE_TEXT:包含用户问题的自由文本字符串,例如 what is bigquery?

    • FILTER:用于使用过滤表达式过滤搜索结果的文本字段。默认值为空字符串。构建过滤条件的方式因您拥有的是网站数据还是包含元数据的非结构化数据而异。如需了解详情,请参阅使用跟进过滤搜索

    点击查看 POST 命令的示例响应。

    {
    "reply": {
    "summary": {
      "summaryText": "BigQuery is a cloud-based data warehouse that enables businesses to analyze all their data very quickly. It is a fully managed service that provides a simple and cost-effective way to store and analyze large amounts of data."
    }
    },
    "conversation": {
    "name": "projects/12345/locations/global/collections/default_collection/dataStores/my-data-store_4321/conversations/11078281986791420687",
    "state": "IN_PROGRESS",
    "userPseudoId": "test_id",
    "messages": [
      {
        "userInput": {
          "input": "what is bigquery?"
        }
      },
      {
        "reply": {
          "summary": {
            "summaryText": "BigQuery is a cloud-based data warehouse that enables businesses to analyze all their data very quickly. It is a fully managed service that provides a simple and cost-effective way to store and analyze large amounts of data."
          }
        }
      }
    ],
    "startTime": "2023-08-15T20:08:12.094639Z"
    },
    "searchResults": [
    {
      "id": "c86f19582746b56f71c9bb6929893835",
      "document": {
        "name": "projects/12345/locations/global/collections/default_collection/dataStores/my-data-store_4321/branches/0/documents/c86f19582746b56f71c9bb6929893835",
        "id": "c86f19582746b56f71c9bb6929893835",
        "derivedStructData": {
          "link": "gs://aquamuse-data-ucs-eval-dev/documents/94627ee0249dfdfda25b1b158c717bca.txt",
          "snippets": [
            {
              "snippet_status": "SUCCESS",
              "snippet": "For larger websites, talk to the IT team and/or utilize a big data solution such as Google \u003cb\u003eBigQuery\u003c/b\u003e to extract all URLs. It may also be necessary to ask the ..."
            }
          ],
          "extractive_answers": [
            {
              "content": "Alternatively, load the Server Log Files into Google BigQuery and use the Google BigQuery interface or the 360 Data Studio to analyze the data. To monitor the indexation numbers of the HTTP and the HTTPS version, keep an eye on all submitted XML Sitemaps."
            }
          ]
        }
      }
    },
    {
      "id": "774bd7ce2a3509ab4bbd1fc876f39dc2",
      "document": {
        "name": "projects/12345/locations/global/collections/default_collection/dataStores/my-data-store_4321/branches/0/documents/774bd7ce2a3509ab4bbd1fc876f39dc2",
        "id": "774bd7ce2a3509ab4bbd1fc876f39dc2",
        "derivedStructData": {
          "snippets": [
            {
              "snippet": "No snippet is available for this page.",
              "snippet_status": "NO_SNIPPET_AVAILABLE"
            }
          ],
          "extractive_answers": [
            {
              "content": "This consists of a collection of virtual tables. A virtual table exists for every queryable object type (content type if you prefer) in the repository. Each row in these virtual tables correspond to an instance of the corresponding object type (or of one of its subtypes)."
            }
          ],
          "link": "gs://aquamuse-data-ucs-eval-dev/documents/28841ef8590a105e9415f1390648a811.txt"
        }
      }
    },
    {
      "id": "3e1d306e49aefd9e23f2d5f7a66e6c76",
      "document": {
        "name": "projects/12345/locations/global/collections/default_collection/dataStores/my-data-store_4321/branches/0/documents/3e1d306e49aefd9e23f2d5f7a66e6c76",
        "id": "3e1d306e49aefd9e23f2d5f7a66e6c76",
        "derivedStructData": {
          "snippets": [
            {
              "snippet": "No snippet is available for this page.",
              "snippet_status": "NO_SNIPPET_AVAILABLE"
            }
          ],
          "extractive_answers": [
            {
              "content": "Other logo switches are based on search terms. For instance, if the term "ASCII art" is searched, an ASCII art version of the Google logo will appear next to the search box."
            }
          ],
          "link": "gs://aquamuse-data-ucs-eval-dev/documents/98008df3eef5d3ee1661c52f23189190.txt"
        }
      }
    },
    {
      "id": "cf94e24aacd47cd2c2f5effcbdeda832",
      "document": {
        "name": "projects/12345/locations/global/collections/default_collection/dataStores/my-data-store_4321/branches/0/documents/cf94e24aacd47cd2c2f5effcbdeda832",
        "id": "cf94e24aacd47cd2c2f5effcbdeda832",
        "derivedStructData": {
          "extractive_answers": [
            {
              "content": "The company is listed on the NASDAQ stock exchange under the ticker symbols GOOGL and GOOG, and on the Frankfurt Stock Exchange under the ticker symbol GGQ1. These ticker symbols now refer to Alphabet Inc., Google's holding company, since the fourth quarter of 2015."
            }
          ],
          "snippets": [
            {
              "snippet": "No snippet is available for this page.",
              "snippet_status": "NO_SNIPPET_AVAILABLE"
            }
          ],
          "link": "gs://aquamuse-data-ucs-eval-dev/documents/d80204083ef1096799fa4b7257548b33.txt"
        }
      }
    },
    {
      "id": "05bc6497a4e7e6ca36b2e495b354b764",
      "document": {
        "name": "projects/12345/locations/global/collections/default_collection/dataStores/my-data-store_4321/branches/0/documents/05bc6497a4e7e6ca36b2e495b354b764",
        "id": "05bc6497a4e7e6ca36b2e495b354b764",
        "derivedStructData": {
          "extractive_answers": [
            {
              "content": "SQL injection countermeasures are designed to utilize secure programming methods. By changing the variables used by the application code, weaknesses in applications can be greatly minimized. This report will detail how to perform a SQL injection and explore the best countermeasures to prevent the attack."
            }
          ],
          "link": "gs://aquamuse-data-ucs-eval-dev/documents/7cba75d646f5774a21d96801bec68bb3.txt",
          "snippets": [
            {
              "snippet_status": "NO_SNIPPET_AVAILABLE",
              "snippet": "No snippet is available for this page."
            }
          ]
        }
      }
    }
    ]
    }
  3. 针对对话中的每个新问题重复第 2 步。

Python

如需了解详情,请参阅 Vertex AI Agent Builder Python API 参考文档

如需向 Vertex AI Agent Builder 进行身份验证,请设置应用默认凭据。 如需了解详情,请参阅为本地开发环境设置身份验证

from typing import List

from google.api_core.client_options import ClientOptions
from google.cloud import discoveryengine_v1 as discoveryengine

# TODO(developer): Uncomment these variables before running the sample.
# project_id = "YOUR_PROJECT_ID"
# location = "YOUR_LOCATION"                    # Values: "global", "us", "eu"
# data_store_id = "YOUR_DATA_STORE_ID"
# search_queries = ["YOUR_FIRST_SEARCH_QUERY", "YOUR_SECOND_SEARCH_QUERY"]


def multi_turn_search_sample(
    project_id: str,
    location: str,
    data_store_id: str,
    search_queries: List[str],
) -> List[discoveryengine.ConverseConversationResponse]:
    #  For more information, refer to:
    # https://cloud.google.com/generative-ai-app-builder/docs/locations#specify_a_multi-region_for_your_data_store
    client_options = (
        ClientOptions(api_endpoint=f"{location}-discoveryengine.googleapis.com")
        if location != "global"
        else None
    )

    # Create a client
    client = discoveryengine.ConversationalSearchServiceClient(
        client_options=client_options
    )

    # Initialize Multi-Turn Session
    conversation = client.create_conversation(
        # The full resource name of the data store
        # e.g. projects/{project_id}/locations/{location}/dataStores/{data_store_id}
        parent=client.data_store_path(
            project=project_id, location=location, data_store=data_store_id
        ),
        conversation=discoveryengine.Conversation(),
    )


    for search_query in search_queries:
        # Add new message to session
        request = discoveryengine.ConverseConversationRequest(
            name=conversation.name,
            query=discoveryengine.TextInput(input=search_query),
            serving_config=client.serving_config_path(
                project=project_id,
                location=location,
                data_store=data_store_id,
                serving_config="default_config",
            ),
            # Options for the returned summary
            summary_spec=discoveryengine.SearchRequest.ContentSearchSpec.SummarySpec(
                # Number of results to include in summary
                summary_result_count=3,
                include_citations=True,
            ),
        )
        response = client.converse_conversation(request)

        print(f"Reply: {response.reply.summary.summary_text}\n")

        for i, result in enumerate(response.search_results, 1):
            result_data = result.document.derived_struct_data
            print(f"[{i}]")
            print(f"Link: {result_data['link']}")
            print(f"First Snippet: {result_data['snippets'][0]['snippet']}")
            print(
                "First Extractive Answer: \n"
                f"\tPage: {result_data['extractive_answers'][0]['pageNumber']}\n"
                f"\tContent: {result_data['extractive_answers'][0]['content']}\n\n"
            )
        print("\n\n")

使用跟进搜索过滤搜索结果

使用“搜索并跟进”功能进行查询时,您可以添加 filter 字段,以限制用于派生回答的文档池。您可以使用过滤条件表达式构建过滤条件。您使用的过滤表达式因您拥有的是网站数据还是包含元数据的非结构化数据而异。

网站数据的过滤表达式

如果您有包含网站数据的数据存储区,则可以使用高级网站索引编制中的过滤表达式中的过滤表达式,通过跟进查询过滤搜索结果。构建过滤条件表达式后,将其用作存储对话和获取响应的第 2 步中 filter 字段的值。

适用于包含元数据的非结构化数据的过滤表达式

如果您的数据存储区包含包含元数据的非结构化数据,您可以使用跟进查询过滤搜索,以便系统根据文档包含的元数据字段返回文档。如需了解如何使用元数据过滤普通搜索(不进行跟进),请参阅过滤结构化或非结构化数据的搜索结果。您可以使用同样的原则,通过元数据过滤包含跟进信息的搜索。构建过滤条件表达式后,将其用作存储对话和获取响应的第 2 步中 filter 字段的值。

配置摘要

搜索(附带跟进)的响应消息是 summaryText 中返回的生成摘要。您可以通过多种方式配置生成的摘要。以下部分介绍了这些功能:

在搜索结果中获取引用

如果指定了引文,则引文是指在搜索摘要中内嵌的数字。这些数字表示摘要中特定句子的来源搜索结果。

如需获取引用,请执行以下操作:

  • 按照上文中的存储对话和获取聊天回复过程操作,但在第 2 步中,运行以下包含将 includeCitations 设置为 true 的 summarySpec 字段的命令。

    curl -X POST \
    -H "Authorization: Bearer $(gcloud auth print-access-token)" \
    -H "Content-Type: application/json" \
    "https://discoveryengine.googleapis.com/v1/projects/PROJECT_ID/locations/global/collections/default_collection/dataStores/DATA_STORE_ID/conversations/CONVERSATION_ID:converse" \
    -d '{
      "query": { "input": "FREE_TEXT"},
      "summarySpec": { "include_citations": true }
    }'
    

    点击查看示例命令的部分响应。

    {
    "reply": {
    "summary": {
    }
    "reply": {
    "summary": {
      "summaryText": "BigQuery is a cloud-based data warehouse that enables businesses to analyze all their data very quickly [1]. It is a fully managed service that provides a simple and cost-effective way to store and analyze large amounts of data [2, 3].",
      "safetyAttributes": {
        "categories": [
          "Finance",
          "Legal"
        ]

摘要文本中包含引用编号。引文编号是指返回的搜索结果,编号从 1 开始。例如,[1] 表示该句子归因于第一个搜索结果。[2, 3] 表示该句子同时归因于第二个和第三个搜索结果。

忽略对抗性查询

恶意查询包含负面评论,或者旨在生成不安全、违反政策的输出。您可以指定不应针对对抗性查询返回搜索摘要。当系统忽略对抗性查询时,summaryText 属性会包含表示未返回任何搜索摘要的样本文字。系统会针对对抗性查询返回搜索文档,但不会返回搜索摘要。

如需指定不应针对对抗性查询返回搜索摘要,请执行以下操作:

  • 按照上文中的存储对话和获取聊天回复过程操作,但在第 2 步中,运行以下包含将 ignoreAdversarialQuery 设置为 true 的 summarySpec 字段的命令。

    curl -X POST \
    -H "Authorization: Bearer $(gcloud auth print-access-token)" \
    -H "Content-Type: application/json" \
    "https://discoveryengine.googleapis.com/v1/projects/PROJECT_ID/locations/global/collections/default_collection/dataStores/DATA_STORE_ID/conversations/CONVERSATION_ID:converse" \
    -d '{
      "query": { "input": "FREE_TEXT"},
      "summarySpec": { "ignoreAdversarialQuery": true }
    }'
    

    点击可查看对抗性询问的部分回答。

    "reply": {
    "summary": {
      "summaryText": "A summary could not be generated for your search query. Here are some search results.",
      "summarySkippedReasons": [
        "ADVERSARIAL_QUERY_IGNORED"
      ]

忽略非摘要查询

非摘要查询会返回不适合总结的结果。例如,“为什么天空是蓝色的?”和“谁是世界上最好的足球运动员?”是寻求摘要的查询,但“SFO 机场”和“2026 年世界杯”不是。这类查询很可能是导航查询。您可以指定不应针对非摘要查询返回搜索摘要。系统会针对非摘要查询返回搜索文档,但不会返回搜索摘要。

如需指定不应针对非摘要查询返回搜索摘要,请执行以下操作:

  • 按照上文中的存储对话和获取聊天回复过程操作,但在第 2 步中,运行以下包含将 ignoreNonSummarySeekingQuery 设置为 true 的 summarySpec 字段的命令。

    curl -X POST \
    -H "Authorization: Bearer $(gcloud auth print-access-token)" \
    -H "Content-Type: application/json" \
    "https://discoveryengine.googleapis.com/v1/projects/PROJECT_ID/locations/global/collections/default_collection/dataStores/DATA_STORE_ID/conversations/CONVERSATION_ID:converse" \
    -d '{
      "query": { "input": "FREE_TEXT"},
      "summarySpec": { "ignore_non_summary_seeking_query": true }
    }'
    

    点击可查看对抗性询问的部分回答。

     "reply": {
    "summary": {
      "summaryText": "A summary could not be generated for your search query. Here are some search results.",
      "summarySkippedReasons": [
        "NON_SUMMARY_SEEKING_QUERY_IGNORED"
      ]

设置摘要中要使用的结果数量

您可以指定用于生成摘要的结果数量。默认情况下,如果未设置 summaryResultCount 字段,系统会使用返回的所有结果来生成摘要。

如需设置要用于摘要的热门结果数量,请执行以下操作:

  • 请按照上文中的存储对话和获取聊天回复过程操作,但在第 2 步中,请运行以下包含用于设置 summaryResultCountsummarySpec 字段的命令。

    curl -X POST \
    -H "Authorization: Bearer $(gcloud auth print-access-token)" \
    -H "Content-Type: application/json" \
    "https://discoveryengine.googleapis.com/v1/projects/PROJECT_ID/locations/global/collections/default_collection/dataStores/DATA_STORE_ID/conversations/CONVERSATION_ID:converse" \
    -d '{
      "query": { "input": "FREE_TEXT"},
      "summarySpec": { "summary_result_count": NUMBER_OF_RESULTS }
    }'
    

    NUMBER_OF_RESULTS:用于生成搜索摘要的热门搜索结果的数量。如果返回的结果数量少于 summaryResultCount,系统会根据所有结果生成摘要。最大值为 5

获取自定义摘要

您可以在请求摘要时在 modelPromptSpec.preamble 字段中提供自然语言说明,以获取自定义摘要。

您可以请求自定义设置,例如长度和详细程度、输出样式(例如“简单”)、输出语言、答案重点和格式(例如表格、项目符号和 XML)。

例如,对于询问“BigQuery 有哪些优势?”的查询,您可以输入自定义说明,如以下示例所示:

  • 说明示例:"please show the answer format in an ordered list"

    回答示例:

    The benefits of BigQuery are:
    
    1. Increased business productivity
    2. IT staff productivity
    3. Reduced infrastructure costs
    4. Loading and exporting data are free
    
  • 说明示例:give a very detailed answer

    回答示例:

    BigQuery is a serverless, highly scalable, and cost-effective cloud data warehouse that enables businesses to analyze all their data very quickly. It is a fully managed service that takes care of provisioning, scaling, and managing the underlying infrastructure, so you can focus on analyzing your data. BigQuery is also integrated with other Google Cloud services, such as Google Kubernetes Engine, Cloud Data Fusion, and Cloud Dataproc, making it easy to build and deploy data pipelines.
    
    Here are some of the benefits of using BigQuery:
    
    * **Fast and scalable:** BigQuery can process petabytes of data very quickly, and it can scale to handle even the most demanding workloads. * **Cost-effective:** BigQuery is a very cost-effective way to store and analyze data. You only pay for the data that you use, and there are no upfront costs or commitments. * **Secure:** BigQuery is a secure platform that meets the needs of even the most security-conscious organizations. * **Easy to use:** BigQuery is easy to use, even for non-technical users. It has a simple and intuitive user interface, and it supports a variety of data sources. * **Integrated with other Google Cloud services:** BigQuery is integrated with other Google Cloud services, making it easy to build and deploy data pipelines.
    
    If you are looking for a fast, scalable, and cost-effective way to analyze your data, then BigQuery is a great option.
    

如需获取自定义摘要,请执行以下操作:

  • 按照上文中的存储对话和获取聊天回复过程操作,但在第 2 步中,运行以下命令,其中包含用于在 modelPromptSpec.preamble 中指定自定义说明的 summarySpec 字段。

      curl -X POST \
      -H "Authorization: Bearer $(gcloud auth print-access-token)" \
      -H "Content-Type: application/json" \
      "https://discoveryengine.googleapis.com/v1/projects/PROJECT_ID/locations/global/collections/default_collection/dataStores/DATA_STORE_ID/conversations/CONVERSATION_ID:converse" \
      -d '{
        "query": { "input": "FREE_TEXT"},
        "summarySpec": {
          "modelPromptSpec": {
            "preamble": "CUSTOMIZATION_INSTRUCTIONS"
          }
        }
      }'
    
    • CUSTOMIZATION_INSTRUCTIONS:自定义说明,以字符串表示。

安全搜索功能可用于从摘要回答中滤除露骨、不安全、违反政策的输出内容。如需详细了解安全搜索功能,请参阅 Vertex AI Search 的安全设置

如需对聊天回复应用安全搜索功能,请执行以下操作:

  • 请按照上文中的存储对话和获取聊天回复过程操作,但在第 2 步中,请在查询下方指定 safe_search

    curl -X POST \
    -H "Authorization: Bearer $(gcloud auth print-access-token)" \
    -H "Content-Type: application/json" \
    "https://discoveryengine.googleapis.com/v1/projects/PROJECT_ID/locations/global/collections/default_collection/dataStores/DATA_STORE_ID/conversations/CONVERSATION_ID:converse" \
    -d '{
      "query": { "input": "FREE_TEXT"},
      "safe_search": true
    }'
    

查看和修改存储的对话

您可以使用命令行获取、删除、更新和列出存储的对话。

从数据存储区获取对话

如需从数据存储区获取与特定对话有关的所有详细信息,请执行以下操作:

  • 运行以下 curl 命令:

    curl -X GET \
    -H "Authorization: Bearer $(gcloud auth print-access-token)" \
    -H "Content-Type: application/json" \
    "https://discoveryengine.googleapis.com/v1/projects/PROJECT_ID/locations/global/collections/default_collection/dataStores/DATA_STORE_ID/conversations/CONVERSATION_ID"
    
    • PROJECT_ID:您的 Google Cloud 项目的项目编号或 ID

    • DATA_STORE_ID:与您的应用关联的数据存储区的 ID。

    • CONVERSATION_ID:对话 ID

    点击查看 GET 命令的示例响应。

    {
    "name": "projects/12345/locations/global/collections/default_collection/dataStores/my-data-store_4321/conversations/2040473575290303058",
    "state": "IN_PROGRESS",
    "userPseudoId": "2040473575290303058",
    "messages": [
    {
      "userInput": {
        "input": "what is bigquery?"
      }
    },
    {
      "reply": {
        "summary": {
          "summaryText": "BigQuery is a cloud-based data warehouse that enables businesses to analyze all their data very quickly. It is a fully managed service that provides a simple and cost-effective way to store and analyze large amounts of data."
        }
      }
    }
    ],
    "startTime": "2023-08-15T20:11:24.046735Z"
    }

从数据存储区中删除对话

默认情况下,系统会自动删除 60 天之前的对话。不过,如果您想删除特定对话(例如,如果对话中意外包含敏感内容),请使用此 API 调用进行删除。

如需从数据存储区中删除对话,请执行以下操作:

  • 运行以下 curl 命令:

    curl -X DELETE \
    -H "Authorization: Bearer $(gcloud auth print-access-token)" \
    -H "Content-Type: application/json" \
    "https://discoveryengine.googleapis.com/v1/projects/PROJECT_ID/locations/global/collections/default_collection/dataStores/DATA_STORE_ID/conversations/CONVERSATION_ID"
    
    • PROJECT_ID:您的 Google Cloud 项目的项目编号或 ID

    • DATA_STORE_ID:与您的应用关联的数据存储区的 ID。

    • CONVERSATION_ID:对话 ID

    DELETE 命令的响应如下所示:

    {}
    

更新对话

您可能出于多种原因而需要更新对话。例如,执行以下任一操作:

  • 将会话标记为已完成

  • 将一个对话中的消息合并到另一个对话中

  • 更改 user_pseudo_id

如需更新对话中的 state,请执行以下操作:

  • 运行以下 curl 命令:

    curl -X PATCH \
    -H "Authorization: Bearer $(gcloud auth print-access-token)" \
    -H "Content-Type: application/json" \
    "https://discoveryengine.googleapis.com/v1/projects/PROJECT_ID/locations/global/collections/default_collection/dataStores/DATA_STORE_ID/conversations/CONVERSATION_ID?updateMask=state" \
    -d '{
      "state": "NEW_STATE"
    }'
    
    • PROJECT_ID:您的 Google Cloud 项目的项目编号或 ID

    • DATA_STORE_ID:与您的应用关联的数据存储区的 ID。

    • CONVERSATION_ID:您要更新的对话的 ID

    • NEW_STATE:状态的新值,例如 COMPLETED

    点击查看 PATCH 命令的示例响应。

    {
    "name": "projects/12345/locations/global/collections/default_collection/dataStores/my-data-store_4321/conversations/11078281986791420687",
    "state": "COMPLETED",
    "userPseudoId": "test_id1",
    "messages": [
    {
      "userInput": {
        "input": "what is bigquery?"
      }
    },
    {
      "reply": {
        "summary": {
          "summaryText": "BigQuery is a cloud-based data warehouse that enables businesses to analyze all their data very quickly. It is a fully managed service that provides a simple and cost-effective way to store and analyze large amounts of data."
        }
      }
    }
    ],
    "startTime": "2023-08-15T20:08:12.094639Z"
    }

如需更新对话中的 user_pseudo_id,请执行以下操作:

  • 运行以下 curl 命令:

    curl -X PATCH \
    -H "Authorization: Bearer $(gcloud auth print-access-token)" \
    -H "Content-Type: application/json" \
    "https://discoveryengine.googleapis.com/v1/projects/PROJECT_ID/locations/global/collections/default_collection/dataStores/DATA_STORE_ID/conversations/CONVERSATION_ID?updateMask=user_pseudo_id" \
    -d '{
      "user_pseudo_id": "NEW_USER_PSEUDO_ID"
    }'
    
    • PROJECT_ID:您的 Google Cloud 项目的项目编号或 ID

    • DATA_STORE_ID:与您的应用关联的数据存储区的 ID。

    • CONVERSATION_ID:您要更新的对话的 ID

    • NEW_USER_PSEUDO_ID:用户伪 ID 的新值

    点击查看 PATCH 命令的示例响应。

    {
    "name": "projects/12345/locations/global/collections/default_collection/dataStores/my-data-store_4321/conversations/11078281986791420687",
    "state": "IN_PROGRESS",
    "userPseudoId": "test_id1",
    "messages": [
    {
      "userInput": {
        "input": "what is bigquery?"
      }
    },
    {
      "reply": {
        "summary": {
          "summaryText": "BigQuery is a cloud-based data warehouse that enables businesses to analyze all their data very quickly. It is a fully managed service that provides a simple and cost-effective way to store and analyze large amounts of data."
        }
      }
    }
    ],
    "startTime": "2023-08-15T20:08:12.094639Z"
    }

上述命令展示了如何更改 user_pseudo_id.。不过,您也可以将 user_pseudo_id 替换为对话资源中的其他字段,从而更新对话中的其他字段。

列出所有对话

如需列出数据存储区中的所有对话,请执行以下操作:

  • 运行以下 curl 命令:

    curl -X GET \
    -H "Authorization: Bearer $(gcloud auth print-access-token)" \
    -H "Content-Type: application/json" \
    "https://discoveryengine.googleapis.com/v1/projects/PROJECT_ID/locations/global/collections/default_collection/dataStores/DATA_STORE_ID/conversations"
    
    • PROJECT_ID:您的 Google Cloud 项目的项目编号或 ID

    • DATA_STORE_ID:与您的应用关联的数据存储区的 ID。

    点击查看 GET 命令的示例响应。

    {
    "conversations": [
    {
      "name": "projects/12345/locations/global/collections/default_collection/dataStores/my-data-store_4321/conversations/11078281986791420687",
      "state": "IN_PROGRESS",
      "userPseudoId": "test_id",
      "messages": [
        {
          "userInput": {
            "input": "what is bigquery?"
          }
        },
        {
          "reply": {
            "summary": {
              "summaryText": "BigQuery is a cloud-based data warehouse that enables businesses to analyze all their data very quickly. It is a fully managed service that provides a simple and cost-effective way to store and analyze large amounts of data."
            }
          }
        }
      ],
      "startTime": "2023-08-15T20:08:12.094639Z"
    },
    {
      "name": "projects/12345/locations/global/collections/default_collection/dataStores/my-data-store_4321/conversations/2040473575290303058",
      "state": "IN_PROGRESS",
      "userPseudoId": "2040473575290303058",
      "messages": [
        {
          "userInput": {
            "input": "what is bigquery?"
          }
        },
        {
          "reply": {
            "summary": {
              "summaryText": "BigQuery is a cloud-based data warehouse that enables businesses to analyze all their data very quickly. It is a fully managed service that provides a simple and cost-effective way to store and analyze large amounts of data."
            }
          }
        }
      ]
    }
    ]
    }

响应包含对话列表和 next_page_token。如果未返回 next_page_token,则表示没有更多对话可列出。

默认页面大小为 50。

按过滤条件列出对话

您可能希望列出数据存储区中的所有对话,而不是列出所有未结束的对话或与特定用户关联的所有对话。

例如,您可以向用户显示其已关闭的搜索记录,并提供重新打开其中某个搜索记录的选项。

为此,您可以列出与给定过滤条件匹配的对话:user_pseudo_idstateIN_PROGRESSCOMPLETED)。

列出用户的对话

如需列出与用户或访问者关联的对话,请执行以下操作:

  • 运行以下 curl 命令:

    curl -X GET \
    -H "Authorization: Bearer $(gcloud auth print-access-token)" \
    -H "Content-Type: application/json" \
    "https://discoveryengine.googleapis.com/v1/projects/PROJECT_ID/locations/global/collections/default_collection/dataStores/DATA_STORE_ID/conversations?filter=user_pseudo_id=USER_PSEUDO_ID"
    
    • PROJECT_ID:您的 Google Cloud 项目的项目编号或 ID

    • DATA_STORE_ID:与您的应用关联的数据存储区的 ID。

    • USER_PSEUDO_ID:您要列出对话的用户的假名 ID。

    GET 命令的响应如下所示:

    点击查看 GET 命令的示例响应。

    {
    "conversations": [
    {
      "name": "projects/12345/locations/global/collections/default_collection/dataStores/my-data-store_4321/conversations/11078281986791420687",
      "state": "IN_PROGRESS",
      "userPseudoId": "test_id",
      "messages": [
        {
          "userInput": {
            "input": "what is bigquery?"
          }
        },
        {
          "reply": {
            "summary": {
              "summaryText": "BigQuery is a cloud-based data warehouse that enables businesses to analyze all their data very quickly. It is a fully managed service that provides a simple and cost-effective way to store and analyze large amounts of data."
            }
          }
        }
      ],
      "startTime": "2023-08-15T20:08:12.094639Z"
    }
    ]
    }

列出用户和状态的对话

如需列出处于特定状态(打开或已关闭)与用户或访问者相关的对话,请执行以下操作:

  • 运行以下 curl 命令:

    curl -X GET \
    -H "Authorization: Bearer $(gcloud auth print-access-token)" \
    -H "Content-Type: application/json" \
    "https://discoveryengine.googleapis.com/v1/projects/PROJECT_ID/locations/global/collections/default_collection/dataStores/DATA_STORE_ID/conversations?filter=user_pseudo_id=USER_PSEUDO_ID%20AND%20state=STATE"
    
    • PROJECT_ID:您的 Google Cloud 项目的项目编号或 ID

    • DATA_STORE_ID:与您的应用关联的数据存储区的 ID。

    • USER_PSEUDO_ID:您要列出对话的用户的假名 ID。

    • STATE:对话是处于打开还是关闭状态(IN_PROGRESSCOMPLETED

    GET 命令的响应如下所示:

    点击查看 GET 命令的示例响应。

    {
    "conversations": [
    {
      "name": "projects/12345/locations/global/collections/default_collection/dataStores/my-data-store_4321/conversations/11078281986791420687",
      "state": "IN_PROGRESS",
      "userPseudoId": "test_id",
      "messages": [
        {
          "userInput": {
            "input": "what is bigquery?"
          }
        },
        {
          "reply": {
            "summary": {
              "summaryText": "BigQuery is a cloud-based data warehouse that enables businesses to analyze all their data very quickly. It is a fully managed service that provides a simple and cost-effective way to store and analyze large amounts of data."
            }
          }
        }
      ],
      "startTime": "2023-08-15T20:08:12.094639Z"
    }
    ]
    }

如需了解过滤语法的一般信息,请参阅 AIP-160 过滤

“相关问题”是包含许可名单功能的预览版功能,除了搜索结果之外,还可以返回相关问题。

例如,当您询问“去墨西哥度假的最佳季节是什么?”时,除了回答您的问题外,搜索功能还会建议您可能要问的其他问题,例如“去墨西哥度假最便宜的月份是什么?”和“墨西哥的旅游旺季是什么月份?”

如果您希望搜索应用返回相关问题,请与您的 Google 客户支持团队联系,告知他们您希望为哪些项目和应用启用相关问题功能。如果您不使用默认的服务配置,则还需要提供服务配置的名称。

启用相关问题功能后,系统会在 ConverseConversationResponse 中以字符串的形式返回问题。

更多信息

  • 如需详细了解 summaryResultCountincludeCitationsignoreAdversarialQueryignoreNonSummarySeekingQuery 字段,请参阅 Vertex AI Agent Builder API 文档中的 SummarySpec

  • 如需有关获取搜索摘要的更多示例,请参阅获取摘要