Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/derailed-dash/gemini-file-search-demo/llms.txt

Use this file to discover all available pages before exploring further.

Every agent in this codelab reads its configuration from environment variables at startup. Setting these variables correctly — particularly GEMINI_API_KEY — is a prerequisite for running any of the SDK or ADK agents. This page walks you through obtaining an API key, creating your .env file, and loading the variables into your shell.

Environment variables

VariableRequiredDefaultDescription
GEMINI_API_KEYYesYour Gemini API key from Google AI Studio. The SDK reads this automatically via genai.Client().
MODELNogemini-2.5-flashThe Gemini model ID to use across all agents.
STORE_NAMENodemo-file-storeThe display name of the File Search Store to attach to RAG agents. Must match the name you used when creating the store in the notebook.
GEMINI_API_KEY must be set before running any agent. Every agent creates a genai.Client() on startup, which requires the key to be present in the environment.

Getting a Gemini API key

The Gemini File Search tool requires the Gemini Developer API, which uses an API key rather than service-account credentials.
1

Open Google AI Studio

Go to Google AI Studio and sign in with your Google account.
2

Create an API key

Follow the steps in the API key guide to generate a key for your Google Cloud project.
3

Copy and keep the key safe

Copy the key immediately after it is displayed. Store it somewhere secure — treat it like a password.

Creating your .env file

The repository ships with .env.template as a starting point. Copy it to .env and fill in your values.
1

Copy the template

cp .env.template .env
2

Edit the file

Open .env in your editor. The template contains:
export GEMINI_API_KEY="your-api-key"
export MODEL="gemini-2.5-flash"
export STORE_NAME="demo-file-store"
Replace your-api-key with your actual Gemini API key. Adjust MODEL and STORE_NAME if needed.
3

Load the variables

Run the following command in the same terminal session you will use to run the agents:
source .env
You must re-run source .env in any new terminal session before running an agent.
.env is listed in .gitignore. Never commit a file containing a real API key to version control.

What happens when STORE_NAME is not set or the store is not found

Both sdk_rag_agent.py and rag_agent_adk/agent.py perform a graceful fallback rather than crashing when the File Search Store is unavailable.
  • If STORE_NAME is not set at all, the agents log:
    WARNING - STORE_NAME env var not set. Skipping store lookup.
    
    and disable RAG capabilities for that session.
  • If STORE_NAME is set but no store with that display name exists, the agents log:
    WARNING - Store '<name>' not found! RAG capabilities disabled.
    
    and continue running without the File Search tool attached.
If the RAG agent starts successfully but cannot answer questions about the story, check that STORE_NAME matches the display name you used when creating the store in notebooks/file_search_store.ipynb. Display names are case-sensitive.

MODEL variable

All agents fall back to gemini-2.5-flash when MODEL is not set. To use a different model, set the variable before sourcing:
export MODEL="gemini-2.5-flash"
source .env
The model must support the tools you intend to use. File Search and Google Search are supported on current Gemini 2.x models. If you see a “model not found” error, verify the model ID is correct.

Build docs developers (and LLMs) love