為文件排名
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
為文件排名
深入探索
如需包含這個程式碼範例的詳細說明文件,請參閱下列內容:
程式碼範例
除非另有註明,否則本頁面中的內容是採用創用 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 page provides information and a code sample on how to rank documents using the Vertex AI Agent Builder.\u003c/p\u003e\n"],["\u003cp\u003eThe code sample demonstrates ranking documents using the \u003ccode\u003eRankServiceClient\u003c/code\u003e from the \u003ccode\u003egoogle.cloud.discoveryengine_v1\u003c/code\u003e library.\u003c/p\u003e\n"],["\u003cp\u003eAuthentication to Vertex AI Agent Builder requires setting up Application Default Credentials, detailed instructions are available in the provided link.\u003c/p\u003e\n"],["\u003cp\u003eThe provided Python code allows for ranking documents based on a query using a specified model such as \u003ccode\u003esemantic-ranker-512@latest\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eThe user can view further information on the topic of ranking and reranking documents with RAG by following a link to detailed documentation.\u003c/p\u003e\n"]]],[],null,["# Rank documents\n\nExplore further\n---------------\n\n\nFor detailed documentation that includes this code sample, see the following:\n\n- [Improve search and RAG quality with ranking API](/generative-ai-app-builder/docs/ranking)\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.RankServiceClient()\n\n # The full resource name of the ranking config.\n # Format: projects/{project_id}/locations/{location}/rankingConfigs/default_ranking_config\n ranking_config = client.ranking_config_path(\n project=project_id,\n location=\"global\",\n ranking_config=\"default_ranking_config\",\n )\n request = discoveryengine.RankRequest(\n ranking_config=ranking_config,\n model=\"semantic-ranker-default@latest\",\n top_n=10,\n query=\"What is Google Gemini?\",\n records=[\n discoveryengine.RankingRecord(\n id=\"1\",\n title=\"Gemini\",\n content=\"The Gemini zodiac symbol often depicts two figures standing side-by-side.\",\n ),\n discoveryengine.RankingRecord(\n id=\"2\",\n title=\"Gemini\",\n content=\"Gemini is a cutting edge large language model created by Google.\",\n ),\n discoveryengine.RankingRecord(\n id=\"3\",\n title=\"Gemini Constellation\",\n content=\"Gemini is a constellation that can be seen in the night sky.\",\n ),\n ],\n )\n\n response = client.rank(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)."]]