google-gemini-file-search

Verified·Scanned 2/18/2026

This skill provides setup and examples for Google Gemini File Search, including scripts and templates to create stores, upload documents, and query with grounding metadata. It requires the GOOGLE_API_KEY, reads local files such as ./docs/manual.pdf, and makes network calls to https://generativelanguage.googleapis.com.

by jezweb·v10a1f16·62.1 KB·329 installs
Scanned from main at 10a1f16 · Transparency log ↗
$ vett add jezweb/claude-skills/google-gemini-file-search

Google Gemini File Search Skill

Fully managed RAG (Retrieval-Augmented Generation) for document Q&A, knowledge bases, and semantic search using Google Gemini's File Search API

Auto-Trigger Keywords

This skill automatically activates when you mention:

Primary Keywords:

  • file search
  • gemini rag
  • document search
  • knowledge base
  • semantic search
  • google embeddings
  • file upload gemini
  • managed rag
  • automatic citations
  • document qa
  • retrieval augmented generation
  • vector search gemini
  • grounding
  • file indexing

Use Case Keywords:

  • customer support knowledge base
  • internal documentation search
  • legal document analysis
  • research paper search
  • code documentation search
  • product information retrieval
  • FAQ search
  • manual indexing

Technical Keywords:

  • @google/genai
  • gemini file search api
  • gemini embeddings
  • document chunking
  • metadata filtering
  • file search store
  • grounding metadata

What This Skill Does

This skill provides complete setup guidance for Google Gemini File Search—a fully managed RAG system that eliminates the need for separate vector databases or custom embedding code. Simply upload documents (PDFs, Word, Excel, code files, etc.) and query them using natural language.

Key Capabilities:

  • 🗂️ 100+ File Formats: Automatic text extraction from PDFs, Word, Excel, PowerPoint, Markdown, JSON, CSV, code files
  • 🧠 Semantic Search: Vector-based search understands meaning and context, not just keywords
  • 📑 Built-in Citations: Grounding metadata automatically points to specific document sections
  • ⚙️ Configurable Chunking: Control chunk size and overlap for optimal retrieval
  • 🏷️ Metadata Filtering: Filter queries by up to 20 custom key-value pairs per document
  • 💰 Cost-Effective: $0.15/1M tokens for one-time indexing, free storage (up to limits)

When to Use This Skill

✅ Use Gemini File Search when:

  • Building document Q&A systems (customer support, internal docs)
  • Creating searchable knowledge bases (wikis, policies, manuals)
  • Implementing semantic search over custom data
  • Need automatic citations for compliance/transparency
  • Want managed RAG without vector DB setup
  • Cost predictability matters (pay-per-indexing, not storage)

❌ Use alternatives when:

  • Need custom embedding models → Use Cloudflare Vectorize
  • Documents update frequently → Consider streaming alternatives
  • Building conversational AI agents → Use OpenAI Assistants or Claude MCP
  • Need global edge performance → Use Cloudflare AutoRAG

Errors Prevented (8 Total)

This skill prevents common implementation errors:

  1. Document Immutability - Documents can't be edited after indexing (must delete+re-upload)
  2. Storage Quota Calculation - Storage = 3x input size (includes embeddings)
  3. Incorrect Chunking Config - Default settings may not be optimal (500 tokens/chunk recommended)
  4. Metadata Limits - Max 20 custom key-value pairs per document
  5. Indexing Cost Surprises - One-time $0.15/1M tokens can add up for large corpora
  6. Operation Polling - Must poll operation status until done: true
  7. Force Delete Required - Stores with documents require force: true to delete
  8. Unsupported Models - Only Gemini 3 Pro/Flash supported (not 2.x or 1.5 models)

What's Included

📖 Comprehensive Documentation

  • Complete setup guide with TypeScript/JavaScript examples
  • 8 documented common errors with prevention strategies
  • Chunking best practices for different content types
  • Metadata schema design patterns
  • Cost optimization techniques
  • Comparison guide (vs Vectorize, OpenAI Files API, Claude MCP)

🛠️ CLI Scripts

  • scripts/create-store.ts - Create and manage file search stores
  • scripts/upload-batch.ts - Batch document upload with progress tracking
  • scripts/query-store.ts - Interactive query tool with citation display
  • scripts/cleanup.ts - Delete stores and documents

📦 Working Templates

  1. basic-node-rag/ - Minimal Node.js/TypeScript example (learning, prototyping)
  2. cloudflare-worker-rag/ - Edge deployment with Cloudflare Workers + R2 integration
  3. nextjs-docs-search/ - Full-stack Next.js app with upload UI and search interface

📚 Reference Documentation

  • references/api-reference.md - Complete API documentation
  • references/chunking-best-practices.md - Detailed chunking strategies
  • references/pricing-calculator.md - Cost estimation guide
  • references/migration-from-openai.md - Migration from OpenAI Files API

Quick Start

import { GoogleGenAI } from '@google/genai'
import fs from 'fs'

// 1. Initialize client
const ai = new GoogleGenAI({
  apiKey: process.env.GOOGLE_API_KEY
})

// 2. Create file search store
const fileStore = await ai.fileSearchStores.create({
  config: { displayName: 'my-knowledge-base' }
})

// 3. Upload documents
const operation = await ai.fileSearchStores.uploadToFileSearchStore({
  name: fileStore.name,
  file: fs.createReadStream('./docs/manual.pdf'),
  config: {
    displayName: 'Installation Manual',
    customMetadata: {
      doc_type: 'manual',
      version: '1.0'
    },
    chunkingConfig: {
      whiteSpaceConfig: {
        maxTokensPerChunk: 500,
        maxOverlapTokens: 50
      }
    }
  }
})

// 4. Poll until indexing complete
while (!operation.done) {
  await new Promise(resolve => setTimeout(resolve, 1000))
  operation = await ai.operations.get({ name: operation.name })
}

// 5. Query with natural language
const response = await ai.models.generateContent({
  model: 'gemini-3-flash',
  contents: 'What are the safety precautions for installation?',
  config: {
    tools: [{
      fileSearch: { fileSearchStoreNames: [fileStore.name] }
    }]
  }
})

console.log('Answer:', response.text)

// 6. Access citations
const grounding = response.candidates[0].groundingMetadata
console.log('Sources:', grounding.groundingChunks)

Prerequisites

Token Efficiency

Without Skill:

  • ~15,000 tokens (trial-and-error setup)
  • 3-5 errors encountered (document immutability, storage quota, chunking issues)
  • Multiple iterations to get working

With Skill:

  • ~5,000 tokens (guided setup with working templates)
  • 0 errors (all 8 common errors documented and prevented)
  • First-try success

Savings: ~65% tokens

Supported File Formats

Documents: PDF, Word (.docx), Excel (.xlsx), PowerPoint (.pptx), Text (.txt), Markdown (.md), RTF

Code: JavaScript (.js), TypeScript (.ts), Python (.py), Java (.java), C++ (.cpp), Go (.go), Rust (.rs), Ruby (.rb), PHP (.php), Swift (.swift), Kotlin (.kt), and 50+ more

Data: JSON (.json), CSV (.csv), XML (.xml), YAML (.yaml)

Max File Size: 100 MB per file

Comparison with Alternatives

FeatureGemini File SearchCloudflare VectorizeOpenAI Files API
SetupSimpleModerateSimple
File Formats100+Manual20+
Max File Size100 MBN/A512 MB
Custom EmbeddingsNoYesNo
CitationsYesManualYes
PricingPay-per-indexUsage-basedStorage-based
Free Tier1 GBDeveloper1 GB

Examples

Customer Support Knowledge Base

// Upload support docs
await ai.fileSearchStores.uploadToFileSearchStore({
  name: fileStore.name,
  file: fs.createReadStream('./support/faq.pdf'),
  config: {
    customMetadata: {
      doc_type: 'faq',
      product: 'widget-pro',
      language: 'en'
    }
  }
})

// Query with metadata filtering
const response = await ai.models.generateContent({
  model: 'gemini-3-flash',
  contents: 'How do I reset the device?',
  config: {
    tools: [{
      fileSearch: {
        fileSearchStoreNames: [fileStore.name],
        metadataFilter: 'doc_type="troubleshooting" AND product="widget-pro"'
      }
    }]
  }
})

Code Documentation Search

// Upload API docs and examples
await ai.fileSearchStores.uploadToFileSearchStore({
  name: fileStore.name,
  file: fs.createReadStream('./docs/api-reference.md'),
  config: {
    customMetadata: {
      doc_type: 'api-reference',
      language: 'typescript',
      version: '1.0'
    },
    chunkingConfig: {
      whiteSpaceConfig: {
        maxTokensPerChunk: 500,  // Smaller chunks for code precision
        maxOverlapTokens: 50
      }
    }
  }
})

Legal Document Analysis

// Upload contracts with fine-grained chunking
await ai.fileSearchStores.uploadToFileSearchStore({
  name: fileStore.name,
  file: fs.createReadStream('./legal/contract.pdf'),
  config: {
    customMetadata: {
      doc_type: 'contract',
      jurisdiction: 'US',
      effective_date: '2025-01-01'
    },
    chunkingConfig: {
      whiteSpaceConfig: {
        maxTokensPerChunk: 300,  // Very small chunks for high precision
        maxOverlapTokens: 30
      }
    }
  }
})

Official Documentation

Version Information

  • Skill Version: 1.0.0
  • Last Verified: 2025-11-10
  • Package Version: @google/genai ^0.21.0
  • Supported Models: gemini-3-pro, gemini-3-flash
  • Node.js: >=18.0.0

License

MIT License - See LICENSE file for details

Maintainer

Jeremy Dawes (Jezweb)


Production Tested | Token Savings: ~65% | 8 Errors Prevented