Classer les documents
Restez organisé à l'aide des collections
Enregistrez et classez les contenus selon vos préférences.
Classer des documents
En savoir plus
Pour obtenir une documentation détaillée incluant cet exemple de code, consultez les articles suivants :
Exemple de code
Sauf indication contraire, le contenu de cette page est régi par une licence Creative Commons Attribution 4.0, et les échantillons de code sont régis par une licence Apache 2.0. Pour en savoir plus, consultez les Règles du site Google Developers. Java est une marque déposée d'Oracle et/ou de ses sociétés affiliées.
[[["Facile à comprendre","easyToUnderstand","thumb-up"],["J'ai pu résoudre mon problème","solvedMyProblem","thumb-up"],["Autre","otherUp","thumb-up"]],[["Difficile à comprendre","hardToUnderstand","thumb-down"],["Informations ou exemple de code incorrects","incorrectInformationOrSampleCode","thumb-down"],["Il n'y a pas l'information/les exemples dont j'ai besoin","missingTheInformationSamplesINeed","thumb-down"],["Problème de traduction","translationIssue","thumb-down"],["Autre","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)."]]