adk-python icon indicating copy to clipboard operation
adk-python copied to clipboard

DiscoveryEngineSearchTool: 400 error with regional (non-global) data stores

Open kaligautier opened this issue 8 months ago • 8 comments

Description

DiscoveryEngineSearchTool fails with a 400 error when used with a data store located in a non-global region (e.g. eu).

Error

400 Incorrect API endpoint used. The current endpoint can only serve traffic from "global" region,
but got "eu" region from the API request.
Please follow https://cloud.google.com/generative-ai-app-builder/docs/locations to use the correct regional API endpoint.

Root cause

In discovery_engine_search_tool.py (L75-84), the SearchServiceClient is always created with the default global endpoint (discoveryengine.googleapis.com):

credentials, _ = google.auth.default()
quota_project_id = getattr(credentials, "quota_project_id", None)
options = (
    client_options.ClientOptions(quota_project_id=quota_project_id)
    if quota_project_id
    else None
)
self._discovery_engine_client = discoveryengine.SearchServiceClient(
    credentials=credentials, client_options=options
)

However, regional data stores (e.g. eu, us, or single-region like europe-west1) require regional endpoints such as eu-discoveryengine.googleapis.com, as documented in Discovery Engine locations.

The location is already present in the data_store_id parameter (e.g. projects/{project}/locations/eu/collections/…), but it is never used to configure the client endpoint.

Reproduction

from google.adk.tools import DiscoveryEngineSearchTool

tool = DiscoveryEngineSearchTool(
    data_store_id="projects/my-project/locations/eu/collections/default_collection/dataStores/my-datastore",
)

# Calling the tool triggers a 400 error
result = tool.discovery_engine_search("test query")
# → {"status": "error", "error_message": "400 Incorrect API endpoint used..."}

Expected behavior

The tool should extract the location from data_store_id (or search_engine_id) and set the appropriate api_endpoint in ClientOptions:

  • eu → eu-discoveryengine.googleapis.com
  • us → us-discoveryengine.googleapis.com
  • europe-west1 → europe-west1-discoveryengine.googleapis.com
  • global → discoveryengine.googleapis.com (default, unchanged)

Suggested fix

Parse the location from the resource ID and pass api_endpoint to ClientOptions:

import re

location_match = re.search(r"/locations/([^/]+)/", data_store_id or search_engine_id)
location = location_match.group(1) if location_match else "global"

api_endpoint = (
    f"{location}-discoveryengine.googleapis.com"
    if location != "global"
    else "discoveryengine.googleapis.com"
)

options = client_options.ClientOptions(
    api_endpoint=api_endpoint,
    quota_project_id=quota_project_id,
)

Alternatively, accept an optional client_options or api_endpoint parameter in the constructor to let users override it.

Environment

  • google-adk version: 1.25.1
  • Data store location: eu
  • Python: 3.14

kaligautier avatar Mar 03 '26 13:03 kaligautier

Hello @kaligautier ,

Have you had a chance to test your fix? If it works well for you, please feel free to raise a PR. We will gladly review it and get it merged if all checks pass.

llalitkumarrr avatar Mar 04 '26 10:03 llalitkumarrr

This europe-west1 → europe-west1-discoveryengine.googleapis.com is not necessary we can keep us eu and global

kaligautier avatar Mar 05 '26 10:03 kaligautier

Hello @kaligautier ,

Thank you for your contribution, we will review this and if all checks pass it will be merged.

llalitkumarrr avatar Mar 06 '26 03:03 llalitkumarrr

Hello @rohityan , could you please have look at this?

llalitkumarrr avatar Mar 06 '26 03:03 llalitkumarrr

Hi, I am also facing this issue when using VertexAISearchTool with bypass_multi_tools_limit being set to True: https://google.github.io/adk-docs/tools/limitations/#workaround-2-bypass_multi_tools_limit When do we expect the issue to be solved?

chc4abt avatar Mar 12 '26 12:03 chc4abt

bypass_multi_tools_limit and DiscoveryEngineSearchTool were introduce as a workaround for the model's limitation that built-in tools cannot be used with other tools together. Since new Gemini models no longer have the limitation, could you please switch to use the built in VertexAiSearchTool?

xuanyang15 avatar Mar 16 '26 19:03 xuanyang15

Since we are EU based the application need to follow GDPR and EU AI act. Gemini 3 and Gemini 3.1 is not available through location EU. So we would appreciate the workaround to be fixed to be compatible again with eu located DiscoveryEngineToolSearchTool and Gemini Enterprise application

chc4abt avatar Mar 17 '26 15:03 chc4abt

Thanks for the information! https://github.com/google/adk-python/pull/4720 is under review now.

xuanyang15 avatar Mar 23 '26 18:03 xuanyang15