Starting April 29, 2025, Gemini 1.5 Pro and Gemini 1.5 Flash models are not available in projects that have no prior usage of these models, including new projects. For details, see Model versions and lifecycle.
Stay organized with collections
Save and categorize content based on your preferences.
In generative AI, grounding is the ability to connect model output to verifiable sources of information. If you provide models with access to specific data sources, grounding tethers their output to this data and reduces the chances of inventing content.
This document shows you how to ground model outputs by using either public or private data and covers the following topics:
When you make a request, you specify the tools the model can use for grounding. For implementation details, see Examples.
To ground with public data, include the GoogleSearchRetrieval tool in your request.
google_search_retrieval: An empty object ({}) that tells the model to use Google Search to ground the response.
To ground with private data, include the Retrieval tool in your request. This tool defines how the model accesses external knowledge from a Vertex AI Search data store.
retrieval: Contains the VertexAISearch object as its source.
vertex_ai_search: Specifies the data store to use for grounding.
datastore: The fully-qualified Vertex AI Search data store resource ID. Specify the ID in the following format: projects/{project}/locations/{location}/collections/default_collection/dataStores/{datastore}.
Examples
Ground response on public web data using Google Search
To ground the response with Google Search public data, include the google_search_retrieval tool in the request. No additional parameters are required.
Set environment variables to use the Gen AI SDK with Vertex AI:
# 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 ...'
Set environment variables to use the Gen AI SDK with Vertex AI:
# 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}
Ground response on private data using Vertex AI Search
You can ground the response with data from a Vertex AI Search data store. For more information, see AI Applications.
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...'
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-27 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)"]]