检查接地
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
Check Grounding
深入探索
如需查看包含此代码示例的详细文档,请参阅以下内容:
代码示例
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。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)."]]