グラウンディングをチェックする
コレクションでコンテンツを整理
必要に応じて、コンテンツの保存と分類を行います。
グラウンディングをチェックする
もっと見る
このコードサンプルを含む詳細なドキュメントについては、以下をご覧ください。
コードサンプル
特に記載のない限り、このページのコンテンツはクリエイティブ・コモンズの表示 4.0 ライセンスにより使用許諾されます。コードサンプルは Apache 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)."]]