本頁說明如何使用 Agent Search 剖析及分塊文件。
您可以調整剖析或分塊設定,以便:
指定 Agent Search 剖析內容的方式。將非結構化內容上傳至 Agent Search 時,您可以指定剖析方式。Agent Search 提供數位剖析器、PDF 專用 OCR 剖析器和版面配置剖析器。您也可以自備剖析過的文件。如果文件含有豐富內容和結構元素 (例如章節、段落、表格、圖片和清單),建議使用版面配置剖析器,從中擷取內容來生成搜尋結果和答案。
請參閱「透過剖析改善內容偵測」。
使用 Agent Search 執行檢索增強生成 (RAG)。 將相關資料上傳至 Agent Search 應用程式,即可改善 LLM 的輸出內容。如要執行這項操作,請開啟文件分塊功能,將資料建立索引並分成多個區塊,提高關聯性並降低 LLM 的運算負載。您也會啟用版面配置剖析器,偵測標題和清單等文件元素,改善文件分塊方式。
如要瞭解 RAG 的分塊作業,以及如何在搜尋要求中傳回分塊,請參閱「為 RAG 分塊文件」。
剖析文件
您可以透過下列方式控管內容剖析:
指定剖析器類型。您可以根據檔案類型,指定要套用的剖析類型:
數位剖析器。除非指定其他剖析器類型,否則所有檔案類型預設都會啟用數位剖析器。如果資料儲存庫未指定其他預設剖析器,或指定的剖析器不支援擷取文件的檔案類型,數位剖析器就會處理擷取的文件。
PDF 的 OCR 剖析。如要上傳掃描的 PDF,或圖片中含有文字的 PDF,可以使用這個剖析器,做為版面配置剖析器的低成本替代方案。請參閱本文的「PDF 專用 OCR 剖析器」一節。
版面配置剖析器。如果打算使用代理搜尋功能進行 RAG,請為 HTML、PDF、DOCX、PPTX 和 XLSX 檔案啟用版面配置剖析器。如要瞭解這個剖析器和啟用方式,請參閱「為 RAG 切分文件」。版面配置剖析器可對圖片和掃描文件執行光學字元辨識。
使用自己的剖析文件。(預先發布版) 如果您已剖析非結構化文件,可以將預先剖析的內容匯入 Agent Search。請參閱「自備剖析文件」。
剖析器可用性比較
下表列出各剖析器支援的文件檔案類型,以及可偵測和剖析的元素。
| 檔案類型 | 數位剖析器 | PDF 的 OCR 剖析器 | 版面配置剖析器 |
|---|---|---|---|
| HTML | 偵測段落元素 | 不適用 | 偵測段落、表格、圖片、清單、標題和標題元素 |
| 偵測段落 (數位文字) 元素 | 偵測段落元素 | 偵測段落、表格、圖片、標題和標題元素 | |
| DOCX | 偵測段落元素 | 不適用 | 偵測段落、表格、圖片、清單、標題、標題元素 |
| PPTX | 偵測段落元素 | 不適用 | 偵測段落、表格、圖片、清單、標題、標題元素 |
| TXT | 偵測段落元素 | 不適用 | 不適用 |
| XLSX | 偵測段落元素 | 不適用 | 偵測段落、表格、標題、標題元素 |
| XLSM | 偵測段落元素 | 不適用 | 偵測段落、表格、標題、標題元素 |
三種剖析器可匯入的非結構化文件大小上限皆相同。請參閱「為資料進行擷取的準備作業」。
數位剖析器
數位剖析器會從文件中擷取機器可讀的文字。可偵測文字區塊,但無法偵測表格、清單和標題等文件元素。
建立資料儲存庫時,如未指定其他剖析器做為預設,系統會使用數位剖析器。此外,如果指定的剖析器不支援上傳的檔案類型,系統也會使用數位剖析器。舉例來說,如果指定版面配置剖析器,系統會使用數位剖析器剖析 TXT 檔案,因為版面配置剖析器不支援文字檔案。
PDF 的 OCR 剖析器
如果是掃描的 PDF,以及文字屬於圖片一部分的 PDF (例如掃描的文件和含有文字的螢幕截圖等圖片),則適合使用 PDF 專用 OCR 剖析器。如果 PDF 同時包含不可搜尋的文字 (例如掃描文字或資訊圖表) 和機器可讀文字,您可以在指定 OCR 剖析器時,將 useNativeText 欄位設為 true。在這種情況下,機器可讀的文字會與 OCR 剖析輸出內容合併,提升文字擷取品質。
如果 PDF 含有複雜的階層或視覺/表格元件,版面配置剖析器可能會提供更佳結果。
如果您有可搜尋的 PDF 或其他數位格式,且主要由機器可讀的文字組成,通常不需要使用 PDF 的 OCR 剖析器。
OCR 處理功能適用於具有非結構化資料儲存庫的自訂搜尋應用程式。由於 OCR 剖析器僅適用於 PDF 檔案,因此只有擷取的 PDF 檔案會由 OCR 剖析器處理,其他檔案類型則由數位剖析器處理。
OCR 處理器可剖析 PDF 檔案的前 500 頁。超過 500 個上限的網頁不會處理。
版面配置剖析器
Agent Search 可透過版面配置剖析功能,偵測 PDF、HTML、DOCX、PPTX、XLSX 和 XLSM 檔案的版面配置。Agent Search 即可識別文字區塊、資料表和清單等內容元素,以及標題和標頭等結構元素,並使用這些元素定義文件的組織和階層。
您可以為所有檔案類型啟用版面配置剖析功能,也可以指定要為哪些檔案類型啟用。版面配置剖析器會偵測段落、表格和清單等內容元素,以及標題、標頭和註腳等結構元素。
如果您有複雜的非可搜尋 PDF,例如具有複雜階層或表格的掃描 PDF,或圖片中含有文字的 PDF (例如資訊圖表),Google 建議使用版面配置剖析器,而非 OCR 剖析器。
只有在 RAG 使用文件分塊功能時,才能使用版面配置剖析器。啟用文件分塊功能後,Agent Search 會在擷取時將文件分割成多個分塊,並以分塊形式傳回文件。偵測文件版面配置可啟用內容感知分塊,並強化與文件元素相關的搜尋和答案生成功能。如要進一步瞭解如何為 RAG 區塊化文件,請參閱「為 RAG 區塊化文件」。
建立資料儲存庫時,您可以選取下列一或多個版面配置剖析器外掛程式:
圖片註解
如果啟用圖片註解功能,當系統在來源文件中偵測到圖片時,會將圖片說明 (註解) 和圖片本身指派給一個區塊。註解會決定是否要在搜尋結果中傳回區塊。如果生成答案,註解可以做為答案的來源。
版面配置剖析器可偵測下列圖片類型:BMP、GIF、JPEG、PNG 和 TIFF。
如要在版面配置剖析中啟用圖片註解功能,請在建立資料儲存庫時執行下列操作:
- 依序選取「Document processing options」>「Layout parser settings」>「Enable image annotation」。
表格註解
啟用表格註解功能後,如果系統在來源文件中偵測到表格,就會將表格的說明 (註解) 和表格本身指派給一個區塊。註解會決定是否要在搜尋結果中傳回區塊。如果生成答案,註解可以做為答案的來源。
如要在版面配置剖析中啟用表格註解,請在建立資料儲存庫時執行下列操作:
- 依序選取「文件處理選項」>「版面配置剖析器設定」>「啟用表格註解」。
Gemini 版面配置剖析 (公開預先發布版)
如果啟用 Gemini 版面配置剖析功能,Gemini 會對 PDF 檔案進行版面配置分析和內容擷取。這項功能可提供高品質的表格辨識、改善閱讀順序,以及更準確的文字辨識。適用於含有非結構化文件的資料儲存庫。Gemini 剖析器外掛程式可與表格註解外掛程式搭配使用。
如要啟用 Gemini 版面配置剖析功能,請在建立資料儲存庫時執行下列操作:
- 依序選取「Document processing options」>「Layout parser settings」>「Enable Gemini enhancement」。
排除 HTML 內容
使用 HTML 文件的版面配置剖析器時,您可以排除 HTML 內容的特定部分,不進行處理。如要提升搜尋應用程式和 RAG 應用程式的資料品質,可以排除樣板或導覽選單、頁首、頁尾或側欄等部分。
layoutParsingConfig 提供下列欄位:
excludeHtmlElements:要排除的 HTML 標記清單。 系統會排除這些標記中的內容。excludeHtmlClasses:要排除的 HTML 類別屬性清單。包含這些類別屬性的 HTML 元素及其內容都會遭到排除。excludeHtmlIds:要排除的 HTML 元素 ID 屬性清單。系統會排除具有這些 ID 屬性的 HTML 元素及其內容。
指定預設剖析器
建立資料儲存庫時,只要加入 documentProcessingConfig 物件,即可為該資料儲存庫指定預設剖析器。如未加入 documentProcessingConfig.defaultParsingConfig,系統會使用數位剖析器。如果指定的剖析器不適用於某個檔案類型,系統也會使用數位剖析器。
REST
如要指定預設剖析器,請按照下列步驟操作:
使用 API 建立搜尋資料儲存庫時,請在資料儲存庫建立要求中加入
documentProcessingConfig.defaultParsingConfig。您可以指定 OCR 剖析器、版面配置剖析器或數位剖析器:如要指定 OCR 剖析器,請按照下列步驟操作:
"documentProcessingConfig": { "defaultParsingConfig": { "ocrParsingConfig": { "useNativeText": "NATIVE_TEXT_BOOLEAN" } } }NATIVE_TEXT_BOOLEAN為選用項目。只有在擷取 PDF 時,才需要設定這個值。如果設為true,系統會為 OCR 剖析器啟用機器可讀文字處理功能。預設值為false。
如何指定版面配置剖析器:
"documentProcessingConfig": { "defaultParsingConfig": { "layoutParsingConfig": {} } }如要指定數位剖析器,請按照下列步驟操作:
"documentProcessingConfig": { "defaultParsingConfig": { "digitalParsingConfig": {} } }
控制台
透過控制台建立搜尋資料儲存庫時,您可以指定預設剖析器。
範例
以下範例說明如何在建立資料儲存庫時,將 OCR 剖析器指定為預設剖析器。
curl -X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json" \
-H "X-Goog-User-Project: exampleproject" \
"https://discoveryengine.googleapis.com/v1/projects/exampleproject/locations/global/collections/default_collection/dataStores?dataStoreId=datastore123" \
-d '{
"displayName": "exampledatastore",
"industryVertical": "GENERIC",
"solutionTypes": ["SOLUTION_TYPE_SEARCH"],
"contentConfig": "CONTENT_REQUIRED",
"documentProcessingConfig": {
"defaultParsingConfig": {
"ocrParsingConfig": {
"useNativeText": "false"
}
}
}
}'
指定檔案類型的剖析器覆寫設定
您可以指定特定檔案類型 (PDF、HTML、DOCX、PPTX、XLSX 和 XLSM) 應由預設剖析器以外的剖析器剖析。如要這麼做,請在資料儲存庫建立要求中加入 documentProcessingConfig 欄位,並指定覆寫剖析器。如未指定預設剖析器,則預設為數位剖析器。
REST
如要指定特定檔案類型的剖析器覆寫設定,請按照下列步驟操作:
使用 API 建立搜尋資料儲存庫時,請在資料儲存庫建立要求中加入
documentProcessingConfig.defaultParsingConfig。您可以為特定檔案類型指定剖析器:
"documentProcessingConfig": { "parsingConfigOverrides": { "FILE_TYPE": { PARSING_CONFIG }, } }更改下列內容:
FILE_TYPE:可接受的值為pdf、html、docx、pptx、xlsm和xlsx。PARSING_CONFIG:指定要套用至檔案類型的剖析器設定。您可以指定 OCR 剖析器、版面配置剖析器或數位剖析器:如要指定 OCR 剖析器,請按照下列步驟操作:
"ocrParsingConfig": { "useNativeText": "NATIVE_TEXT_BOOLEAN" }NATIVE_TEXT_BOOLEAN:選用。只有在擷取 PDF 時才需要設定。如果設為true,系統會為 OCR 剖析器啟用機器可讀文字處理功能。預設值為false。
如何指定版面配置剖析器:
"layoutParsingConfig": {}如要指定數位剖析器,請按照下列步驟操作:
"documentProcessingConfig": { "defaultParsingConfig": { "digitalParsingConfig": {} } }
控制台
透過控制台建立搜尋資料儲存庫時,您可以為特定檔案類型指定剖析器覆寫設定。
範例
以下範例在建立資料儲存庫時,指定 PDF 檔案應由 OCR 剖析器處理,HTML 檔案則應由版面配置剖析器處理。在這種情況下,數位剖析器會處理 PDF 和 HTML 以外的所有檔案。
curl -X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json" \
-H "X-Goog-User-Project: exampleproject" \
"https://discoveryengine.googleapis.com/v1/projects/exampleproject/locations/global/collections/default_collection/dataStores?dataStoreId=datastore123" \
-d '{
"displayName": "exampledatastore",
"industryVertical": "GENERIC",
"solutionTypes": ["SOLUTION_TYPE_SEARCH"],
"contentConfig": "CONTENT_REQUIRED",
"documentProcessingConfig": {
"parsingConfigOverrides": {
"pdf": {
"ocrParsingConfig": {
"useNativeText": "false"
},
},
"html": {
"layoutParsingConfig": {}
}
}
}
}'
編輯現有資料儲存庫的文件剖析設定
如果您已有資料儲存庫,可以變更預設剖析器,並新增檔案格式例外狀況。不過,更新後的剖析器設定只會套用至匯入資料儲存庫的新文件。資料儲存庫中現有的文件不會使用新設定重新剖析。
如要變更資料儲存庫的文件剖析設定,請按照下列步驟操作:
前往 Google Cloud 控制台的「AI Applications」頁面。
點按導覽選單中的「Data Stores」(資料儲存庫)。
在「Name」(名稱) 欄中,按一下要編輯的資料儲存庫。
在「處理設定」分頁中,編輯「文件剖析」設定。
「Document chunking」(文件分塊) 設定無法變更。如果資料儲存庫未啟用文件分塊功能,就無法選擇版面配置剖析器。
按一下「提交」。
設定版面配置剖析器,排除 HTML 內容
您可以設定版面配置剖析器,在 documentProcessingConfig.defaultParsingConfig.layoutParsingConfig 中指定 excludeHtmlElements、excludeHtmlClasses 或 excludeHtmlIds,排除 HTML 內容。
REST
如要排除特定 HTML 內容,不讓版面配置剖析器處理,請按照下列步驟操作:
使用 API 建立搜尋資料儲存庫時,請在資料儲存庫建立要求中加入
documentProcessingConfig.defaultParsingConfig.layoutParsingConfig。如要排除特定 HTML 代碼類型,請使用:
"documentProcessingConfig": { "defaultParsingConfig": { "layoutParsingConfig": { "excludeHtmlElements": ["HTML_TAG_1","HTML_TAG_2","HTML_TAG_N"] } } }將 HTML_TAG 變數替換為標記名稱,例如
nav和footer。如要排除特定 HTML 元素類別屬性,請使用:
"documentProcessingConfig": { "defaultParsingConfig": { "layoutParsingConfig": { "excludeHtmlClasses": ["HTML_CLASS_1","HTML_CLASS_2","HTML_CLASS_N"] } } }將 HTML_CLASS 變數替換為類別屬性,例如
overlay和screenreader。如要排除特定 HTML 元素 ID 屬性,請使用:
"documentProcessingConfig": { "defaultParsingConfig": { "layoutParsingConfig": { "excludeHtmlIds": ["HTML_ID_1","HTML_ID_2","HTML_ID_N"] } } }將 HTML_ID 變數替換為 ID 屬性,例如
cookie-banner。
範例
這個範例指定當版面配置剖析器處理 HTML 檔案時,剖析器會略過下列項目:
HTML 元素標記:
header、footer、nav和asideoverlays和screenreader類型的 HTML 元素類別屬性屬性 ID 為
cookie-banner的任何元素
curl -X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json" \
-H "X-Goog-User-Project: exampleproject" \
"https://discoveryengine.googleapis.com/v1/projects/exampleproject/locations/global/collections/default_collection/dataStores?dataStoreId=datastore123&createAdvancedSiteSearch=true" \
-d '{
"displayName": "exampledatastore",
"industryVertical": "GENERIC",
"contentConfig": "PUBLIC_WEBSITE",
"documentProcessingConfig": {
"chunkingConfig": {
"layoutBasedChunkingConfig": {}
},
"defaultParsingConfig": {
"layoutParsingConfig": {
"excludeHtmlElements": ["header", "footer", "nav", "aside"],
"excludeHtmlClasses": ["overlays", "screenreader"],
"excludeHtmlIds": ["cookie-banner"]
}
}
}
}'
取得剖析後的 JSON 文件
您可以呼叫 getProcessedDocument 方法,並指定 PARSED_DOCUMENT 做為處理的文件類型,取得 JSON 格式的剖析文件。如果您需要將剖析後的文件上傳至其他位置,或決定使用自備剖析後文件功能,將剖析後的文件重新匯入 Agent Search,則以 JSON 格式取得剖析後的文件會很有幫助。
REST
如要取得剖析後的 JSON 文件,請按照下列步驟操作:
呼叫
getProcessedDocument方法:curl -X GET \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ "https://discoveryengine.googleapis.com/v1alpha/projects/PROJECT_ID/locations/global/collections/default_collection/dataStores/DATA_STORE_ID/branches/0/documents/DOCUMENT_ID:getProcessedDocument?processed_document_type=PARSED_DOCUMENT"更改下列內容:
PROJECT_ID:專案 ID。DATA_STORE_ID:資料儲存庫的 ID。DOCUMENT_ID:要取得的文件 ID。
使用自己的剖析文件
您可以將預先剖析的非結構化文件匯入 Agent Search 資料儲存庫。舉例來說,您可以自行剖析 PDF 並匯入剖析結果,而非匯入原始 PDF 文件。這樣一來,您就能以結構化方式匯入文件,確保搜尋和答案生成功能取得文件版面配置和元素的相關資訊。
剖析後的非結構化文件會以 JSON 表示,並使用一系列文字、表格和清單區塊描述非結構化文件。
事前準備
準備剖析後的文件。
如要將剖析後的文件擷取至非結構化資料儲存庫,每份文件都必須以獨立 JSON 檔案表示,並遵循下列 JSON 結構定義:
| 欄位 | 類型 | 說明 |
|---|---|---|
title |
字串 | 內容檔案的標題。 |
description |
字串 | 選用:文件說明。 |
uri |
字串 | 內容的 Cloud Storage URI。 |
name |
字串 | 選用:文件的完整資源名稱路徑。 |
blocks |
陣列 | 代表文件結構的版面配置區塊已排序的清單。 |
擷取剖析後的非結構化資料
匯入 JSON 檔案和剖析後的非結構化文件資料時,方法與匯入其他類型的非結構化文件 (例如 PDF) 相同。只要上傳 JSON 檔案,且系統在您的中繼資料 JSON Lines 檔案中,透過 application/json MIME 類型或 JSON 副檔名識別該檔案,就會將其視為剖析文件。
如要擷取剖析過的非結構化資料,請按照下列步驟操作:
準備 JSON Lines 中繼資料檔案。
中繼資料檔案的每一列都必須符合 structData 格式:
{ "id": "DOCUMENT_ID", "structData": { "category": "CATEGORY", "updated": "YYYY-MM-DD" }, "content": { "mimeType": "application/json", "uri": "gs://PARSED_DOC_FILE" } }更改下列內容:
DOCUMENT_ID:文件的專屬 ID。CATEGORY:您選擇的文件分類標籤。這個欄位通常用於中繼資料,可用於篩選和分面。YYYY-MM-DD:文件的修改日期。PARSED_DOC_FILE:您在上方「事前準備」中建立的其中一個獨立 JSON 檔案的 Cloud Storage 路徑,例如my_bucket/my_folder/my_file.json。
將資料擷取至新的非結構化資料儲存庫 (建立搜尋資料儲存庫),或現有的資料儲存庫 (重新整理非結構化資料)。
為 RAG 將文件分塊
根據預設,Agent Search 已針對文件檢索進行最佳化,搜尋應用程式會傳回文件,例如 PDF 或網頁,以及每項搜尋結果。
文件分塊功能適用於具有非結構化資料儲存庫的自訂搜尋應用程式。
Agent Search 則可針對 RAG 進行最佳化,讓搜尋應用程式主要用於以自訂資料強化 LLM 輸出內容。啟用文件分塊功能後,Agent Search 會將文件分割成多個區塊。搜尋應用程式可在搜尋結果中傳回相關資料區塊,而非完整文件。使用分塊資料進行 RAG,可提高 LLM 答案的關聯性,並降低 LLM 的運算負載。
如要將 Agent Search 用於 RAG:
限制
區塊劃分有下列限制:
- 資料儲存庫建立後,就無法開啟或關閉文件分塊功能。
- 您可以對已啟用文件分塊功能的資料儲存庫,提出文件搜尋要求,而非分塊搜尋要求。不過,如果資料儲存庫啟用文件分塊功能,則不適合用於傳回文件。系統會將分塊匯總成文件,然後傳回文件。
文件分塊選項
本節說明啟用文件分塊時,需要指定的選項。
建立資料儲存庫時,請開啟下列選項,讓 Agent Search 將文件建立索引為分塊。
依版面配置分塊文件。如要啟用這個選項,請在資料儲存庫建立要求中加入
documentProcessingConfig欄位,並指定ChunkingConfig.LayoutBasedChunkingConfig。啟用版面配置感知文件分塊功能後,Agent Search 會偵測文件的版面配置,並在分塊時納入考量。這可提高語意連貫性,並減少內容用於檢索和 LLM 生成時的雜訊。區塊中的所有文字都會來自相同的版面配置實體,例如標題、子標題和清單。
版面配置剖析。如要啟用這個選項,請在建立資料儲存庫時指定
ParsingConfig.LayoutParsingConfig。版面配置剖析器會偵測 PDF、HTML 和 DOCX 等檔案的版面配置。這項工具會識別文字區塊、表格、清單、標題和標頭等元素,並使用這些元素定義文件的組織和階層。
如要進一步瞭解版面配置剖析,請參閱「版面配置剖析」。
開啟文件分塊功能
如要啟用文件分塊功能,請在資料儲存庫建立要求中加入 documentProcessingConfig 物件,並啟用版面配置感知文件分塊和版面配置剖析功能。
REST
如要啟用文件分塊功能,請按照下列步驟操作:
使用 API 建立搜尋資料儲存庫時,請在資料儲存庫建立要求中加入
documentProcessingConfig.chunkingConfig物件。"documentProcessingConfig": { "chunkingConfig": { "layoutBasedChunkingConfig": { "chunkSize": CHUNK_SIZE_LIMIT, "includeAncestorHeadings": HEADINGS_BOOLEAN, } }, "defaultParsingConfig": { "layoutParsingConfig": {} } }更改下列內容:
CHUNK_SIZE_LIMIT:選用。每個分塊的詞元大小上限。預設值為 500。支援的值為 100 至 500 (含)。HEADINGS_BOOLEAN:選用。決定是否在每個區塊中加入標題。預設值為false。將標題和各層級的標題附加至文件中間的分塊,有助於避免在分塊擷取和排名時遺失脈絡。
控制台
透過控制台建立搜尋資料儲存庫時,可以啟用文件分塊功能。
使用自己的區塊
如果您已自行將文件分塊,可以將這些文件上傳至代理搜尋,而不啟用文件分塊選項。
如要將文件預先分割成多個區塊,每份文件都必須以獨立 JSON 檔案表示,並遵循下列結構定義:
{
"documentMetadata": {
"title": "DOCUMENT_TITLE",
"uri": "gs://ORIGINAL_DOC_FILE"
},
"chunks": [
{
"id": "CHUNK_ID",
"content": "CHUNK_CONTENT",
"pageSpan": {
"pageStart": PAGE_START,
"pageEnd": PAGE_END
}
}
]
}
更改下列內容:
DOCUMENT_TITLE:文件標題。ORIGINAL_DOC_FILE:原始文件檔案的 Cloud Storage 路徑,例如my-bucket-123/my_folder/document.pdf。CHUNK_ID:區塊的專屬 ID。CHUNK_CONTENT:分塊的文字內容。PAGE_START::區塊在原始文件中的起始頁碼 (從 1 開始)。PAGE_END:區塊在原始文件中的結束頁碼 (從 1 開始)。
這項功能沒有明確的啟用切換鈕。上傳符合這個結構定義的 JSON 檔案,並在中繼資料行檔案中,以 application/json MIME 類型或 JSON 副檔名識別該檔案時,系統會自動辨識並擷取該檔案,做為預先分塊的文件。
列出文件的區塊
如要列出特定文件的所有區塊,請呼叫 Chunks.list 方法。
REST
如要列出文件的區塊,請按照下列步驟操作:
呼叫
Chunks.list方法:curl -X GET \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ "https://discoveryengine.googleapis.com/v1alpha/projects/PROJECT_ID/locations/global/collections/default_collection/dataStores/DATA_STORE_ID/branches/0/documents/DOCUMENT_ID/chunks"更改下列內容:
PROJECT_ID:專案 ID。DATA_STORE_ID:資料儲存庫的 ID。DOCUMENT_ID:要列出哪些文件的 chunks。
從處理過的文件取得 JSON 格式的區塊
您可以呼叫 getProcessedDocument 方法,以 JSON 格式取得特定文件的所有區塊。如果您需要將區塊上傳至其他位置,或決定使用自備區塊功能將區塊重新匯入 Agent Search,則以 JSON 格式取得區塊會很有幫助。
REST
如要取得文件的 JSON 區塊,請按照下列步驟操作:
呼叫
getProcessedDocument方法:curl -X GET \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ "https://discoveryengine.googleapis.com/v1alpha/projects/PROJECT_ID/locations/global/collections/default_collection/dataStores/DATA_STORE_ID/branches/0/documents/DOCUMENT_ID:getProcessedDocument?processed_document_type=CHUNKED_DOCUMENT"更改下列內容:
PROJECT_ID:專案 ID。DATA_STORE_ID:資料儲存庫的 ID。DOCUMENT_ID:要取得區塊的文件 ID。
取得特定區塊
如要取得特定區塊,請呼叫 Chunks.get 方法。
REST
如要取得特定區塊,請按照下列步驟操作:
呼叫
Chunks.get方法:curl -X GET \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ "https://discoveryengine.googleapis.com/v1alpha/projects/PROJECT_ID/locations/global/collections/default_collection/dataStores/DATA_STORE_ID/branches/0/documents/DOCUMENT_ID/chunks/CHUNK_ID"更改下列內容:
PROJECT_ID:專案 ID。DATA_STORE_ID:資料儲存庫的 ID。DOCUMENT_ID:區塊來源文件的 ID。CHUNK_ID:要傳回的區塊 ID。
在搜尋要求中傳回區塊
確認資料已正確分塊後,Agent Search 就能在搜尋結果中傳回分塊資料。
回覆會傳回與搜尋查詢相關的區塊。此外,您也可以選擇傳回來源文件中相關 chunk 前後相鄰的 chunk。相鄰的區塊可以增加背景資訊和準確度。
REST
如要取得分塊資料:
提出搜尋要求時,請將
ContentSearchSpec.SearchResultMode指定為chunks。contentSearchSpec": { "searchResultMode": "RESULT_MODE", "chunkSpec": { "numPreviousChunks": NUMBER_OF_PREVIOUS_CHUNKS, "numNextChunks": NUMBER_OF_NEXT_CHUNKS } }RESULT_MODE:決定搜尋結果是以完整文件或片段形式傳回。如要取得資料塊,資料儲存庫必須啟用文件分塊功能。可接受的值為documents和chunks。如果資料儲存庫已啟用文件分塊功能,預設值為chunks。NUMBER_OF_PREVIOUS_CHUNKS:要傳回的區塊數量,這些區塊緊接在相關區塊之前。最大允許值為 5。NUMBER_OF_NEXT_CHUNKS:要傳回的區塊數量,緊接在相關區塊之後。最大值為 5。
範例
下列搜尋查詢要求範例會將 SearchResultMode 設為 chunks、要求一個前一個區塊和一個下一個區塊,並使用 pageSize 將結果數量限制為單一相關區塊。
curl -X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json" \
-H "X-Goog-User-Project: exampleproject" \
"https://discoveryengine.googleapis.com/v1/projects/exampleproject/locations/global/collections/default_collection/dataStores/datastore123/servingConfigs/default_search:search" \
-d '{
"query": "animal",
"pageSize": 1,
"contentSearchSpec": {
"searchResultMode": "CHUNKS",
"chunkSpec": {
"numPreviousChunks": 1,
"numNextChunks": 1
}
}
}'
以下範例顯示範例查詢傳回的回應。回應內容包含相關分塊、前一個和後一個分塊、原始文件的中繼資料,以及每個分塊來源的文件頁面範圍。
回應
{ "results": [ { "chunk": { "name": "projects/961309680810/locations/global/collections/default_collection/dataStores/allie-pdf-adjacent-chunks_1711394998841/branches/0/documents/0d8619f429d7f20b3575b14cd0ad0813/chunks/c17", "id": "c17", "content": "\n# ESS10: Stakeholder Engagement and Information Disclosure\nReaders should also refer to ESS10 and its guidance notes, plus the template available for a stakeholder engagement plan. More detail on stakeholder engagement in projects with risks related to animal health is contained in section 4 below. The type of stakeholders (men and women) that can be engaged by the Borrower as part of the project's environmental and social assessment and project design and implementation are diverse and vary based on the type of intervention. The stakeholders can include: Pastoralists, farmers, herders, women's groups, women farmers, community members, fishermen, youths, etc. Cooperatives members, farmer groups, women's livestock associations, water user associations, community councils, slaughterhouse workers, traders, etc. Veterinarians, para-veterinary professionals, animal health workers, community animal health workers, faculties and students in veterinary colleges, etc. 8 \n# 4. Good Practice in Animal Health Risk Assessment and Management\n\n# Approach\nRisk assessment provides the transparent, adequate and objective evaluation needed by interested parties to make decisions on health-related risks associated with project activities involving live animals. As the ESF requires, it is conducted throughout the project cycle, to provide or indicate likelihood and impact of a given hazard, identify factors that shape the risk, and find proportionate and appropriate management options. The level of risk may be reduced by mitigation measures, such as infrastructure (e.g., diagnostic laboratories, border control posts, quarantine stations), codes of practice (e.g., good animal husbandry practices, on-farm biosecurity, quarantine, vaccination), policies and regulations (e.g., rules for importing live animals, ban on growth hormones and promotors, feed standards, distance required between farms, vaccination), institutional capacity (e.g., veterinary services, surveillance and monitoring), changes in individual behavior (e.g., hygiene, hand washing, care for animals). Annex 2 provides examples of mitigation practices. This list is not an exhaustive one but a compendium of most practiced interventions and activities. The cited measures should take into account social, economic, as well as cultural, gender and occupational aspects, and other factors that may affect the acceptability of mitigation practices by project beneficiaries and other stakeholders. Risk assessment is reviewed and updated through the project cycle (for example to take into account increased trade and travel connectivity between rural and urban settings and how this may affect risks of disease occurrence and/or outbreak). Projects monitor changes in risks (likelihood and impact) by using data, triggers or indicators. ", "documentMetadata": { "uri": "gs://table_eval_set/pdf/worldbank/AnimalHealthGoodPracticeNote.pdf", "title": "AnimalHealthGoodPracticeNote" }, "pageSpan": { "pageStart": 14, "pageEnd": 15 }, "chunkMetadata": { "previousChunks": [ { "name": "projects/961309680810/locations/global/collections/default_collection/dataStores/allie-pdf-adjacent-chunks_1711394998841/branches/0/documents/0d8619f429d7f20b3575b14cd0ad0813/chunks/c16", "id": "c16", "content": "\n# ESS6: Biodiversity Conservation and Sustainable Management of Living Natural Resources\nThe risks associated with livestock interventions under ESS6 include animal welfare (in relation to housing, transport, and slaughter); diffusion of pathogens from domestic animals to wildlife, with risks for endemic species and biodiversity (e.g., sheep and goat plague in Mongolia affecting the saiga, an endemic species of wild antelope); the introduction of new breeds with potential risk of introducing exotic or new diseases; and the release of new species that are not endemic with competitive advantage, potentially putting endemic species at risk of extinction. Animal welfare relates to how an animal is coping with the conditions in which it lives. An animal is in a good state of welfare if it is healthy, comfortable, well nourished, safe, able to express innate behavior, 7 Good Practice Note - Animal Health and related risks and is not suffering from unpleasant states such as pain, fear or distress. Good animal welfare requires appropriate animal care, disease prevention and veterinary treatment; appropriate shelter, management and nutrition; humane handling, slaughter or culling. The OIE provides standards for animal welfare on farms, during transport and at the time of slaughter, for their welfare and for purposes of disease control, in its Terrestrial and Aquatic Codes. The 2014 IFC Good Practice Note: Improving Animal Welfare in Livestock Operations is another example of practical guidance provided to development practitioners for implementation in investments and operations. Pastoralists rely heavily on livestock as a source of food, income and social status. Emergency projects to restock the herds of pastoralists affected by drought, disease or other natural disaster should pay particular attention to animal welfare (in terms of transport, access to water, feed, and animal health) to avoid potential disease transmission and ensure humane treatment of animals. Restocking also entails assessing the assets of pastoralists and their ability to maintain livestock in good conditions (access to pasture and water, social relationship, technical knowledge, etc.). Pastoralist communities also need to be engaged by the project to determine the type of animals and breed and the minimum herd size to be considered for restocking. \n# Box 5. Safeguarding the welfare of animals and related risks in project activities\nIn Haiti, the RESEPAG project (Relaunching Agriculture: Strengthening Agriculture Public Services) financed housing for goats and provided technical recommendations for improving their welfare, which is critical to avoid the respiratory infections, including pneumonia, that are serious diseases for goats. To prevent these diseases, requires optimal sanitation and air quality in herd housing. This involves ensuring that buildings have adequate ventilation and dust levels are reduced to minimize the opportunity for infection. Good nutrition, water and minerals are also needed to support the goats immune function. The project paid particular attention to: (i) housing design to ensure good ventilation; (ii) locating housing close to water sources and away from human habitation and noisy areas; (iii) providing mineral blocks for micronutrients; (iv) ensuring availability of drinking water and clean food troughs. ", "documentMetadata": { "uri": "gs://table_eval_set/pdf/worldbank/AnimalHealthGoodPracticeNote.pdf", "title": "AnimalHealthGoodPracticeNote" }, "pageSpan": { "pageStart": 13, "pageEnd": 14 } } ], "nextChunks": [ { "name": "projects/961309680810/locations/global/collections/default_collection/dataStores/allie-pdf-adjacent-chunks_1711394998841/branches/0/documents/0d8619f429d7f20b3575b14cd0ad0813/chunks/c18", "id": "c18", "content": "\n# Scoping of risks\nEarly scoping of risks related to animal health informs decisions to initiate more comprehensive risk assessment according to the type of livestock interventions and activities. It can be based on the following considerations: • • • • Type of livestock interventions supported by the project (such as expansion of feed resources, improvement of animal genetics, construction/upgrading and management of post-farm-gate facilities, etc. See also Annex 2); Geographic scope and scale of the livestock interventions; Human and animal populations that are likely to be affected (farmers, women, children, domestic animals, wildlife, etc.); and Changes in the project or project context (such as emerging disease outbreak, extreme weather or climatic conditions) that would require a re-assessment of risk levels, mitigation measures and their likely effect on risk reduction. Scenario planning can also help to identify project-specific vulnerabilities, country-wide or locally, and help shape pragmatic analyses that address single or multiple hazards. In this process, some populations may be identified as having disproportionate exposure or vulnerability to certain risks because of occupation, gender, age, cultural or religious affiliation, socio-economic or health status. For example, women and children may be the main caretakers of livestock in the case of 9 Good Practice Note - Animal Health and related risks household farming, which puts them into close contact with animals and animal products. In farms and slaughterhouses, workers and veterinarians are particularly exposed, as they may be in direct contact with sick animals (see Box 2 for an illustration). Fragility, conflict, and violence (FCV) can exacerbate risk, in terms of likelihood and impact. Migrants new to a geographic area may be immunologically naïve to endemic zoonotic diseases or they may inadvertently introduce exotic diseases; and refugees or internally displaced populations may have high population density with limited infrastructure, leaving them vulnerable to disease exposure. Factors such as lack of access to sanitation, hygiene, housing, and health and veterinary services may also affect disease prevalence, contributing to perpetuation of poverty in some populations. Risk assessment should identify populations at risk and prioritize vulnerable populations and circumstances where risks may be increased. It should be noted that activities that seem minor can still have major consequences. See Box 6 for an example illustrating how such small interventions in a project may have large-scale consequences. It highlights the need for risk assessment, even for simple livestock interventions and activities, and how this can help during the project cycle (from concept to implementation). ", "documentMetadata": { "uri": "gs://table_eval_set/pdf/worldbank/AnimalHealthGoodPracticeNote.pdf", "title": "AnimalHealthGoodPracticeNote" }, "pageSpan": { "pageStart": 15, "pageEnd": 16 } } ] } } } ], "totalSize": 61, "attributionToken": "jwHwjgoMCICPjbAGEISp2J0BEiQ2NjAzMmZhYS0wMDAwLTJjYzEtYWQxYS1hYzNlYjE0Mzc2MTQiB0dFTkVSSUMqUMLwnhXb7Ygtq8SKLa3Eii3d7Ygtj_enIqOAlyLm7Ygtt7eMLduPmiKN96cijr6dFcXL8xfdj5oi9-yILdSynRWCspoi-eyILYCymiLk7Ygt", "nextPageToken": "ANxYzNzQTMiV2MjFWLhFDZh1SMjNmMtADMwATL5EmZyMDM2YDJaMQv3yagQYAsciPgIwgExEgC", "guidedSearchResult": {}, "summary": {} }