Skip to content

Search grounding is not working - Error: use google_search field instead of google_search_retrieval field #330

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
thenameless7741 opened this issue Jan 28, 2025 · 16 comments
Assignees
Labels
component:js sdk Issue/PR related to JavaScript SDK status:triaged Issue/PR triaged to the corresponding sub-team type:bug Something isn't working

Comments

@thenameless7741
Copy link

thenameless7741 commented Jan 28, 2025

Description of the bug:

I implemented the search grounding feature by following the sample code and it seems to be broken at the moment:

  const modelParams: ModelParams = {
    model: 'gemini-2.0-flash-exp',
    tools: [
      {
        googleSearchRetrieval: {
          dynamicRetrievalConfig: {
            mode: DynamicRetrievalMode.MODE_DYNAMIC,
            dynamicThreshold: 0.7, // default
          },
        },
      },
    ],
  };

Error: [GoogleGenerativeAI Error]: Error fetching from https://generativelanguage.googleapis.com/v1beta/models/gemini-2.0-flash-exp:generateContent: [400 Bad Request] Unable to submit request because Please use google_search field instead of google_search_retrieval field..

A temporary workaround is to replace googleSearchRetrieval with an empty googleSearch:

  const modelParams: ModelParams = {
    model: 'gemini-2.0-flash-exp',
    tools: [
      { googleSearch: {} },
    ],
  };

Simply replacing the field name would result in this error:

Error: [GoogleGenerativeAI Error]: Error fetching from https://generativelanguage.googleapis.com/v1beta/models/gemini-2.0-flash-exp:generateContent: [400 Bad Request] Invalid JSON payload received. Unknown name "dynamicRetrievalConfig" at 'tools[0].google_search': Cannot find field.

[{"@type":"type.googleapis.com/google.rpc.BadRequest","fieldViolations":[{"field":"tools[0].google_search","description":"Invalid JSON payload received. Unknown name "dynamicRetrievalConfig" at 'tools[0].google_search': Cannot find field."}]}]

Actual vs expected behavior:

Expected behavior: the documentation, sample code, and type definition should be updated to use googleSearch field.

Thank you.

@Leask
Copy link
Contributor

Leask commented Jan 30, 2025

The issue is fixed, but no one has merged it: #318

@Gunand3043 Gunand3043 added type:bug Something isn't working status:triaged Issue/PR triaged to the corresponding sub-team component:js sdk Issue/PR related to JavaScript SDK labels Jan 30, 2025
@HunderlineK
Copy link

this library is effectively abandoned - no commit merged since about 3 months ago?

@Leask
Copy link
Contributor

Leask commented Feb 4, 2025

this library is effectively abandoned - no commit merged since about 3 months ago?

It seems so, but unfortunately.

@colintoh
Copy link

Bumping this. Having the exact same issue.

@Hth4nh
Copy link

Hth4nh commented Feb 10, 2025

Bump

@sugoidesune
Copy link

I could not make it work...

@hkt74 hkt74 self-assigned this Feb 20, 2025
@hkt74
Copy link
Collaborator

hkt74 commented Feb 20, 2025

Thanks for your feedback.

Starting with Gemini 2.0 models, search grounding tool changed from googleSearchRetrieval to googleSearch, as part of the change, dynamicRetrievalConfig has been removed from the new tool, the model can decide when to use Google Search.

Gemini 1.5 models can still use googleSearchRetrieval

The team is working on updating the api document, thanks @Leask for contributing the samples, I will review your PR shortly.

@Leask
Copy link
Contributor

Leask commented Feb 20, 2025

Thanks for your feedback.

Starting with Gemini 2.0 models, search grounding tool changed from googleSearchRetrieval to googleSearch, as part of the change, dynamicRetrievalConfig has been removed from the new tool, the model can decide when to use Google Search.

Gemini 1.5 models can still use googleSearchRetrieval

The team is working on updating the api document, thanks @Leask for contributing the samples, I will review your PR shortly.

Thank you for the review.
I have already submitted an updated version.
😄

@hkt74
Copy link
Collaborator

hkt74 commented Feb 21, 2025

PR #318 has been merged

@hkt74 hkt74 closed this as completed Feb 21, 2025
@Glutch
Copy link

Glutch commented Feb 21, 2025

Thanks for your feedback.

Starting with Gemini 2.0 models, search grounding tool changed from googleSearchRetrieval to googleSearch, as part of the change, dynamicRetrievalConfig has been removed from the new tool, the model can decide when to use Google Search.

Gemini 1.5 models can still use googleSearchRetrieval

The team is working on updating the api document, thanks @Leask for contributing the samples, I will review your PR shortly.

I'm using tools: [{google_search: {},},] but the groundingMetadata is almost always empty. "the model can decide when to use Google Search". So enabling this tool, lets the model decide for itself if it needs to use google_search? I need to force it, my use case completely breaks if it doesn't use the grounding. Is there no way to force the grounding?

@Leask
Copy link
Contributor

Leask commented Feb 21, 2025

Thanks for your feedback.
Starting with Gemini 2.0 models, search grounding tool changed from googleSearchRetrieval to googleSearch, as part of the change, dynamicRetrievalConfig has been removed from the new tool, the model can decide when to use Google Search.
Gemini 1.5 models can still use googleSearchRetrieval
The team is working on updating the api document, thanks @Leask for contributing the samples, I will review your PR shortly.

I'm using tools: [{google_search: {},},] but the groundingMetadata is almost always empty. "the model can decide when to use Google Search". So enabling this tool, lets the model decide for itself if it needs to use google_search? I need to force it, my use case completely breaks if it doesn't use the grounding. Is there no way to force the grounding?

Try to ask "tell me the latest movies on IMDB". You will see the result.

@Glutch
Copy link

Glutch commented Feb 21, 2025

Thanks for your feedback.
Starting with Gemini 2.0 models, search grounding tool changed from googleSearchRetrieval to googleSearch, as part of the change, dynamicRetrievalConfig has been removed from the new tool, the model can decide when to use Google Search.
Gemini 1.5 models can still use googleSearchRetrieval
The team is working on updating the api document, thanks @Leask for contributing the samples, I will review your PR shortly.

I'm using tools: [{google_search: {},},] but the groundingMetadata is almost always empty. "the model can decide when to use Google Search". So enabling this tool, lets the model decide for itself if it needs to use google_search? I need to force it, my use case completely breaks if it doesn't use the grounding. Is there no way to force the grounding?

Try to ask "tell me the latest movies on IMDB". You will see the result.

I have in my prompt "SEARCH THE WEB, use google_search, use grounding. Return in json format information about "Iphone 16" etc etc".

And it returns, without using grounding. "The upcoming iphone 16 is expected to feature blabla".

How do i force it to use grounding when it's obviously needed?

@hkt74
Copy link
Collaborator

hkt74 commented Feb 22, 2025

@Glutch Could you try a more specific prompt?

for example could you return the latest Iphone 16 price?, it returned the results with search sources

I recommend to play around it in AI Studio first to test the prompt and tools, thanks

@HungGithubUser
Copy link

Added another PR to use googleSearch in typescript

@Glutch
Copy link

Glutch commented Apr 3, 2025

@Glutch Could you try a more specific prompt?

for example could you return the latest Iphone 16 price?, it returned the results with search sources

I recommend to play around it in AI Studio first to test the prompt and tools, thanks

Two months later, this issue still feels critical. I've built multiple services that heavily rely on search grounding, and I consistently struggle to get long prompts to trigger a search. We need a boolean option to force a search, similar to how dynamic_threshold worked before. Even better would be to provide the AI with exactly what to search for, for most cases i know exactly what would be the best search query - letting the ai come up with search queries isn't always the best option either.

It feels like the API is developed to work autonomously like a chat client, we're developers, not grandmas, we can handle it

@hkt74
Copy link
Collaborator

hkt74 commented Apr 3, 2025

Hi @Glutch do you have an example prompt to reproduce the issue? thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component:js sdk Issue/PR related to JavaScript SDK status:triaged Issue/PR triaged to the corresponding sub-team type:bug Something isn't working
Projects
None yet
Development

No branches or pull requests