Agent Retrieval (舊稱 向量搜尋 2.0) 提供 VertexRanker,可進行語意重新排名,這項功能由 Ranking API 支援。
Agent Retrieval 擷取並融合候選結果 (使用倒數排名融合 (RRF) 技術) 後,VertexRanker 會使用專屬語意模型,根據自然語言查詢重新評估合併的候選結果。這項功能可提升前 k 項結果的關聯性,特別是搜尋功能無法掌握細微差異的查詢。系統會在伺服器端重新排序,並呼叫 BatchSearchDataObjects。不需要額外的用戶端連線或額外的來回行程。
VertexRanker
VertexRanker 會設為 BatchSearchDataObjectsRequest 物件 combine.ranker 欄位的重新排序工具。您必須設定主要排序器 (僅支援 RRF)。重新排序器會在 RRF 融合步驟後執行,並以語意重新評分的清單取代輸出內容。
下表列出排序器設定欄位。
| 欄位 | 必填 | 說明 |
|---|---|---|
combine.ranker.rrf.weights |
是 | 基礎搜尋結果 RRF 融合的權重。 |
combine.ranker.vertex_ranker.model |
是 | 排名模型名稱。支援的值:semantic-ranker-fast@latest、semantic-ranker-default@latest、semantic-ranker-fast-004、semantic-ranker-default-004。如要瞭解各項模型,請參閱「排名 API 模型」。 |
combine.ranker.vertex_ranker.top_n |
是 | 要從合併清單傳送至排序器的候選人數量上限。有效值介於 1 到 1000 之間。 |
combine.ranker.vertex_ranker.text_record_spec.query |
是 | 排序器用來為記錄評分的自然語言查詢。 |
combine.ranker.vertex_ranker.text_record_spec.title_template |
是 | 範本字串 (例如 {title}),用於指定如何為每筆記錄擷取 (建構) 標題。使用點路徑指定資料欄位。 |
combine.ranker.vertex_ranker.text_record_spec.content_template |
是 | 範本字串,例如 {body.text},指定如何為每筆記錄擷取 (建構) 主要內容。使用點路徑指定資料欄位。 |
combine.top_k |
選用 | 重新排序後要傳回的最終結果數。這個值必須小於或等於 vertex_ranker.top_n,且小於或等於 1000。 |
以下範例說明要求主體。
{
"searches": [
{ "semantic_search": { "search_text": "running shoes", "search_field": "embedding", "task_type": "RETRIEVAL_QUERY", "top_k": 50 } },
{ "text_search": { "search_text": "running shoes", "data_field_names": ["title"], "top_k": 50 } }
],
"combine": {
"top_k": 10,
"ranker": {
"rrf": { "weights": [1.0, 1.0] },
"vertex_ranker": {
"model": "semantic-ranker-fast@latest",
"top_n": 50,
"text_record_spec": {
"query": "running shoes",
"title_template": "{title}",
"content_template": "{body.text}"
}
}
}
}
}
範本會使用點路徑前往資料物件資料欄位,例如 {title} 或 {nested.field}。這些欄位必須存在於集合架構中,否則驗證時會拒絕要求。如果資料物件缺少提供的欄位,伺服器會從儲存空間重新擷取完整記錄,因此範本仍可填入資料。
配額和價格
Agent Retrieval 的 VertexRanker 會提供免費方案配額,並根據用量收取超額費用。每個專案在每 30 天週期內,都會獲得免費的排名使用量配額。只要用量未超出配額,就不會產生任何費用。如果用量超出此額度,消費者專案將適用標準 Ranking API 定價。
下表列出配額值。
| 項目 | 值 |
|---|---|
| 免費方案配額 | 每個消費者專案每 30 天可使用 80,000 個排名單位。 |
| 超額用量 | 消費者專案會按照標準 Ranking API 定價計費。 |
| 每次重新排序呼叫的記錄數量上限 | 1000 (top_n 必須介於 [1, 1000] 和 top_k 之間,且 top_k <= top_n)。 |
達到免費層級配額不會導致要求失敗。用完 80,000 個排序單位的配額後,後續的 VertexRanker 使用量仍可順利執行,但會以超額用量計費。配額會在首次使用後的 30 天重設。
系統會根據傳送至排序器的記錄數量,以及標題和內容範本的大小,計算排序單元,並採用與獨立 Ranking API 相同的會計方式。詳情請參閱「排名 API 定價」。
如要使用 VertexRanker,必須先在消費者專案中啟用 Discovery Engine。詳情請參閱「失敗條件」。
故障處理和警告
VertexRanker 會盡可能重新排序。如果排名呼叫失敗,BatchSearchDataObjects RPC 仍會成功,並傳回截斷至 top_k 的 RRF 融合結果。回應中的 search_response_metadata.warnings 欄位會回報失敗情形。系統會保留 Ranking API 的完整狀態碼。非預期狀態的警告代碼為
UNAVAILABLE,警告訊息為:
"Reranking is temporarily unavailable. Returning fused (RRF) results without
semantic reranking."
失敗條件
在下列情況下,整個 BatchSearchDataObjects RPC 會失敗,且不會回溯至 RRF。FAILED_PRECONDITION
- 未啟用 Discovery Engine API - Ranking API 會傳回
FAILED_PRECONDITION,並顯示訊息Discovery Engine API is not enabled for the consumer project /<N/>. Please enable the API and try again."。解決方法:在消費者專案中啟用 Discovery Engine API。
消費者專案必須啟用 Discovery Engine,才能重新排序。
下表列出警告代碼、產生警告的常見原因,以及說明警告的訊息。
| 警告代碼 | 常見原因 | 警告訊息 |
|---|---|---|
RESOURCE_EXHAUSTED |
消費者專案超出 Ranking API 配額。注意:超過 80,000 個排名單元配額不會觸發這項警告,而是會產生超額費用。 | <Quota exceeded message>; RankService.Rank call failed for consumer project <N> with request query: <query> and <model>: semantic-ranker-fast@latest number of records: <N> |
DEADLINE_EXCEEDED |
Ranker.Rank 未在要求期限內完成。 |
<deadline-exceeded message from Ranker.Rank>; RankService.Rank call failed for consumer project <N> with request query: <query> and <model>: semantic-ranker-fast@latest number of records: <N> |
UNAVAILABLE |
傳回 Ranker.Rank UNAVAILABLE,或傳回已摺疊為 UNAVAILABLE 的非保留代碼 (例如 INTERNAL)。 |
如果基礎程式碼為 UNAVAILABLE:"RankService.Rank call failed for consumer project... 其他情況: "Reranking is temporarily unavailable. Returning fused (RRF) results without semantic reranking." |
FAILED_PRECONDITION |
Ranking API 傳回的任何 FAILED_PRECONDITION。 |
RankService.Rank call failed for consumer project <N> with request query: <query> and <model>: semantic-ranker-fast@latest number of records: <N> |
CANCELLED |
呼叫端在重新排序完成前取消了 BatchSearchDataObjects RPC。 |
<cancellation message from the cancelled RankService.Rank RPC>; RankService.Rank call failed for consumer project <N> with request query: <query> and <model>: semantic-ranker-fast@latest number of records: <N> |