跳至主要內容

Google Gemini 推出 Grounding with Google Search 功能!AI 搜尋大戰白熱化

Google 旗下的 Gemini 模型推出 Grounding with Google Search 功能,允許開發者將 Gemini 模型的回應與 Google 搜尋結果連結,提升回應的準確性和即時性,並有效減少 AI 幻覺,劍指 OpenAI ChatGPT Search。

The Walking Fish 步行魚
The Walking Fish 步行魚 ·
923 字 · 閱讀時間: 3 分鐘 · ...
Google Gemini 推出 Grounding with Google Search 功能!AI 搜尋大戰白熱化
Fig. 01 — Google Gemini 推出 Grounding with Google … FEATURED IMAGE

Google 於 2024 年 10 月 31 日(台灣時間 11/1) 正式推出 Gemini 的 Grounding with Google Search 功能,允許 Gemini 模型從 Google 搜尋結果中獲取最新、更精確的資訊,提升回應的準確性和即時性,並有效減少 AI 幻覺(hallucinations)。而 ChatGPT Search 挑在此功能宣布後 1 分鐘後推出(Google 1:00 AM、OpenAI 1:01 AM),較勁意味相當濃厚。

當用戶透過 Gemini API 或 Google AI Studio 提交查詢時,系統會運用 Google 搜尋引擎尋找相關的最新資訊,並將這些資訊提供給 Gemini 模型。模型會根據搜尋結果生成更準確、更符合現況的答案,並在回覆中提供資料來源連結和搜尋建議,增加透明度和可信度。

Google 建議開發者在以下情況下使用 Grounding with Google Search

  • 需要減少 AI 幻覺的應用: Grounding 技術能有效降低 Gemini 模型產生不實資訊的機率。
  • 需要提供最新資訊的應用: 模型能透過 Google 搜尋獲取即時資訊,讓 AI 應用程式更貼近現實。
  • 希望能提升透明度和可信度的應用: 提供資料來源連結能提升 AI 應用程式的透明度,並引導使用者點擊連結了解更多資訊,有助於增加發布者的流量。
  • 希望能提供更豐富資訊的應用: Grounding 技術能整合 Google 搜尋的豐富資訊,使 Gemini 模型能提供更全面的答案。

目前 Gemini 1.5 全系列的模型皆支援使用 Grounding with Google Search,開發者可以在 Google AI Studio 的「工具」區段,或透過啟用 API 中的 google_search_retrieval 工具來啟動此功能。 Grounding 功能現在已可在 Google AI Studio 中免費測試,但在 API 中則需付費使用,每 1,000 次查詢的費用為 35 美元,免費版 Gemini API 無法調用 Grounding with Google Search 功能(詳見:Gemini API pricing 或 Vertex AI 定價)。

Google AI Studio 比較模式下的模型回覆,無搜尋(左)和有搜尋(右) 價格截圖自:Vertex AI 定價

函式庫呼叫程式碼範例

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
import google.generativeai as genai
import os

genai.configure(api_key=os.environ["API_KEY"])
model = genai.GenerativeModel('models/gemini-1.5-flash-002')

response = model.generate_content(contents="Who won Wimbledon this year?",
                                  tools='google_search_retrieval')

print(response)
# Response contains `groundingMetadata` with grounding sources, confidence scores, and search suggestions

動態檢索功能:

即使啟用了 Grounding with Google Search,並非每個查詢都需要 grounding,這會造成額外的成本和延遲。因此,Google 提供了 動態檢索(dynamic retrieval) 功能,讓開發者能更精細地控制 grounding 的使用。當開發者請求 grounded 答案時,動態檢索功能會根據提示內容給予一個預測分數(0 到 1 之間的浮點數),分數越高表示越需要 grounding。開發者可以設定一個閾值,只有分數超過閾值的查詢才會使用 grounding(預設閾值為 0.3)。

圖片取自: Google Developer Blog

更詳細的程式碼範例和說明,請參考 Google 官方文件。

SHARE / 分享此文章