檢查接地
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
檢查接地
深入探索
如需包含這個程式碼範例的詳細說明文件,請參閱下列內容:
程式碼範例
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["難以理解","hardToUnderstand","thumb-down"],["資訊或程式碼範例有誤","incorrectInformationOrSampleCode","thumb-down"],["缺少我需要的資訊/範例","missingTheInformationSamplesINeed","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],[],[[["\u003cp\u003eThis code sample demonstrates how to check grounding using the Vertex AI Agent Builder Python API, verifying the accuracy of generated answers against provided facts.\u003c/p\u003e\n"],["\u003cp\u003eThe grounding check process involves setting up a \u003ccode\u003eGroundedGenerationServiceClient\u003c/code\u003e and specifying a grounding configuration, an answer candidate, and relevant facts.\u003c/p\u003e\n"],["\u003cp\u003eAuthentication to Vertex AI Agent Builder requires setting up Application Default Credentials, as detailed in the linked documentation for local development environments.\u003c/p\u003e\n"],["\u003cp\u003eThe provided example sends a \u003ccode\u003eCheckGroundingRequest\u003c/code\u003e with sample data and then prints the server's \u003ccode\u003eresponse\u003c/code\u003e when complete.\u003c/p\u003e\n"]]],[],null,["# Check grounding\n\nExplore further\n---------------\n\n\nFor detailed documentation that includes this code sample, see the following:\n\n- [Check grounding with RAG](/generative-ai-app-builder/docs/check-grounding)\n\nCode sample\n-----------\n\n### Python\n\n\nFor more information, see the\n[AI Applications Python API\nreference documentation](/python/docs/reference/discoveryengine/latest).\n\n\nTo authenticate to AI Applications, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for a local development environment](/docs/authentication/set-up-adc-local-dev-environment).\n\n from google.cloud import discoveryengine_v1 as discoveryengine\n\n # TODO(developer): Uncomment these variables before running the sample.\n # project_id = \"YOUR_PROJECT_ID\"\n\n client = discoveryengine.GroundedGenerationServiceClient()\n\n # The full resource name of the grounding config.\n # Format: projects/{project_id}/locations/{location}/groundingConfigs/default_grounding_config\n grounding_config = client.grounding_config_path(\n project=project_id,\n location=\"global\",\n grounding_config=\"default_grounding_config\",\n )\n\n request = discoveryengine.CheckGroundingRequest(\n grounding_config=grounding_config,\n answer_candidate=\"Titanic was directed by James Cameron. It was released in 1997.\",\n facts=[\n discoveryengine.GroundingFact(\n fact_text=(\n \"Titanic is a 1997 American epic romantic disaster movie. It was directed, written,\"\n \" and co-produced by James Cameron. The movie is about the 1912 sinking of the\"\n \" RMS Titanic. It stars Kate Winslet and Leonardo DiCaprio. The movie was released\"\n \" on December 19, 1997. It received positive critical reviews. The movie won 11 Academy\"\n \" Awards, and was nominated for fourteen total Academy Awards.\"\n ),\n attributes={\"author\": \"Simple Wikipedia\"},\n ),\n discoveryengine.GroundingFact(\n fact_text=(\n 'James Cameron\\'s \"Titanic\" is an epic, action-packed romance'\n \"set against the ill-fated maiden voyage of the R.M.S. Titanic;\"\n \"the pride and joy of the White Star Line and, at the time,\"\n \"the largest moving object ever built. \"\n 'She was the most luxurious liner of her era -- the \"ship of dreams\" -- '\n \"which ultimately carried over 1,500 people to their death in the \"\n \"ice cold waters of the North Atlantic in the early hours of April 15, 1912.\"\n ),\n attributes={\"author\": \"Simple Wikipedia\"},\n ),\n ],\n grounding_spec=discoveryengine.CheckGroundingSpec(citation_threshold=0.6),\n )\n\n response = client.check_grounding(request=request)\n\n # Handle the response\n print(response)\n\nWhat's next\n-----------\n\n\nTo search and filter code samples for other Google Cloud products, see the\n[Google Cloud sample browser](/docs/samples?product=genappbuilder)."]]