經過調整的搜尋模型可提供比基礎搜尋模型更優質的結果。
如有產業或公司專屬查詢,一般 LLM 無法妥善處理,就特別適合使用搜尋調整功能。可用於進一步訓練搜尋模型。
限制
搜尋調整功能只能套用至非結構化資料儲存庫。
關於訓練資料
如要調整搜尋模型,請先彙整訓練資料。
訓練資料應包含您預期使用者會提出的查詢,以及 250 到 500 個字元的文字片段,其中包含回答查詢所需的相關資訊。只要每個摘要都包含可回答查詢的資訊,查詢就能與多個摘要建立關聯。
訓練資料也應包含不與查詢配對的文字片段,但在風格和長度上與答案相似。這些沒有關聯查詢的片段會提供隨機負面資料,以便調整模型。Google 建議您提供至少 10,000 個這類程式碼片段。
以下是一些術語,說明您需要提供的訓練資料:
訓練查詢:您預期使用者會提出的查詢。請務必聚焦於含有特定領域或公司術語的查詢。
請至少提供 100 個。
摘錄片段:摘錄片段 (通常是多個段落) 必須逐字從資料儲存庫中的文件中擷取。資料儲存庫中的所有文件統稱為「語料庫」。
您必須提供兩種類型的擷取片段:
包含回答訓練查詢所需相關資訊的片段。這些區隔與查詢相符。
未與任何訓練查詢建立關聯的區段。這些區隔會在模型調整期間用作隨機負面資料。
一兩句話的長度不足以做為擷取片段,因為片段必須包含足夠的訓練背景資訊。舉例來說,如果要回應「誰創立了 Google」這類查詢,只提供「Larry Page」這類簡短的摘要是不夠的。如需足夠長的片段範例,請參閱下表的範例。
每個查詢至少提供一個擷取片段,以及至少 10,000 個額外的擷取片段。
關聯度分數:關聯度分數是用來估算擷取區段與查詢的關聯程度的非負整數。您必須為每個查詢和擷取片段組合提供分數值。分數為 0 表示擷取區段與查詢完全無關。分數大於零表示有一定程度的相關性。針對簡單評分,Google 建議為所有相關區隔給予 1 分,非相關區隔則給予 0 分。或者,如果您想依關聯程度排序,可以將關聯分數設為 0 到 10 分 (例如),其中 10 分代表最相關的區段,0 分代表完全不相關的區段。
提供至少 100 個相關分數,並視需要提供其他非相關分數。
查詢和擷取片段配對的範例
下表列出一些查詢和擷取片段組合範例。以下是維基百科的一般範例。不過,為了進行實用的調整,您需要提供專屬資料集的文件,其中包含您業務的專屬資訊,且不容易在網路上找到。
本表中的最後一組為零分對應項目的範例,其中答案與查詢無關。
訓練查詢 | 擷取區段 | 分數 |
---|---|---|
誰創立了 Google? | Google 由美國電腦科學家 Larry Page 和 Sergey Brin 於 1998 年 9 月 4 日共同創立,當時兩人都是加州史丹佛大學的博士生。他們共同擁有 Google 約 14% 的公開上市股票,並透過超級表決權股票控制 56% 的股東投票權。該公司於 2004 年透過首次公開募股 (IPO) 上市。2015 年,Google 進行重組,成為 Alphabet Inc. 的百分之百子公司。Google 是 Alphabet 旗下規模最大的子公司,也是 Alphabet 網路資產和權益的控股公司。Sundar Pichai 於 2015 年 10 月 24 日獲任命為 Google 執行長,接替 Larry Page 的職位,後者則成為 Alphabet 執行長。2019 年 12 月 3 日,Pichai 也成為 Alphabet 的執行長。[...] 在最有價值品牌清單中,Google 在《Forbes》和《Interbrand》的排名分別為第二和第四。 | 1 |
血液離開右心室後會流向哪裡? | 含氧血會透過肺靜脈離開肺部,然後返回心臟左側,完成肺部循環。這股血液隨後會進入左心房,再經由二尖瓣泵送至左心室。從左心室開始,血液會經過主動脈瓣進入主動脈。接著,血液會透過全身循環分布到身體,然後再次回到肺循環。動脈 主要文章:肺動脈 從右心室開始,血液會經由半月形肺動脈瓣膜泵入左、右主肺動脈 (每個肺一個),再分支成較小的肺動脈,散布至肺部。[...] 心臟分流是指心臟部位之間的非自然連結,導致血液流動時會繞過肺部。 | 1 |
保齡球名人堂位於何處? | 世界保齡球作家協會 ( WBW) 國際保齡球名人堂於 1993 年成立,位於德州阿靈頓的國際保齡球校區內,隸屬於國際保齡博物館和名人堂。歷史:國際保齡球博物館和名人堂位於美國密蘇里州聖路易的 11 Stadium Plaza,與聖路易紅雀名人堂博物館共用同一棟建築,直到 2008 年 11 月 8 日。後來遷移到阿靈頓,並於 2010 年初重新開幕。2012 年,WBW 與國際保齡球媒體協會 (International Bowling Media Association) 合併。合併後,WBW 名人堂入選者將成為 IBMA Luby 名人堂的一員。] 世界保齡球作家協會 (World Bowling Writers) 的官員,他們組成了名人堂的董事會。][...] 獲選者為獲得最多票數的男女選手。 | 1 |
為什麼天空是藍色的? | 「Hello, World!」程式通常是簡單的電腦程式,會在螢幕 (通常是主控台) 上輸出 (或顯示) 類似「Hello, World!」的訊息,同時忽略任何使用者輸入內容。這是大多數通用程式設計語言中的一小段程式碼,用於說明語言的基本語法。「Hello, World!」程式通常是新程式語言的學生所寫的第一個程式,但這類程式也可以用於檢查,確保用於編譯或執行原始程式碼的電腦軟體已正確安裝,且操作人員瞭解如何使用該軟體。[...] C 語言版本是由 Kernighan 在 1972 年撰寫的「A Tutorial Introduction to the Language B」所提及,其中第一個已知的程式版本,是在用來說明外部變數的範例中找到 | 0 |
關於測試
訓練完成後,系統會測試經過調整的搜尋,判斷調整是否改善了結果。您可以明確提供要測試的查詢。如果您未提供測試查詢,Vertex AI Search 會使用 20% 的訓練查詢做為測試查詢。
訓練用檔案
訓練資料必須以三個 (選填四個) 特定檔案上傳:
三個訓練檔案 (字元集檔案、查詢檔案和訓練標籤檔案) 和 (選用) 測試標籤檔案必須儲存在 Cloud Storage 中。檔案路徑是由 trainCustomMethod
呼叫中的欄位定義。
語料庫檔案
詞彙庫檔案包含擷取片段:片段包含可用於回答查詢檔案中查詢的資訊,以及許多用於在調整模型時用作隨機負面資料的額外片段。您至少應有 100 個包含查詢答案的區隔,且查詢可由多個區隔回答。您也應至少有 10,000 個隨機區段。
如果資料儲存庫中的文件含有 500 個字詞以下,您可以使用整份文件做為片段。否則,請透過程式輔助方式從資料儲存庫中的文件隨機建立 250 至 500 個字的片段,然後將這些片段新增至字元集檔案。
詞庫檔案是 JSONL (JSON 行) 檔案,其中每行都有欄位 _id
和 text
,其中包含字串值。例如:
{"_id": "doc1", "text": "Google was founded on September 4, 1998, by American computer scientists Larry Page and Sergey Brin while they were PhD students at Stanford University in California. Together they own about 14% of its publicly listed shares and control 56% of its stockholder voting power through super-voting stock. The company went public via an initial public offering (IPO) in 2004. In 2015, Google was reorganized as a wholly owned subsidiary of Alphabet Inc. Google is Alphabet's largest subsidiary and is a holding company for Alphabet's internet properties and interests. Sundar Pichai was appointed CEO of Google on October 24, 2015, replacing Larry Page, who became the CEO of Alphabet. On December 3, 2019, Pichai also became the CEO of Alphabet. [...] On the list of most valuable brands, Google is 105 ranked second by Forbes and fourth by Interbrand."}
{"_id": "doc2", "text": "Oxygenated blood leaves the lungs through pulmonary veins, which return it to the left part of the heart, completing the pulmonary cycle. This blood then enters the left atrium, which pumps it through the mitral valve into the left ventricle. From the left ventricle, the blood passes through the aortic valve to the aorta. The blood is then distributed to the body through the systemic circulation before returning again to the pulmonary circulation. Arteries Main article: Pulmonary artery From the right ventricle, blood is pumped through the semilunar pulmonary valve into the left and right main pulmonary artery (one for each lung), which branch into smaller pulmonary arteries that spread throughout the lungs. [...] Cardiac shunt is an unnatural connection between parts of the heart that leads to blood flow that bypasses the lungs."}
{"_id": "doc3", "text": "The World Bowling Writers ( WBW ) International Bowling Hall of Fame was established in 1993 and is located in the International Bowling Museum and Hall of Fame , on the International Bowling Campus in Arlington , Texas. History The International Bowling Museum and Hall of Fame was located at 11 Stadium Plaza, St. Louis, Missouri, USA, and shared the same building with the St. Louis Cardinals Hall of Fame Museum, until November 8, 2008. It moved to Arlington and reopened in early 2010. In 2012, the WBW was merged with the International Bowling Media Association. After the merger, the WBW Hall of Fame inductees became part of the IBMA Luby Hall of Fame. officers of the World Bowling Writers, which formed the Hall's Board.][...] The man and woman who receive the most votes are elected."}
{"_id": "doc4", "text": "A \"Hello, World!\" program is generally a simple computer program which outputs (or displays) to the screen (often the console) a message similar to "Hello, World!" while ignoring any user input. A small piece of code in most general-purpose programming languages, this program is used to illustrate a language's basic syntax. A "Hello, World!" program is often the first written by a student of a new programming language, but such a program can also be used as a check to ensure that the computer software intended to compile or run source code is correctly installed, and that its operator understands how to use it. [...] The C-language version was preceded by Kernighan's own 1972 A Tutorial Introduction to the Language B, where the first known version of the program is found in an example used to illustrate external variables."}
檔案大小上限為 500,000 行。
查詢檔案
查詢檔案包含用於調整模型的查詢範例。每個查詢都應在詞彙庫檔案中提供一或多個對應的擷取片段。您應提供至少 100 個正比對查詢。您也可以提供不相關的查詢:這些查詢對應的擷取區隔與相關度分數為零。
查詢檔案採用 JSONL 格式,欄位與字典檔案相同。
例如:
{"_id": "query1", "text": "who founded Google?"}
{"_id": "query2", "text": "where is blood pumped after it leaves the right ventricle?"}
{"_id": "query3", "text": "where is the bowling hall of fame located?"}
{"_id": "query4", "text": "why is the sky blue?"}
檔案中允許的查詢數量上限為 40,000 個。
訓練標籤
訓練標籤檔案會將查詢與擷取片段連結,並為每個查詢和片段配對評分。
如果沒有測試標籤檔案,訓練標籤檔案中的 20% 查詢會保留用於評估訓練後的調整模型。
這個檔案包含查詢 ID 和相符 (或不相符) 的擷取片段 ID,以及片段與查詢的關聯度分數。每個查詢至少要有一個資料列;如果有兩個區段回答查詢,則該查詢會有兩個資料列。Score
是整數值,但不得為負數。分數大於零,表示文件與查詢相關。數字越大,表示關聯性越高。如果省略分數,則預設值為 1。
訓練標籤檔案是含有標頭的 TSV (定位點分隔值) 檔案。檔案必須含有 query-id
、corpus-id
和 score
欄。query-id
是與查詢檔案中的 _id
鍵相符的字串,而 corpus-id
是與字庫檔案中的 _id
相符的字串。
例如:
query-id corpus-id score
query1 doc1 1
query2 doc2 1
query3 doc3 1
query3 doc9 1
query4 doc4 0
訓練標籤檔案中至少須包含 100 個不重複的查詢 ID。訓練標籤檔案中的查詢 ID 數量加上測試標籤檔案中的查詢數量,不得超過 500,000 個。
測試標籤
與訓練標籤檔案一樣,這個選用檔案包含查詢 ID 和擷取片段與關聯分數。與訓練標籤檔案相比,這類檔案包含較少且不同的查詢。如果有,系統會使用檔案中的查詢和擷取片段組合來評估調整結果。如果沒有測試標籤檔案,系統會使用訓練標籤檔案中的查詢和擷取片段組合進行評估。
這個檔案的格式與訓練標籤檔案相同。
例如:
query-id corpus-id score
query200 doc200 1
query201 doc201 1
query202 doc202 1
雖然測試標籤檔案並非必要,但如果您提供此檔案,則檔案中必須包含至少三個不重複的查詢 ID。
事前準備
為應用程式啟用 Enterprise 版功能。
調整搜尋
如要使用自己的訓練資料調整搜尋模型,請按照下列步驟操作。
控制台
如要使用 Google Cloud 控制台調整模型,請按照下列步驟操作:
準備訓練資料,以及選用的測試資料檔案。請使用「訓練檔案」一節所述的格式。
將檔案上傳至 Cloud Storage。
前往 Google Cloud 控制台的「AI Applications」頁面。
在「Apps」頁面中,按一下要訓練模型的應用程式名稱。
在導覽選單中,按一下「Configurations」(設定)。
按一下「調整」分頁標籤。
按一下「調整基礎模型」。
指定您在前面步驟 1 和 2 中準備的詞彙庫、查詢、訓練和 (選用) 測試檔案。
按一下「Start Tuning」。
重新整理頁面,即可在「Tuning」分頁的「Recent tuning activity」表格中查看狀態。
REST
如要使用 trainCustomModel
方法調整資料儲存庫,請按照下列步驟操作:
準備訓練資料 (以及選用的測試資料) 檔案。請使用「訓練檔案」一節所述的格式。
將檔案放入 Cloud Storage 值區。
執行下列 curl 指令,將 Cloud Storage 值區中的檔案上傳至 Vertex AI 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:trainCustomModel" \ -d '{ "gcsTrainingInput": { "corpusDataPath": "CORPUS_JSONL_GCS_PATH", "queryDataPath": "QUERY_JSONL_GCS_PATH", "trainDataPath": "TRAIN_TSV_GCS_PATH", "testDataPath": "TEST_TSV_GCS_PATH" }, "modelType": "search-tuning" }'
更改下列內容:
PROJECT_ID
: Google Cloud 專案的 ID。DATA_STORE_ID
:要調整的資料儲存庫 ID。CORPUS_JSONL_GCS_PATH
:Cloud Storage 中的字元集 JSONL 檔案路徑,例如gs://my-bucket/corpus.jsonl
。QUERY_JSONL_GCS_PATH
:Cloud Storage 中的查詢 JSONL 檔案路徑,例如gs://my-bucket/query.jsonl
。TRAIN_TSV_GCS_PATH
:Cloud Storage 中的訓練標籤 TSV 檔案路徑,例如gs://my-bucket/train.tsv
。TEST_TSV_GCS_PATH
:選用欄位,可指定測試標籤 TSV 檔案的 Cloud Storage 路徑,例如gs://my-bucket/test.tsv
。如果沒有測試標籤檔案,請移除testDataPath
欄位或將其留空。
如需此方法的一般資訊,請參閱
trainCustomModel
。上傳資料檔案後,系統就會自動開始調整。
按一下即可查看 curl 指令和回應範例。
curl -X POST -H "Authorization: Bearer $(gcloud auth print-access-token)" -H "Content-Type: application/json" "https://discoveryengine.googleapis.com/v1/projects/12345/locations/global/collections/default_collection/dataStores/my-data-store_4321:trainCustomModel" -d '{ "dataStore": "projects/12345/locations/global/collections/default_collection/dataStores/my-data-store_4321", "gcsTrainingInput": { "corpusDataPath": "gs://my-bucket/corpus.jsonl", "queryDataPath": "gs://my-bucket/query.jsonl", "trainDataPath": "gs://my-bucket/train.tsv" }, "modelType": "search-tuning" }
{ "name": "projects/12345/locations/global/collections/default_collection/dataStores/my-data-store_4321/operations/train-custom-model-6071430366161939774", "metadata": { "@type": "type.googleapis.com/google.cloud.discoveryengine.v1.TrainCustomModelMetadata" }, "response": { "@type": "type.googleapis.com/google.cloud.discoveryengine.v1.TrainCustomModelResponse", "modelStatus": "in-progress" } }
請記下
trainCustomModel
方法傳回的name
值,然後按照「取得長時間執行作業的詳細資料」中的指示,查看搜尋調校作業何時完成。
Python
詳情請參閱 AI Applications Python API 參考說明文件。
如要向 AI Applications 進行驗證,請設定應用程式預設憑證。詳情請參閱「為本機開發環境設定驗證機制」。
測試並使用經過調整的搜尋功能,針對個別搜尋查詢使用
調整完成後,您可以測試調整後的模型,比較使用該模型執行查詢的結果,以及使用基礎模型執行相同查詢的結果。
控制台
如要使用 Google Cloud 控制台預覽經過調整的模型行為,請按照下列步驟操作:
前往「調整」分頁:
前往 Google Cloud 控制台的「AI Applications」頁面。
按一下要預覽的應用程式名稱。
按一下 [Configurations]。
按一下「調整」分頁標籤。
按一下「調整後的模型」,然後使用右側的預覽面板,建立使用調整後模型的查詢。
按一下「基本模型」,然後使用右側的預覽面板,使用原始模型提出查詢。
比較結果的品質。
REST
如要評估調整效果,您可以將 enableSearchAdaptor
欄位設為 true
,然後再設為 false
,並比較結果。將 enableSearchAdaptor
欄位設為 true
,表示系統會為該查詢使用經過調整的搜尋版本。
如要使用經過調整的模型進行搜尋查詢,請按照下列步驟操作:
在查詢方法呼叫中,將
customFineTuningSpec
欄位的enableSearchAdaptor
欄位設為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/engines/APP_ID/servingConfigs/default_search:search" \ -d '{ "query": "QUERY", "customFineTuningSpec": { "enableSearchAdaptor": true } }'
更改下列內容:
PROJECT_ID
: Google Cloud 專案的 ID。APP_ID
:要查詢的應用程式 ID。
如要進一步瞭解搜尋查詢,請參閱「取得搜尋結果」和 servingConfigs.search
方法。
Python
詳情請參閱 AI Applications Python API 參考說明文件。
如要向 AI Applications 進行驗證,請設定應用程式預設憑證。詳情請參閱「為本機開發環境設定驗證機制」。
開啟精準搜尋
測試完經過調整的搜尋功能,並決定要將其用於所有搜尋查詢後,您可以將其設為預設搜尋模型。
控制台
如要將經過調整的模型設為預設模型,並套用至主要預覽頁面、小工具和 API 呼叫,請按照下列步驟操作:
前往「調整」分頁:
前往 Google Cloud 控制台的「AI Applications」頁面。
按一下應用程式名稱。
按一下 [Configurations]。
按一下「調整」分頁標籤。
按一下「調整後的模型」。
按一下 [發布]。
REST
將調整過的模型設為預設模型時,您不需要在搜尋查詢中指定 customFineTuningSpec
欄位,如同前述程序所示。
如要預設使用經過調整的搜尋版本進行所有搜尋查詢,請按照下列步驟操作:
如要將經過調整的搜尋設為預設模型,請執行下列 curl 指令:
curl -X PATCH \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ -H "Content-Type: application/json" \ -H "X-Goog-User-Project: PROJECT_ID" \ "https://discoveryengine.googleapis.com/v1/projects/PROJECT_ID/locations/global/collections/default_collection/engines/APP_ID/servingConfigs/default_search?updateMask=customFineTuningSpec.enableSearchAdaptor" \ -d '{ "customFineTuningSpec": { "enableSearchAdaptor": true } }'
如需此方法的一般資訊,請參閱
servingConfigs.patch
。
Python
詳情請參閱 AI Applications Python API 參考說明文件。
如要向 AI Applications 進行驗證,請設定應用程式預設憑證。詳情請參閱「為本機開發環境設定驗證機制」。
關閉精選搜尋
如果您不想再使用經過調整的搜尋功能,例如發現結果並未比調整前好,甚至更糟,則可以停用經過調整的搜尋功能。
控制台
如要恢復使用基礎模型做為預設模型,請按照下列步驟操作:
前往「調整」分頁:
前往 Google Cloud 控制台的「AI Applications」頁面。
按一下應用程式名稱。
按一下 [Configurations]。
按一下「調整」分頁標籤。
按一下「Base model」。
按一下 [發布]。
REST
如要停止使用經過調整的模型,請執行與前一個類似的 curl 呼叫,但將 enableSearchAdaptor
設為 false
:
執行下列 curl 指令:
curl -X PATCH \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ -H "Content-Type: application/json" \ -H "X-Goog-User-Project: PROJECT_ID" \ "https://discoveryengine.googleapis.com/v1/projects/PROJECT_ID/locations/global/collections/default_collection/engines/APP_ID/servingConfigs/default_search?updateMask=customFineTuningSpec.enableSearchAdaptor" \ -d '{ "customFineTuningSpec": { "enableSearchAdaptor": false } }'
如需此方法的一般資訊,請參閱
servingConfigs.patch
。
Python
詳情請參閱 AI Applications Python API 參考說明文件。
如要向 AI Applications 進行驗證,請設定應用程式預設憑證。詳情請參閱「為本機開發環境設定驗證機制」。
後續步驟
- 如要瞭解搜尋調整對搜尋品質的影響,請評估搜尋品質。詳情請參閱「評估搜尋品質」。