후속 질문으로 데이터 스토어 검색
컬렉션을 사용해 정리하기
내 환경설정을 기준으로 콘텐츠를 저장하고 분류하세요.
데이터 스토어에서 멀티턴/대화형 검색을 실행합니다.
더 살펴보기
이 코드 샘플이 포함된 자세한 문서는 다음을 참조하세요.
코드 샘플
달리 명시되지 않는 한 이 페이지의 콘텐츠에는 Creative Commons Attribution 4.0 라이선스에 따라 라이선스가 부여되며, 코드 샘플에는 Apache 2.0 라이선스에 따라 라이선스가 부여됩니다. 자세한 내용은 Google Developers 사이트 정책을 참조하세요. 자바는 Oracle 및/또는 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)."]]