From google-gemini-file-search
Implements Google Gemini File Search for managed RAG on 100+ file formats including PDF, code, Markdown. Use for document Q&A, knowledge bases, immutability errors, quotas, polling failures.
npx claudepluginhub secondsky/claude-skills --plugin google-gemini-file-searchThis skill uses the workspace's default tool permissions.
**Status**: Production Ready | **Last Verified**: 2025-11-18
Generates design tokens/docs from CSS/Tailwind/styled-components codebases, audits visual consistency across 10 dimensions, detects AI slop in UI.
Records polished WebM UI demo videos of web apps using Playwright with cursor overlay, natural pacing, and three-phase scripting. Activates for demo, walkthrough, screen recording, or tutorial requests.
Delivers idiomatic Kotlin patterns for null safety, immutability, sealed classes, coroutines, Flows, extensions, DSL builders, and Gradle DSL. Use when writing, reviewing, refactoring, or designing Kotlin code.
Status: Production Ready | Last Verified: 2025-11-18
Google Gemini File Search is fully managed RAG (Retrieval-Augmented Generation):
Key difference from other RAG:
Get API key: https://aistudio.google.com/apikey (Free tier: 1 GB storage, 1,500 requests/day)
bun add @google/genai
Version: 0.21.0+ | Node.js: 18+
import { GoogleGenerativeAI } from '@google/genai';
import fs from 'fs';
const ai = new GoogleGenerativeAI(process.env.GOOGLE_AI_API_KEY);
// Create store
const fileStore = await ai.fileSearchStores.create({
config: { displayName: 'my-knowledge-base' }
});
// Upload document
const operation = await ai.fileSearchStores.uploadToFileSearchStore({
name: fileStore.name,
file: fs.createReadStream('./manual.pdf'),
config: {
displayName: 'Installation Manual',
chunkingConfig: {
whiteSpaceConfig: {
maxTokensPerChunk: 500,
maxOverlapTokens: 50
}
}
}
});
// Poll until done
while (!operation.done) {
await new Promise(resolve => setTimeout(resolve, 1000));
operation = await ai.operations.get({ name: operation.name });
}
// Query documents
const model = ai.getGenerativeModel({
model: 'gemini-2.5-pro', // Only 2.5 Pro/Flash supported
tools: [{
fileSearchTool: {
fileSearchStores: [fileStore.name]
}
}]
});
const result = await model.generateContent('How do I install the product?');
console.log(result.response.text());
// Get citations
const grounding = result.response.candidates[0].groundingMetadata;
if (grounding) {
console.log('Sources:', grounding.groundingChunks);
}
Load references/setup-guide.md for complete walkthrough with batch uploads, error handling, and production checklist.
done: true (with timeout)Problem: Trying to update existing document
Solution: Delete + re-upload pattern
// Find and delete old version
const docs = await ai.fileSearchStores.documents.list({
parent: fileStore.name
});
const oldDoc = docs.documents.find(d => d.displayName === 'manual.pdf');
if (oldDoc) {
await ai.fileSearchStores.documents.delete({
name: oldDoc.name,
force: true
});
}
// Upload new version
await ai.fileSearchStores.uploadToFileSearchStore({
name: fileStore.name,
file: fs.createReadStream('manual-v2.pdf'),
config: { displayName: 'manual.pdf' }
});
Problem: Storage calculation wrong (3x multiplier)
Solution: Estimate before upload
const fileSize = fs.statSync('data.pdf').size;
const estimatedStorage = fileSize * 3; // Embeddings + metadata
if (estimatedStorage > 1e9) {
console.warn('⚠️ May exceed free tier 1 GB limit');
}
Problem: Using wrong model version
Solution: Use Gemini 2.5 only
// ✅ CORRECT
const model = ai.getGenerativeModel({
model: 'gemini-2.5-pro', // or gemini-2.5-flash
tools: [{ fileSearchTool: { fileSearchStores: [storeName] } }]
});
// ❌ WRONG
const model = ai.getGenerativeModel({
model: 'gemini-1.5-pro', // Not supported!
tools: [{ fileSearchTool: { fileSearchStores: [storeName] } }]
});
Load references/error-catalog.md for all 8 errors with detailed solutions including chunking, operation polling, metadata limits, and force delete requirements.
Cloudflare Vectorize - Global edge performance, custom embeddings, real-time R2 updates OpenAI Files API - Assistants API, conversational threads, very large collections (10,000+)
// Upload support docs with metadata
await ai.fileSearchStores.uploadToFileSearchStore({
name: fileStore.name,
file: fs.createReadStream('troubleshooting.pdf'),
config: {
displayName: 'Troubleshooting Guide',
customMetadata: {
doc_type: 'support',
category: 'troubleshooting',
language: 'en'
}
}
});
const files = ['doc1.pdf', 'doc2.md', 'doc3.docx'];
const uploadPromises = files.map(file =>
ai.fileSearchStores.uploadToFileSearchStore({
name: fileStore.name,
file: fs.createReadStream(file),
config: { displayName: file }
})
);
const operations = await Promise.all(uploadPromises);
// Poll all operations
for (const op of operations) {
let operation = op;
while (!operation.done) {
await new Promise(resolve => setTimeout(resolve, 1000));
operation = await ai.operations.get({ name: operation.name });
}
console.log('✅', operation.response.displayName);
}
// 1. List existing documents
const docs = await ai.fileSearchStores.documents.list({
parent: fileStore.name
});
// 2. Delete old version
const oldDoc = docs.documents.find(d => d.displayName === 'manual.pdf');
if (oldDoc) {
await ai.fileSearchStores.documents.delete({
name: oldDoc.name,
force: true
});
}
// 3. Upload new version
const operation = await ai.fileSearchStores.uploadToFileSearchStore({
name: fileStore.name,
file: fs.createReadStream('manual-v2.pdf'),
config: {
displayName: 'manual.pdf',
customMetadata: {
version: '2.0',
updated_at: new Date().toISOString()
}
}
});
// 4. Poll until done
while (!operation.done) {
await new Promise(resolve => setTimeout(resolve, 1000));
operation = await ai.operations.get({ name: operation.name });
}
Load references/setup-guide.md for additional patterns including code documentation search and internal knowledge bases.
references/setup-guide.md when:references/error-catalog.md when:100+ formats including:
Not supported: Images in PDFs (text extraction only), Audio files, Video files
Indexing (one-time): $0.15 per 1M tokens Storage: Free (10 GB - 1 TB depending on tier) Query embeddings: Free (retrieved context counts as input tokens)
Example: 1,000-page document ≈ 500k tokens → Indexing cost: $0.075 → Storage: ~1.5 GB (3x multiplier)
Technical docs: 500 tokens/chunk, 50 overlap Prose: 800 tokens/chunk, 80 overlap Legal: 300 tokens/chunk, 30 overlap
chunkingConfig: {
whiteSpaceConfig: {
maxTokensPerChunk: 500, // Smaller = more precise
maxOverlapTokens: 50 // 10% overlap recommended
}
}
References (references/):
setup-guide.md - Complete setup walkthrough (authentication, store creation, file upload, batch patterns, production checklist)error-catalog.md - All 8 documented errors with solutions (immutability, storage, chunking, metadata, costs, polling, force delete, model compatibility)Official Documentation:
Questions? Issues?
references/setup-guide.md for complete setupreferences/error-catalog.md for all 8 errors