Datenspeicher mit Nachfragen durchsuchen
Mit Sammlungen den Überblick behalten
Sie können Inhalte basierend auf Ihren Einstellungen speichern und kategorisieren.
Mehrere Suchanfragen in Folge bzw. eine Konversationssuche in einem Datenspeicher durchführen
Weitere Informationen
Eine ausführliche Dokumentation, die dieses Codebeispiel enthält, finden Sie hier:
Codebeispiel
Nächste Schritte
Wenn Sie nach Codebeispielen für andere Google Cloud -Produkte suchen und filtern möchten, können Sie den Google Cloud -Beispielbrowser verwenden.
Sofern nicht anders angegeben, sind die Inhalte dieser Seite unter der Creative Commons Attribution 4.0 License und Codebeispiele unter der Apache 2.0 License lizenziert. Weitere Informationen finden Sie in den Websiterichtlinien von Google Developers. Java ist eine eingetragene Marke von Oracle und/oder seinen Partnern.
[[["Leicht verständlich","easyToUnderstand","thumb-up"],["Mein Problem wurde gelöst","solvedMyProblem","thumb-up"],["Sonstiges","otherUp","thumb-up"]],[["Schwer verständlich","hardToUnderstand","thumb-down"],["Informationen oder Beispielcode falsch","incorrectInformationOrSampleCode","thumb-down"],["Benötigte Informationen/Beispiele nicht gefunden","missingTheInformationSamplesINeed","thumb-down"],["Problem mit der Übersetzung","translationIssue","thumb-down"],["Sonstiges","otherDown","thumb-down"]],[],[[["\u003cp\u003eThis code sample demonstrates how to perform a multi-turn or conversational search on a specified data store using the Vertex AI Agent Builder.\u003c/p\u003e\n"],["\u003cp\u003eThe process involves setting up Application Default Credentials for authentication and utilizing the Vertex AI Agent Builder Python API.\u003c/p\u003e\n"],["\u003cp\u003eThe code initializes a multi-turn session, adds new messages (search queries), and retrieves responses that include summaries and search results.\u003c/p\u003e\n"],["\u003cp\u003eThe code uses \u003ccode\u003ediscoveryengine.ConversationalSearchServiceClient\u003c/code\u003e to create conversations, add queries, and print the response, including summaries, links, and snippets.\u003c/p\u003e\n"],["\u003cp\u003eThis search functionality can be tested further by using the google cloud sample browser.\u003c/p\u003e\n"]]],[],null,["# Search a data store with follow-ups\n\nPerform a multi-turn/conversational search on a data store.\n\nExplore further\n---------------\n\n\nFor detailed documentation that includes this code sample, see the following:\n\n- [Search with follow-ups](/generative-ai-app-builder/docs/multi-turn-search)\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 typing import List\n\n from google.api_core.client_options import ClientOptions\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 # location = \"YOUR_LOCATION\" # Values: \"global\", \"us\", \"eu\"\n # data_store_id = \"YOUR_DATA_STORE_ID\"\n # search_queries = [\"YOUR_FIRST_SEARCH_QUERY\", \"YOUR_SECOND_SEARCH_QUERY\"]\n\n\n def multi_turn_search_sample(\n project_id: str,\n location: str,\n data_store_id: str,\n search_queries: List[str],\n ) -\u003e List[discoveryengine.ConverseConversationResponse]:\n # For more information, refer to:\n # https://cloud.google.com/generative-ai-app-builder/docs/locations#specify_a_multi-region_for_your_data_store\n client_options = (\n ClientOptions(api_endpoint=f\"{location}-discoveryengine.googleapis.com\")\n if location != \"global\"\n else None\n )\n\n # Create a client\n client = discoveryengine.ConversationalSearchServiceClient(\n client_options=client_options\n )\n\n # Initialize Multi-Turn Session\n conversation = client.create_conversation(\n # The full resource name of the data store\n # e.g. projects/{project_id}/locations/{location}/dataStores/{data_store_id}\n parent=client.data_store_path(\n project=project_id, location=location, data_store=data_store_id\n ),\n conversation=discoveryengine.Conversation(),\n )\n\n\n for search_query in search_queries:\n # Add new message to session\n request = discoveryengine.ConverseConversationRequest(\n name=conversation.name,\n query=discoveryengine.TextInput(input=search_query),\n serving_config=client.serving_config_path(\n project=project_id,\n location=location,\n data_store=data_store_id,\n serving_config=\"default_config\",\n ),\n # Options for the returned summary\n summary_spec=discoveryengine.SearchRequest.ContentSearchSpec.SummarySpec(\n # Number of results to include in summary\n summary_result_count=3,\n include_citations=True,\n ),\n )\n response = client.converse_conversation(request)\n\n print(f\"Reply: {response.reply.summary.summary_text}\\n\")\n\n for i, result in enumerate(response.search_results, 1):\n result_data = result.document.derived_struct_data\n print(f\"[{i}]\")\n print(f\"Link: {result_data['link']}\")\n print(f\"First Snippet: {result_data['snippets'][0]['snippet']}\")\n print(\n \"First Extractive Answer: \\n\"\n f\"\\tPage: {result_data['extractive_answers'][0]['pageNumber']}\\n\"\n f\"\\tContent: {result_data['extractive_answers'][0]['content']}\\n\\n\"\n )\n print(\"\\n\\n\")\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)."]]