本頁面介紹 Agent Search 的後續搜尋功能,並說明如何使用 API 呼叫實作。
如要在搜尋小工具中新增後續搜尋功能,請參閱「設定搜尋小工具的結果」。
關於含後續查詢的搜尋
「搜尋並提出後續問題」功能採用生成式 AI 模型。「搜尋並提出後續問題」與一般非結構化資料搜尋不同,因為前者會考量同一搜尋工作階段中的先前查詢。
含後續查詢的搜尋支援下列功能:
自然語言查詢處理:處理及理解人類語言輸入內容、識別查詢意圖,並傳回相關結果。
脈絡感知:理解先前互動的脈絡,並提供符合脈絡的回覆。
多輪對話:使用者可以提出後續問題,並獲得相關回覆。
含後續查詢的搜尋範例
以下是含後續查詢的搜尋範例。假設您想瞭解墨西哥度假資訊:
你:一年中什麼時候最適合去墨西哥度假?
搜尋並接續提問:墨西哥最適合度假的時間是乾季,也就是 11 月到 4 月。
你:匯率是多少?
搜尋並接續提問:1 美元約等於 17.65 墨西哥披索。
你:12 月的平均溫度是多少?
搜尋後續問題:平均溫度介於 70 到 78°F 之間。 坎昆的平均溫度約為 25°C。
如果使用一般搜尋,系統無法回答「匯率是多少?」這個問題,因為一般搜尋不知道您想查詢墨西哥的匯率。同樣地,一般搜尋不會保留上下文,因此無法提供墨西哥的溫度。
關於對話
在搜尋與後續查詢中,對話是由使用者提供的文字查詢和 Agent Search 提供的回覆組成。
這類查詢和回覆組合有時稱為「訊息」。在上述範例中,第二則訊息由「What is the exchange rate?」和「1 USD is equal to approximately 17.65 Mexican pesos.」組成。
對話會儲存在非結構化資料所在的資料儲存庫中。在資料儲存庫中,對話是以對話資源表示。除了包含查詢和回覆訊息外,對話資源還包含:
專屬名稱 (對話 ID)。
狀態 (進行中或已完成)。
使用者虛擬 ID,也就是追蹤使用者的訪客 ID。可透過程式輔助方式指派。
開始時間和結束時間。
事前準備
請確認您符合下列必要條件。相關規定會因應用程式類型而異。
如果您有網站搜尋應用程式,請確認下列功能已啟用:
儲存對話並取得回覆
您可以使用指令列或用戶端程式庫生成搜尋回覆,並儲存搜尋與後續對話。
REST
如要使用指令列建立對話,並根據使用者輸入內容生成回覆,請按照下列步驟操作:
指定要儲存對話記錄的資料儲存庫:
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:用來追蹤搜尋訪客的專屬 ID。舉例來說,您可以使用 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" }
生成搜尋回覆,並新增至資料儲存庫中的新對話或現有對話:
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." } ] } } } ] }
針對對話中的每個新問題,重複執行步驟 2。
Python
詳情請參閱 Agent Search Python API 參考文件。
如要向 Agent Search 進行驗證,請設定應用程式預設憑證。詳情請參閱「為本機開發環境設定驗證機制」。
篩選含後續查詢的搜尋
使用後續查詢功能進行搜尋時,您可以加入 filter 欄位,限制回覆來源的文件範圍。您可以使用篩選運算式建構篩選器。篩選運算式會因您使用的是網站資料,還是含中繼資料的非結構化資料而異。
網站資料的篩選運算式
如果資料儲存庫含有網站資料,您可以使用「使用進階網站索引建立功能的篩選運算式」中的篩選運算式,透過後續查詢篩選搜尋結果。建構篩選運算式後,請在「儲存對話並取得回覆」的步驟 2 中,將其用於 filter 欄位的值。
含中繼資料的非結構化資料篩選運算式
如果資料儲存庫含有非結構化資料和中繼資料,您可以使用後續查詢篩選搜尋結果,根據文件包含的中繼資料欄位傳回文件。請參閱「篩選結構化或非結構化資料的搜尋結果」,瞭解如何使用中繼資料篩選一般搜尋 (不含後續追蹤)。您可以使用相同原則,透過中繼資料篩選後續追蹤搜尋。建構篩選運算式後,請在「儲存對話並取得回覆」的步驟 2 中,將運算式用於 filter 欄位的值。
設定摘要
「搜尋與後續問題」的回覆訊息,是以 summaryText 格式傳回的生成摘要。您可以透過多種方式設定生成的摘要。以下各節將說明這些方法:
取得附有引用來源的搜尋結果
如果指定引用來源,搜尋摘要中會顯示數字。這些數字代表摘要中的特定句子取自哪些搜尋結果。
如何取得引用內容:
請按照上述「儲存對話並取得對話回覆」程序操作,但在步驟 2 中,請執行包含
summarySpec欄位的指令,將includeCitations設為 true。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 中,請執行包含
summarySpec欄位的指令,將ignoreAdversarialQuery設為 true。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 中,請執行包含
summarySpec欄位的指令,將ignoreNonSummarySeekingQuery設為 true。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 執行這個指令,其中包含設定
summaryResultCount的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": { "summary_result_count": NUMBER_OF_RESULTS } }'NUMBER_OF_RESULTS:要根據多少筆熱門結果生成搜尋摘要。如果傳回的結果數量少於
summaryResultCount,系統會根據所有結果生成摘要。最大值為5。
取得自訂摘要
要求摘要時,您可以在 modelPromptSpec.preamble 欄位中提供自然語言指示,取得自訂摘要。
您可以要求自訂長度和詳細程度、輸出樣式 (例如「簡單」)、輸出語言、答案重點和格式 (例如表格、項目符號和 XML)。
舉例來說,如果查詢「What are the benefits of bigquery?」(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 中,請執行這個指令,其中包含
summarySpec欄位,用於指定modelPromptSpec.preamble中的自訂指示。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:自訂操作說明,以字串表示。
對對話回覆套用安全搜尋
安全搜尋功能可用於濾除摘要回覆中煽情露骨、不安全、違反政策的輸出內容。如要進一步瞭解安全搜尋,請參閱「代理搜尋的安全設定」。
如要對對話回覆套用安全搜尋,請按照下列步驟操作:
按照上述「儲存對話並取得對話回覆」程序操作,但在步驟 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_id
或
state
(IN_PROGRESS 或 COMPLETED)。
列出使用者的對話
如要列出與使用者或訪客相關聯的對話,請按照下列步驟操作:
執行下列 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_PROGRESS或COMPLETED)
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 中的字串形式傳回問題。
更多資訊
如要進一步瞭解
summaryResultCount、includeCitations、ignoreAdversarialQuery、ignoreNonSummarySeekingQuery欄位,請參閱 Agent Search API 說明文件中的 SummarySpec。如需更多取得搜尋摘要的範例,請參閱「取得摘要」。