Can't configure generate_content for a filesearchstore

google.generativeai version is 0.8.5

I’m new to using the google api and having a problem doing a basic generate_content against a file search store that I have already created and uploaded 40-something PDFs files to.

I’ve looked at examples for how to configure the tool or to use GenerateContentConfig all to no avail. It seems that in every attempt I use, there’s no FileSearchStore type or option to use as a config…

First method, error is “module google.generativeai.types has no attribute GenerateContentConfig

import google.generativeai as genai
import google.generativeai.types as types
 
print(dir(types))
print(genai.__version__)

genai.configure(api_key=key)
model = genai.GenerativeModel('gemini-2.5-pro')

response1 = model.generate_content(
    contents="How many files were uploaded?",
    config=types.GenerateContentConfig(
        tools=[
            types.Tool(
                file_search=types.FileSearch(
                    file_search_store_names=[myFileSearchStoreName]
                )
            )
        ]
    )
)

print(response1.text)

Alternative methods.. pre-creating the configs…

Example 2, error: AttributeError: module ‘google.generativeai.types’ has no attribute ‘FileSearch’


generateSearchTool = types.GenerationConfigType(
    tools=[
        types.Tool(
            file_search=types.FileSearch(
                file_search_store_names=[myFileSearchStoreName]
            )
        )
    ]
)

response2 = model.generate_content(
    contents="How many tariff files were uploaded?",
    tools=[generateSearchTool]
)

print(response2.text)

Example 3, error TypeError: Tool._init_() got an unexpected keyword argument ‘file_search’

fileTool = types.Tool(
    file_search={
        'file_search_stores':[myFileSearchStoreName]
    }
)

  
response3 = model.generate_content(
    "How many tariff files were uploaded?",
    tools=[fileTool]
)
print(response3.text)

Example 4. error module ‘google.generativeai.types’ has no attribute ‘ToolConfig’

tool_config = types.ToolConfig(
    file_search_config=types.FileSearchConfig(
        file_search_store_names=[myFileSearchStoreName]
    )
)

response4 = model.generate_content(
    "How many tariff files were uploaded?",
    tool_config=tool_config
)

print(response4.text)

Can anyone shed any light?

Hi @SANIT,

Welcome to the Google AI Forum! :confetti_ball: :confetti_ball:

It looks like you’re encountering some issues with configuring generate_content for a FileSearchStore using the google.generativeai library.

Corrected Approach with google.generativeai.client

Once your File Search Store is set up and files are uploaded, you would define a Tool object that points to your myFileSearchStoreName.

Please refer to this documentation for correct pattern