Google File Search API templates, configuration patterns, and usage examples for managed RAG with Gemini. Use when building File Search integrations, implementing RAG with Google AI, chunking documents, configuring grounding citations, or when user mentions Google File Search, Gemini RAG, document indexing, or semantic search.
Limited to specific tools
Additional assets for this skill
This skill is limited to using the following tools:
examples/advanced-chunking.mdexamples/basic-setup.mdexamples/grounding-citations.mdexamples/metadata-filtering.mdexamples/multi-store.mdscripts/configure_chunking.pyscripts/extract_citations.pyscripts/search_query.pyscripts/setup_file_search.pyscripts/upload_documents.pyscripts/validate_setup.pytemplates/chunking-config.jsontemplates/env.exampletemplates/metadata-schema.jsontemplates/python-client.pytemplates/store-config.jsonComprehensive skill for implementing Google File Search API with Gemini models for Retrieval-Augmented Generation (RAG).
Google File Search provides managed RAG capabilities through:
This skill provides templates, scripts, and examples for implementing File Search in Python applications using the google-generativeai package.
This skill is automatically invoked when:
CRITICAL: All templates and examples use placeholder values:
❌ NEVER hardcode actual API keys
✅ ALWAYS use: GOOGLE_API_KEY=your_google_api_key_here
✅ ALWAYS use: GOOGLE_GENAI_API_KEY=your_google_genai_api_key_here
✅ ALWAYS read from environment variables in code
✅ ALWAYS add .env* to .gitignore (except .env.example)
Obtain API keys from: https://aistudio.google.com/apikey
Before implementing File Search, fetch the latest documentation:
WebFetch: https://ai.google.dev/gemini-api/docs/file-search
WebFetch: https://ai.google.dev/gemini-api/docs/embeddings
Use the Python setup script to create a new store:
python scripts/setup_file_search.py --name "My RAG Store"
This Python script:
Customize chunking for your document domain:
python scripts/configure_chunking.py --max-tokens 200 --overlap 20
Generates configuration file with:
Upload files to the store:
python scripts/upload_documents.py --path /path/to/documents
This script:
Verify search functionality:
python scripts/search_query.py --query "your search query"
Tests:
Run comprehensive validation:
python scripts/validate_setup.py
Checks:
scripts/setup_file_search.pyInitialize a new file search store with display name.
Usage:
python scripts/setup_file_search.py --name "Store Name"
scripts/upload_documents.pyUpload and index documents to a file search store.
Usage:
python scripts/upload_documents.py --path /path/to/documents
python scripts/upload_documents.py --file /path/to/file.pdf --metadata author="John Doe"
scripts/configure_chunking.pyGenerate chunking configuration file.
Usage:
python scripts/configure_chunking.py --max-tokens 200 --overlap 20
python scripts/configure_chunking.py --preset small # 100 tokens, 10 overlap
python scripts/configure_chunking.py --preset large # 500 tokens, 50 overlap
scripts/search_query.pyTest semantic search with sample queries.
Usage:
python scripts/search_query.py --query "explain quantum computing"
python scripts/search_query.py --query "author=Einstein" --metadata-filter
scripts/validate_setup.pyComprehensive validation of File Search configuration.
Usage:
python scripts/validate_setup.py
python scripts/validate_setup.py --verbose
templates/store-config.json
templates/chunking-config.json
templates/metadata-schema.json
templates/env.example
templates/python-setup.py
Complete Python implementation template:
templates/typescript-setup.ts
Complete TypeScript implementation template:
examples/basic-setup.mdSimple File Search implementation for getting started:
examples/advanced-chunking.mdCustom chunking strategies for different document types:
examples/metadata-filtering.mdUsing metadata for targeted search:
examples/grounding-citations.mdExtract and display source citations:
examples/multi-store.mdManage multiple file search stores:
Documents: PDF, DOCX, ODT, PPTX, XLSX, CSV, TXT, MD Code: Python, JavaScript, Java, TypeScript, Go, Rust, SQL Data: JSON, XML, YAML, HTML Archives: ZIP (automatically extracted)
Over 100 MIME types supported.
Per-Document:
Total Storage by Tier:
Storage calculation: Input size × ~3 (includes embeddings)
Optimization tip: Index documents once, query multiple times for cost efficiency.
Chunk Size Optimization
Metadata Strategy
Store Organization
Citation Handling
Error Handling
from google import genai
from fastapi import FastAPI, HTTPException
app = FastAPI()
client = genai.Client(api_key=os.getenv("GOOGLE_API_KEY"))
@app.post("/search")
async def search(query: str, store_id: str):
response = client.models.generate_content(
model="gemini-2.5-flash",
contents=query,
config={
"tools": [{"file_search": {"store_id": store_id}}]
}
)
return {
"answer": response.text,
"citations": response.candidates[0].grounding_metadata
}
// app/api/search/route.ts
import { GoogleGenAI } from '@google/generative-ai';
export async function POST(request: Request) {
const { query, storeId } = await request.json();
const genai = new GoogleGenAI(process.env.GOOGLE_API_KEY!);
const model = genai.getGenerativeModel({ model: 'gemini-2.5-flash' });
const result = await model.generateContent({
contents: [{ role: 'user', parts: [{ text: query }] }],
tools: [{ fileSearch: { storeId } }]
});
return Response.json({
answer: result.response.text(),
citations: result.response.candidates[0].groundingMetadata
});
}
Issue: Files not uploading
Issue: Poor search results
Issue: Missing citations
Issue: Quota exceeded
Skill Version: 1.0.0 Last Updated: 2025-11-11 Compatible With: Gemini 2.5 Pro/Flash, Google GenAI SDK