取得摘要和擷取的內容

Agent Search 可在每則搜尋回覆中提供搜尋摘要、擷取答案和擷取片段,提升結果品質。

  • 摘要:摘要是搜尋結果文件中的一小段文字,可預覽搜尋結果內容。其中包含可在 UI 中顯示的命中醒目顯示。摘要通常會顯示在每筆搜尋結果下方,協助使用者評估該結果的關聯性和實用性。摘要適用於含有非結構化資料和網站資料 (基本網站搜尋和進階網站索引) 的資料儲存庫。

  • 擷取答案:擷取答案是與每筆搜尋結果一併傳回的逐字文字。直接從原始文件擷取。擷取式答案通常會顯示在網頁頂端附近,為使用者提供與查詢內容相關的簡短答案。如果資料儲存庫包含非結構化資料,且具備進階網站索引建立功能,則可使用擷取型答案。

  • 擷取片段:擷取片段是與每筆搜尋結果一併傳回的逐字文字。擷取片段通常比擷取答案更冗長。擷取片段可以做為查詢的答案,也可以用於執行後置處理工作,以及做為大型語言模型的輸入內容,以生成答案或新文字。如果資料儲存庫包含非結構化資料,且具備進階網站索引建立功能,則可使用擷取片段。

範例

以下範例有助於說明摘要、擷取答案和擷取片段之間的差異。

查詢:「什麼是 Agent Search?」

  • 摘要:

    為此,我們推出全新的 Agent Search,讓開發人員能以最快的速度開始建構生成式應用程式,例如機器人、...

  • 擷取答案:

    開發人員可透過 Agent Search 快速推出新體驗,包括機器人、對話介面、自訂搜尋引擎、數位助理等。開發人員可透過 API 存取 Google 的基礎模型,並使用現成範本,在幾小時、甚至是幾分鐘內,快速製作出生成式應用程式。

  • 擷取區隔:

    企業和政府也希望運用這項新 AI 技術,讓客戶、合作夥伴和員工的互動更有效率且更有幫助。為此,我們推出全新的 Agent Search。

    開發人員可透過 Agent Search 快速推出新體驗,包括機器人、對話介面、自訂搜尋引擎、數位助理等。開發人員可透過 API 存取 Google 的基礎模型,並使用現成範本,在幾小時、甚至是幾分鐘內,快速製作出生成式應用程式。開發人員還能運用 Agent Search 執行下列操作:

    • 結合組織資料和資訊檢索技術,提供相關答案。
    • 不只用文字搜尋和回覆。
    • 結合自然對話與結構化流程。
    • 不只提供資訊,還要能交易。

事前準備

視應用程式類型而定,請完成下列必要條件:

文字片段

摘要是從每份搜尋結果文件中擷取的簡短逐字稿。包括以粗體 HTML 代碼醒目顯示命中項目,以便在使用者介面中顯示搜尋結果預覽。一般來說,摘要會以預覽文字的形式顯示在搜尋結果下方,協助使用者判斷點選該搜尋結果是否實用。

摘要適用於網站和非結構化搜尋。

取得程式碼片段

如何取得摘要:

  1. 傳送包含 ContentSearchSpec.SnippetSpec 的搜尋要求,並將 returnSnippet 設為 true。

    在下列 SnippetSpec 範例中,指定每筆搜尋結果都能傳回摘要。

    "contentSearchSpec":
    {
      "snippetSpec":
      {
        "returnSnippet": true
      }
    }
    • returnSnippet:如果設為 true,則傳回摘要。
  2. 從搜尋回應中取得摘要。摘要會與 derivedStructData.snippets 中的每筆搜尋結果一併傳回。

    在以下範例中,文件是搜尋回應中的其中一項結果,結果中包含以粗體醒目顯示命中項目的摘要:

    {
      "id": "54321",
      "document": {
        "name": "projects/123/locations/global/collections/default_collection/dataStores/example-datastore/branches/0/documents/54321",
        "id": "54321",
        "derivedStructData": {
          "link": "gs://cloud-samples-data/gen-app-builder/search/alphabet-investor-pdfs/2008_google_annual_report.pdf",
          "snippets": [
            {
              "snippet": "Google Chrome. Google Chrome is an open-source browser that combines a minimal design with technologies to make the web faster, safer, and easier to navigate.",
              "snippet_status": "SUCCESS"
            }
          ]
        }
      }
    }
    • snippet:包含為文件搜尋結果產生的程式碼片段。命中醒目顯示會包含在粗體 HTML 代碼中。
    • snippet_status:如果系統產生摘要,這個欄位會傳回 SUCCESS。如果未產生摘要,這個欄位會傳回 NO_SNIPPET_AVAILABLE。

擷取式答案

擷取答案是從文件中逐字擷取的一段文字。當文件在搜尋回應中做為搜尋結果傳回時,系統會一併傳回相關的擷取答案。

擷取式答案可以是從搜尋結果文件中擷取的文字,例如段落、表格或項目符號清單。擷取式答案比擷取式片段短。

如果需要精確、逐字的回覆,而非重新詮釋的摘要,可以使用擷取答案,做為摘要回覆的替代方案。

摘要答案適用於包含非結構化資料和進階網站索引的資料儲存庫。

取得擷取式答案

如何取得擷取答案:

  1. 傳送搜尋要求,並使用 ContentSearchSpec.extractiveContentSpec 指定 maxExtractiveAnswerCount。

    以下 extractiveContentSpec 範例指定可為每筆搜尋結果傳回答案。

    "contentSearchSpec":
    {
      "extractiveContentSpec": {
        "maxExtractiveAnswerCount": 1
      }
    }
    • maxExtractiveAnswerCount:: 每筆搜尋結果要傳回的摘要答案數量。預設值為 0,最大值為 5。
  2. 從搜尋回應中取得擷取答案。extractive_answers 中的每項搜尋結果都會傳回擷取式答案。

    在以下範例中,文件是搜尋回應中的其中一項結果,且結果中包含擷取式答案:

    {
      "id": "54321",
      "document": {
        "name": "projects/123/locations/global/collections/default_collection/dataStores/example-datastore/branches/0/documents/54321",
        "id": "54321",
        "derivedStructData": {
          "extractive_answers": [
            {
              "pageNumber": "2",
              "content": "Google saw growth throughout the year both in our domestic business and internationally, both on Google owned sites and on the Google Network. Specifically, revenues from Google owned sites increased 101% on a year over year basis, from $792 million to $1.6 billion."
            }
          ],
          "link": "gs://cloud-samples-data/gen-app-builder/search/alphabet-investor-pdfs/2004Q4_earnings_google.pdf"
        }
    }
    }
    • pageNumber:如果可以從文件中擷取頁碼,這個欄位會指出答案的擷取來源。
    • content:擷取答案的內容。

擷取式片段

擷取片段是從搜尋結果文件中逐字擷取的文字。擷取片段與擷取答案類似,但擷取片段通常更完整、更詳細。擷取式片段通常會做為輸入內容,供您自己的 LLM 生成答案或新文字。

擷取片段可以有多個段落,包括表格和項目符號清單等格式化文字。

擷取片段適用於包含非結構化資料和進階網站索引的資料儲存庫。

擷取片段選項

擷取式片段有下列選項:

  • 片段數量:您可以指定每筆搜尋結果最多傳回 10 個擷取片段。

  • 關聯性分數:關聯性分數是根據查詢與擷取區隔的相似度計算。您可以指定傳回擷取片段時,一併傳回關聯性分數。分數範圍介於 -1.0 (較不相關) 至 1.0 (較相關)。啟用關聯性分數可能會增加延遲時間。

  • 相鄰片段:您可以設定 numPreviousSegments 和 numNextSegments,從相關片段前後取得最多 3 個片段。相鄰區隔可為相關區隔提供背景資訊,並提高準確度。

    啟用相鄰區隔可能會增加延遲時間。

取得擷取片段

下列步驟說明如何取得非結構化資料的擷取片段。您可以按照類似步驟,取得網站資料的擷取片段。

  1. 傳送搜尋要求,並使用 ContentSearchSpec.extractiveContentSpec 指定 maxExtractiveSegmentCount。

    以下 extractiveContentSpec 範例指定每筆搜尋結果可傳回一個片段。

    "contentSearchSpec":
    {
      "extractiveContentSpec": {
        "maxExtractiveSegmentCount": 1
      }
    }
    • maxExtractiveSegmentCount: :每個搜尋結果要傳回的擷取片段數量。預設值為 0,最大值為 10。

    其他選項:

    • returnExtractiveSegmentScore:設為 true,即可傳回每個傳回片段的關聯性分數。
    • numPreviousSegments:在相關片段之前傳回的相鄰片段數量。預設值為 0,最大值為 3。使用相鄰區隔可能會增加延遲時間。
    • numNextSegments:在相關片段後方傳回的相鄰片段數量。預設值為 0,最大值為 3。使用相鄰區隔可能會增加延遲時間。

    如要進一步瞭解這些選項,請參閱「擷取片段選項」。

  2. 從搜尋回應中取得區隔。extractive_segments 中的每項搜尋結果都會傳回片段。

    在以下範例中,文件是搜尋回應中的其中一項結果,且結果中包含一個片段:

    {
      "id": "54321",
      "document": {
        "name": "projects/123/locations/global/collections/default_collection/dataStores/example-datastore/branches/0/documents/54321",
        "id": "54321",
        "derivedStructData": {
          "extractive_segments": [
            {
              "pageNumber": "2",
              "content": "Client\nGoogle Toolbar. Google Toolbar is a free application that adds a Google search box to web browsers (Internet\nExplorer and Firefox) and improves user web experience through features such as a pop-up blocker that blocks\npop-up advertising, an autofill feature that completes web forms with information saved on a user's computer, and\ncustomizable buttons that let users search their favorite web sites and stay updated on their favorite feeds.\n\nGoogle Chrome. Google Chrome is an open-source browser that combines a minimal design with\ntechnologies to make the web faster, safer, and easier to navigate.\nGoogle Pack. Google Pack is a free collection of safe, useful software programs from Google and other\ncompanies that improve the user experience online and on the desktop. It includes programs that help users\nbrowse the web faster, remove spyware and viruses.\n\nPicasa. Picasa is a free service that allows users to view, manage and share their photos. Picasa enables users\nto import, organize and edit their photos, and upload them to Picasa Web Albums where the photos can be shared\nwith others on the internet.\n\nGoogle Desktop. Google Desktop lets people perform a full-text search on the contents of their own\ncomputer, including email, files, instant messenger chats and web browser history. Users can view web pages they\nhave visited even when they are not online. Google Desktop also includes a customizable Sidebar that includes\nmodules for weather, stock tickers and news.\n\n5"
            }
          ],
          "link": "gs://cloud-samples-data/gen-app-builder/search/alphabet-investor-pdfs/2004Q4_earnings_google.pdf"
        }
    }
    }
    • pageNumber:如果可以從文件中擷取頁碼,這個欄位會指出答案的擷取來源。
    • content:擷取片段的內容。

後續步驟