本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。
Web Grounding
Web Grounding 可讓 Amazon Nova 搜尋 Web 以取得目前資訊,並提供包含引文的回應。此功能適用於需要模型訓練資料以外up-to-date的查詢。
Web Grounding 的運作方式
為提示詞啟用 Web Grounding 後,會執行下列步驟:
-
請求組態:您的應用程式會將使用者提示傳送至已啟用 nova_grounding 的 Amazon Bedrock API
systemTool。 -
搜尋與分析:模型會判斷是否需要搜尋、執行一或多個相關資訊搜尋,以及評估是否需要額外的搜尋,以擴展其對特定子主題的理解或深入了解。
-
回應產生:Amazon Nova 會自動合成搜尋結果中的資訊,以產生以即時資訊為基礎的最終 API 回應,並附上其來源的引文。
如何使用 Web Grounding
如需使用 Web Grounding 之程式碼的完整範例,請參閱程式碼範例一節。
若要在您的結果中包含 Web Grounding,請在 toolConfig 區塊中指定下列systemTool參數:
import boto3 from botocore.config import Config # Create the Bedrock Runtime client with extended timeout bedrock = boto3.client( "bedrock-runtime", region_name="us-east-1", config=Config(read_timeout=3600) ) # Define the tool configuration tool_config = { "tools": [{ "systemTool": { "name": "nova_grounding" } }] } # Send the request response = bedrock.converse( modelId="us.amazon.nova-2-lite-v1:0", messages=[{ "role": "user", "content": [{"text": "What are the latest developments in quantum computing?"}] }], toolConfig=tool_config ) # Extract text with interleaved citations output_with_citations = "" content_list = response["output"]["message"]["content"] for content in content_list: if "text" in content: output_with_citations += content["text"] elif "citationsContent" in content: citations = content["citationsContent"]["citations"] for citation in citations: url = citation["location"]["web"]["url"] output_with_citations += f" [{url}]" print(output_with_citations)
區域可用性
Web Grounding 目前僅適用於美國區域,且僅受美國 CRIS 設定檔支援。
回應結構
以下是回應範例。為了簡潔起見,已縮短回應:
{ "output": { "message": { "content": [ { "text": "Recent quantum computing developments include...", "citationsContent": [ { "location": { "web": { "url": "https://example.com/quantum-news", "domain": "example.com" } } } ] } ] } } }
每個引文包括:
-
text:模型產生的回應區段。 -
citationsContent:與文字區段相關的引文資料的主要容器。 -
citations: 內citationsContent保存引文位置的容器。 -
location: 內citations存放引文來源的容器。 -
web: 內location包含 Web 來源詳細資訊的容器。 -
url:引文來源的完整 Web 地址 (URL)。 -
domain:來源 URL 的根網域。
接地安全
您的資料永遠不會離開 AWS 基礎設施。模型產生的查詢會保留在 AWS 服務中,絕不會傳送到更廣泛的網際網路。我們廣泛的內部 Web 搜尋索引和知識圖表會優先考慮值得信賴的高品質來源,並在傳入時篩選惡意內容。最後,我們會透過執行時期篩選保護您的應用程式免於間接提示詞注入和錯誤資訊 (請注意,此風險緩解措施僅限於非英文語言)。
錯誤處理
請勿包含名稱為 nova_grounding 的 toolSpec 項目。包含具有此名稱的工具會導致錯誤。
以下是使用 Web Grounding 時可能發生的潛在錯誤清單:
-
malformed_tool_use -
max_tokens -
malformed_model_output
內建工具所需的許可
為了確保您的角色可以存取 Amazon Bedrock 上的 Web Grounding,您有兩個選項:
-
在您的 IAM 角色上啟用 BedrockFullAccess:如果您的角色具有 BedrockFullAccess,它將可以自動存取 Web Grounding。
-
新增特定許可 (如有需要):如果您需要更精細的存取控制,請將此政策新增至角色的 IAM 政策,以您的 ID 取代帳戶 AWS 帳戶 ID:
{ "Statement": [ { "Effect": "Allow", "Action": ["bedrock:InvokeTool"], "Resource": ["arn:aws:bedrock::{111122223333}:system-tool/amazon.nova_grounding"] } ] }
Web Grounding aws:requestedRegion的條件金鑰設定為「未指定」。如果您現有的政策或服務控制政策 (SCP) 強制執行此條件,您可能會遇到存取問題。更新條件以允許「未指定」requestedRegion,可以解決此問題。
注意
如果您啟用 Web Grounding 工具,您必須為您以及最終使用者對包含基礎資訊的輸出的任何使用負責。當您的輸出包含來自引文或來源材料連結的基礎資訊時,您會知道這一點。您必須在您提供給最終使用者的輸出中保留並顯示這些引文和連結。
注意
Web Grounding 會增加額外成本。如需詳細資訊,請前往 AWS Bedrock 定價