# Replace the `GOOGLE_CLOUD_PROJECT` and `GOOGLE_CLOUD_LOCATION` values# with appropriate values for your project.exportGOOGLE_CLOUD_PROJECT=GOOGLE_CLOUD_PROJECTexportGOOGLE_CLOUD_LOCATION=globalexportGOOGLE_GENAI_USE_VERTEXAI=True
fromgoogleimportgenaifromgoogle.genai.typesimport(GenerateContentConfig,GoogleSearch,HttpOptions,Tool,)client=genai.Client(http_options=HttpOptions(api_version="v1"))response=client.models.generate_content(model="gemini-2.5-flash",contents="When is the next total solar eclipse in the United States?",config=GenerateContentConfig(tools=[# Use Google Search ToolTool(google_search=GoogleSearch())],),)print(response.text)# Example response:# 'The next total solar eclipse in the United States will occur on ...'
# Replace the `GOOGLE_CLOUD_PROJECT` and `GOOGLE_CLOUD_LOCATION` values# with appropriate values for your project.exportGOOGLE_CLOUD_PROJECT=GOOGLE_CLOUD_PROJECTexportGOOGLE_CLOUD_LOCATION=globalexportGOOGLE_GENAI_USE_VERTEXAI=True
import("context""fmt""io"genai"google.golang.org/genai")//generateWithGoogleSearchshowshowtogeneratetextusingGoogleSearch.funcgenerateWithGoogleSearch(wio.Writer)error{ctx:=context.Background()client,err:=genai.NewClient(ctx, &genai.ClientConfig{HTTPOptions:genai.HTTPOptions{APIVersion:"v1"},})iferr!=nil{returnfmt.Errorf("failed to create genai client: %w",err)}modelName:="gemini-2.5-flash"contents:=[]*genai.Content{{Parts:[]*genai.Part{{Text:"When is the next total solar eclipse in the United States?"},},Role:"user"},}config:= &genai.GenerateContentConfig{Tools:[]*genai.Tool{{GoogleSearch: &genai.GoogleSearch{}},},}resp,err:=client.Models.GenerateContent(ctx,modelName,contents,config)iferr!=nil{returnfmt.Errorf("failed to generate content: %w",err)}respText:=resp.Text()fmt.Fprintln(w,respText)//Exampleresponse://ThenexttotalsolareclipseintheUnitedStateswilloccuronMarch30,2033,butitwillonly...returnnil}
Vertex AI Search를 사용한 비공개 데이터에 대한 기본 응답
Vertex AI Search 데이터 스토어의 데이터로 응답을 그라운딩합니다.
자세한 내용은 AI Applications를 참고하세요.
경고: 당분간 이 '그라운딩' 인터페이스는 Vertex AI Search '청크 모드'를 지원하지 않습니다.
Python용 Gen AI SDK
fromgoogleimportgenaifromgoogle.genai.typesimport(GenerateContentConfig,HttpOptions,Retrieval,Tool,VertexAISearch,)client=genai.Client(http_options=HttpOptions(api_version="v1"))# Load Data Store ID from Vertex AI Search# datastore = "projects/111111111111/locations/global/collections/default_collection/dataStores/data-store-id"response=client.models.generate_content(model="gemini-2.5-flash",contents="How do I make an appointment to renew my driver's license?",config=GenerateContentConfig(tools=[# Use Vertex AI Search ToolTool(retrieval=Retrieval(vertex_ai_search=VertexAISearch(datastore=datastore,)))],),)print(response.text)# Example response:# 'The process for making an appointment to renew your driver's license varies depending on your location. To provide you with the most accurate instructions...'
[[["이해하기 쉬움","easyToUnderstand","thumb-up"],["문제가 해결됨","solvedMyProblem","thumb-up"],["기타","otherUp","thumb-up"]],[["이해하기 어려움","hardToUnderstand","thumb-down"],["잘못된 정보 또는 샘플 코드","incorrectInformationOrSampleCode","thumb-down"],["필요한 정보/샘플이 없음","missingTheInformationSamplesINeed","thumb-down"],["번역 문제","translationIssue","thumb-down"],["기타","otherDown","thumb-down"]],["최종 업데이트: 2025-09-04(UTC)"],[],[],null,["# Grounding\n\nIn generative AI, grounding is the ability to connect model output to verifiable\nsources of information. If you provide models with access to specific data\nsources, then grounding tethers their output to these data and reduces the\nchances of inventing content.\n\nWith Vertex AI, you can ground model outputs in the following ways:\n\n- Ground with Google Search - ground a model with publicly available web data.\n- Ground to your own data - ground a model with your own data from Vertex AI Search as a data store.\n\nFor more information about grounding, see [Grounding overview](/vertex-ai/generative-ai/docs/grounding/overview).\n\nSupported models\n----------------\n\n- [Gemini 2.5 Flash-Lite](/vertex-ai/generative-ai/docs/models/gemini/2-5-flash-lite)\n- [Gemini 2.5 Flash with Live API native audio](/vertex-ai/generative-ai/docs/models/gemini/2-5-flash#live-api-native-audio) (Preview)\n- [Gemini 2.0 Flash with Live API](/vertex-ai/generative-ai/docs/models/gemini/2-0-flash#live-api) (Preview)\n- [Gemini 2.5 Pro](/vertex-ai/generative-ai/docs/models/gemini/2-5-pro)\n- [Gemini 2.5 Flash](/vertex-ai/generative-ai/docs/models/gemini/2-5-flash)\n- [Gemini 2.0 Flash](/vertex-ai/generative-ai/docs/models/gemini/2-0-flash)\n\nParameter list\n--------------\n\nSee [examples](#examples) for implementation details.\n\n#### `GoogleSearchRetrieval`\n\nGround the response with public data.\n\n#### `Retrieval`\n\nGround the response with private data from Vertex AI Search as a data store.\nDefines a retrieval tool that the model can call to access external knowledge.\n\n#### `VertexAISearch`\n\nExamples\n--------\n\n### Ground response on public web data using Google Search\n\nGround the response with Google Search public data. Include the `google_search_retrieval` tool in the request. No additional parameters are required. \n\n### Python\n\n#### Install\n\n```\npip install --upgrade google-genai\n```\n\n\nTo learn more, see the\n[SDK reference documentation](https://googleapis.github.io/python-genai/).\n\n\nSet environment variables to use the Gen AI SDK with Vertex AI:\n\n```bash\n# Replace the `GOOGLE_CLOUD_PROJECT` and `GOOGLE_CLOUD_LOCATION` values\n# with appropriate values for your project.\nexport GOOGLE_CLOUD_PROJECT=GOOGLE_CLOUD_PROJECT\nexport GOOGLE_CLOUD_LOCATION=global\nexport GOOGLE_GENAI_USE_VERTEXAI=True\n```\n\n\u003cbr /\u003e\n\n from google import genai\n from google.genai.types import (\n GenerateContentConfig,\n GoogleSearch,\n HttpOptions,\n Tool,\n )\n\n client = genai.Client(http_options=HttpOptions(api_version=\"v1\"))\n\n response = client.models.generate_content(\n model=\"gemini-2.5-flash\",\n contents=\"When is the next total solar eclipse in the United States?\",\n config=GenerateContentConfig(\n tools=[\n # Use Google Search Tool\n Tool(google_search=GoogleSearch())\n ],\n ),\n )\n\n print(response.text)\n # Example response:\n # 'The next total solar eclipse in the United States will occur on ...'\n\n### Go\n\nLearn how to install or update the [Go](/vertex-ai/generative-ai/docs/sdks/overview).\n\n\nTo learn more, see the\n[SDK reference documentation](https://pkg.go.dev/google.golang.org/genai).\n\n\nSet environment variables to use the Gen AI SDK with Vertex AI:\n\n```bash\n# Replace the `GOOGLE_CLOUD_PROJECT` and `GOOGLE_CLOUD_LOCATION` values\n# with appropriate values for your project.\nexport GOOGLE_CLOUD_PROJECT=GOOGLE_CLOUD_PROJECT\nexport GOOGLE_CLOUD_LOCATION=global\nexport GOOGLE_GENAI_USE_VERTEXAI=True\n```\n\n\u003cbr /\u003e\n\n import (\n \t\"context\"\n \t\"fmt\"\n \t\"io\"\n\n \tgenai \"google.golang.org/genai\"\n )\n\n // generateWithGoogleSearch shows how to generate text using Google Search.\n func generateWithGoogleSearch(w io.Writer) error {\n \tctx := context.Background()\n\n \tclient, err := genai.NewClient(ctx, &genai.ClientConfig{\n \t\tHTTPOptions: genai.HTTPOptions{APIVersion: \"v1\"},\n \t})\n \tif err != nil {\n \t\treturn fmt.Errorf(\"failed to create genai client: %w\", err)\n \t}\n\n \tmodelName := \"gemini-2.5-flash\"\n \tcontents := []*genai.Content{\n \t\t{Parts: []*genai.Part{\n \t\t\t{Text: \"When is the next total solar eclipse in the United States?\"},\n \t\t},\n \t\t\tRole: \"user\"},\n \t}\n \tconfig := &genai.GenerateContentConfig{\n \t\tTools: []*genai.Tool{\n \t\t\t{GoogleSearch: &genai.GoogleSearch{}},\n \t\t},\n \t}\n\n \tresp, err := client.Models.GenerateContent(ctx, modelName, contents, config)\n \tif err != nil {\n \t\treturn fmt.Errorf(\"failed to generate content: %w\", err)\n \t}\n\n \trespText := resp.Text()\n\n \tfmt.Fprintln(w, respText)\n\n \t// Example response:\n \t// The next total solar eclipse in the United States will occur on March 30, 2033, but it will only ...\n\n \treturn nil\n }\n\n\u003cbr /\u003e\n\n### Ground response on private data using Vertex AI Search\n\nGround the response with data from a Vertex AI Search data store.\nFor more information, see [AI Applications](/vertex-ai-search-and-conversation).\n\nBefore you ground a response with private data, [create a data store](/generative-ai-app-builder/docs/create-data-store-es) and a [search app](/generative-ai-app-builder/docs/create-engine-es).\n\nWARNING: For the time being, this \"grounding\" interface does not support Vertex AI Search \"chunk mode\". \n\n### Gen AI SDK for Python\n\n from google import genai\n from google.genai.types import (\n GenerateContentConfig,\n HttpOptions,\n Retrieval,\n Tool,\n VertexAISearch,\n )\n\n client = genai.Client(http_options=HttpOptions(api_version=\"v1\"))\n\n # Load Data Store ID from Vertex AI Search\n # datastore = \"projects/111111111111/locations/global/collections/default_collection/dataStores/data-store-id\"\n\n response = client.models.generate_content(\n model=\"gemini-2.5-flash\",\n contents=\"How do I make an appointment to renew my driver's license?\",\n config=GenerateContentConfig(\n tools=[\n # Use Vertex AI Search Tool\n Tool(\n retrieval=Retrieval(\n vertex_ai_search=VertexAISearch(\n datastore=datastore,\n )\n )\n )\n ],\n ),\n )\n\n print(response.text)\n # Example response:\n # 'The process for making an appointment to renew your driver's license varies depending on your location. To provide you with the most accurate instructions...'\n\nWhat's next\n-----------\n\nFor detailed documentation, see the following:\n\n- [Grounding](/vertex-ai/generative-ai/docs/grounding/overview)\n- [Gemini API](/vertex-ai/generative-ai/docs/model-reference/gemini)"]]