-
Notifications
You must be signed in to change notification settings - Fork 811
Incorrect Code Example for File Search Tool in Official Documentation #1703
Description
Component: google-generativeai Python SDK (File Search / Vector Store)
Bug Description:
https://ai.google.dev/gemini-api/docs/file-search?hl=ko
I am reporting an issue with the official documentation for the new File Search feature. The code snippet demonstrating how to use a file_search_store as a tool within client.models.generate_content is syntactically incorrect and does not work.
The documentation's example for the config parameter seems to be missing the required types.Tool and types.FileSearch class wrappers, which are necessary to properly structure the tool configuration.
Incorrect Code from Documentation
The following code, based on the documentation, fails with an error:
# This code from the documentation is incorrect
response = client.models.generate_content(
model="gemini-2.5-flash",
contents="""Can you tell me about Robert Graves""",
config=types.GenerateContentConfig(
tools=[
# This part is syntactically incorrect and missing the required classes
file_search=(
file_search_store_names=[file_search_store.name]
)
]
)
)Corrected & Working Code
To fix this, the tools list must contain a types.Tool object, which in turn uses a types.FileSearch object for its file_search argument, like so:
# This is the corrected, working version
response = client.models.generate_content(
model='gemini-2.5-flash',
contents='What does the research say about Robert Graves...',
config=types.GenerateContentConfig(
tools=[types.Tool( # <-- Must wrap in types.Tool
file_search=types.FileSearch( # <-- Must use types.FileSearch
file_search_store_names=[store.name]
)
)]
)
)Suggestion:
https://www.youtube.com/watch?v=D8323EQVGY8
Please update the official documentation to reflect the correct usage (the second code block) to avoid confusion for developers trying to implement this new feature.