对文档进行排名
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
对文档进行排名
深入探索
如需查看包含此代码示例的详细文档,请参阅以下内容:
代码示例
如未另行说明,那么本页面中的内容已根据知识共享署名 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 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)."]]