フォローアップ付きのデータストアを検索する
コレクションでコンテンツを整理
必要に応じて、コンテンツの保存と分類を行います。
データストアに対してマルチターン / 会話型検索を実行します。
もっと見る
このコードサンプルを含む詳細なドキュメントについては、以下をご覧ください。
コードサンプル
特に記載のない限り、このページのコンテンツはクリエイティブ・コモンズの表示 4.0 ライセンスにより使用許諾されます。コードサンプルは Apache 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 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)."]]