|
| 1 | +--- |
| 2 | +title: Gemini File Search Stores |
| 3 | +description: Manage Google Gemini File Search Stores with automatic document uploads, organization, and synchronization for RAG workflows. |
| 4 | +--- |
| 5 | + |
| 6 | +A complete solution for managing Gemini's [File Search Stores](https://ai.google.dev/api/file-search), enabling **RAG (Retrieval Augmented Generation)** workflows with automatic document uploads, category organization, and bidirectional sync between your local database and Gemini's cloud storage. |
| 7 | + |
| 8 | +Build up your own knowledge base in File Stores, optionally organized into categories, that you can query to ground your AI chats with your own data - whether that's searching across a single document, a category of related documents, or your entire filestore. |
| 9 | + |
| 10 | +Here's an example of querying the single [v3 Release Notes](/docs/v3) document for its best features: |
| 11 | + |
| 12 | +<Screenshot src="/img/gemini-search-document.webp" /> |
| 13 | + |
| 14 | +## Install |
| 15 | + |
| 16 | +Install the **gemini** extension via the CLI: |
| 17 | + |
| 18 | +<ShellCommand>llms --add gemini</ShellCommand> |
| 19 | + |
| 20 | +#### Required |
| 21 | + |
| 22 | +To use this extension, you must configure your Gemini API key. |
| 23 | + |
| 24 | +1. Obtain an API key from [Google AI Studio](https://aistudio.google.com/). |
| 25 | +2. Add it to your environment variables or `.env` file: |
| 26 | + |
| 27 | +```bash |
| 28 | +GEMINI_API_KEY=your_api_key_here |
| 29 | +``` |
| 30 | + |
| 31 | +## Features |
| 32 | + |
| 33 | +- **Filestore Management**: Create and manage isolated stores of documents for different projects or knowledge bases. |
| 34 | +- **Drag & Drop Uploads**: Easily upload documents (PDF, Text, Markdown, etc.) by dragging them into the UI or clicking on it to open the File picker. |
| 35 | +- **Smart Categorization**: Organize documents into categories (folders) for granular retrieval. |
| 36 | +- **Contextual RAG Chat**: |
| 37 | + - **Ask Filestore**: Chat with the entire knowledge base of a filestore. |
| 38 | + - **Ask Category**: Focus your chat on a specific category within a filestore. |
| 39 | + - **Ask Document**: Chat with a single specific document. |
| 40 | +- **Bi-Directional Sync**: The "Sync Store" feature reconciles your local database with the remote Gemini File API, ensuring consistency. |
| 41 | + |
| 42 | +## Usage |
| 43 | + |
| 44 | +From your home page you can click the **Chat** icon to start a RAG chat session against all documents in your filestore. Or click the filestore list item to open it and manage documents. |
| 45 | + |
| 46 | +<Screenshot src="/img/gemini-filestores.webp" /> |
| 47 | + |
| 48 | +### 1. Creating a Filestore |
| 49 | + |
| 50 | +First step is to create a Filestore to hold your documents. Navigate to the Gemini extension page and click **New Store**. Give it a descriptive name (e.g., "Project Documentation"). This creates a logical container in the Gemini Filestore Search API. |
| 51 | + |
| 52 | +<Screenshot src="/img/gemini-filestores-create.webp" /> |
| 53 | + |
| 54 | +### macOS Performance |
| 55 | + |
| 56 | +⚠️ For a yet unknown reason, Gemini filestore operations takes seconds on our Linux systems, but can take up to several minutes on our macOS desktops (on same network). |
| 57 | +The Create/Delete Filestore operations are synchronous and block the UI and server until completed, but once created document uploads are asynchronous and run by a Background Worker DB Queue without blocking the UI. |
| 58 | + |
| 59 | +## Filestore UI |
| 60 | + |
| 61 | +Once you've created a Filestore, clicking on it opens the Filestore management interface where you can upload, organize, and interact with your documents. |
| 62 | + |
| 63 | +<Screenshot src="/img/gemini-filestores-new.webp" /> |
| 64 | + |
| 65 | +#### Summary |
| 66 | +Displays aggregate statistics about the filestore including total document count and storage size. |
| 67 | +The **New Chat** button or the **Chat Icon** next to **All Documents** lets you quickly start a conversation using all documents as context. |
| 68 | + |
| 69 | +#### Documents Section |
| 70 | +- **New Category**: Type a category name and click the folder icon to create a new organizational folder before uploading |
| 71 | +- **Upload Zone**: Drag and drop files or click to open the file picker. Supports PDFs, Text files, and Markdown documents |
| 72 | +- **Search**: Filter documents by name |
| 73 | +- **Sort**: Order documents by "Newest First" or other criteria |
| 74 | + |
| 75 | +#### Store Management |
| 76 | +- **Sync Store**: Reconciles your local database with Gemini's remote storage to detect and resolve any discrepancies |
| 77 | +- **Delete Store**: Permanently removes the filestore and all its documents from both local storage and Gemini's servers |
| 78 | + |
| 79 | +### 2. Uploading Documents |
| 80 | + |
| 81 | +You can drag and drop files directly onto the drop zone or click the file icon to select files. |
| 82 | + |
| 83 | +<Screenshot src="/img/gemini-filestores-upload-single.webp" /> |
| 84 | + |
| 85 | +When uploading, the UI will order the documents by **Uploading** where it shows the progress of the current document being uploaded first, followed by documents yet to be uploaded. |
| 86 | + |
| 87 | +- **Supported Formats**: Text, Markdown, PDF, and other text-based formats. |
| 88 | +- **Categories**: You can type a category name (e.g., "API Docs") in the input field before uploading to automatically organize files. |
| 89 | + |
| 90 | +<Screenshot src="/img/gemini-filestores-upload-folder.webp" /> |
| 91 | + |
| 92 | +### 3. Chatting with Data |
| 93 | +Once your documents are uploaded and processed (status shows as "Active"), you can start a RAG chat: |
| 94 | +- Click the **Chat Icon** next to the Filestore name in the list to chat all documents in the store. |
| 95 | +- Inside a Filestore, click the **Chat Icon** on a specific Category to limit the context to that folder. |
| 96 | +- Click the **Chat Icon** on an individual document to ask questions about that specific file only. |
| 97 | + |
| 98 | +## Query All Documents in the Store |
| 99 | + |
| 100 | +Each RAG Session starts a new Chat configured with a **Gemini Model** and the `file_search` tool pre-configured to use the selected filestore, category, or document, as visually indicated by the header labels. |
| 101 | + |
| 102 | +<Screenshot src="/img/gemini-search-all.webp" /> |
| 103 | + |
| 104 | +The bottom of the Chat session shows the grounded sources used to answer your query. |
| 105 | + |
| 106 | +You can expand the sources section to see which documents were used to answer your query. |
| 107 | + |
| 108 | +<Screenshot src="/img/gemini-search-all-expanded.webp" /> |
| 109 | + |
| 110 | +As sources contain incomplete fragments of your documents, they may not render perfectly in the UI. If needed you can click the filename to download the full original document for reference. |
| 111 | + |
| 112 | +## Query only Documents in a Category |
| 113 | + |
| 114 | +When querying a specific category, the extension automatically constructs the `file_search` tool call with the appropriate `metadata_filter` to limit the query to that category of documents. |
| 115 | + |
| 116 | +<Screenshot src="/img/gemini-search-category.webp" /> |
| 117 | + |
| 118 | +## Query a Single Document |
| 119 | + |
| 120 | +Simarly, when querying a specific document, the extension constructs the `file_search` tool call with the appropriate `metadata_filter` to limit the query to that single document. |
| 121 | + |
| 122 | +<Screenshot src="/img/gemini-search-document.webp" /> |
| 123 | + |
| 124 | +### 4. Syncing |
| 125 | +If you suspect your local data is out of sync with Gemini (e.g., after manual deletion in AI Studio or network interruptions), click the **Sync Store** button. |
| 126 | +- The sync report will show any discrepancies. |
| 127 | +- It will automatically attempt to repair issues where possible (e.g., updating local metadata). |
| 128 | +- It highlights files that are missing locally or remotely. |
| 129 | + |
| 130 | +<Screenshot src="/img/gemini-sync.webp" /> |
| 131 | + |
| 132 | + |
| 133 | +## Configuration |
| 134 | + |
| 135 | + |
| 136 | +#### Optional |
| 137 | + |
| 138 | +```bash |
| 139 | +# Override MIME types for specific file extensions (comma-separated) |
| 140 | +# Format: extension:mime/type,extension:mime/type |
| 141 | +GEMINI_UPLOAD_MIME_TYPES="mdx:text/markdown,cshtml:text/html" |
| 142 | +``` |
| 143 | + |
| 144 | +Although Gemini Filestore docs indicate support for a [wide range of MIME types](https://ai.google.dev/gemini-api/docs/file-search#application), in practice many aren't detected or supported correctly. If you encounter an error with automatic detection or find that a particular MIME type isn't supported, you can use this variable to override the MIME type for specific file extensions during upload to ensure proper indexing and searchability. |
| 145 | + |
| 146 | +### Database Storage |
| 147 | +The extension automatically creates a SQLite database at: |
| 148 | +``` |
| 149 | +.llms/user/default/gemini/gemini.sqlite |
| 150 | +``` |
| 151 | + |
| 152 | +### File Cache |
| 153 | +Uploaded files are stored in the cache directory with SHA-256 hash-based filenames: |
| 154 | +``` |
| 155 | +~/.llms/cache/[hash_prefix]/[hash].[ext] |
| 156 | +~/.llms/cache/[hash_prefix]/[hash].info.json |
| 157 | +``` |
| 158 | + |
| 159 | +## Key Features |
| 160 | + |
| 161 | +### Intelligent Document Management |
| 162 | +- **Automatic Deduplication**: SHA-256 hash-based duplicate detection prevents redundant uploads |
| 163 | +- **Category Organization**: Organize documents into logical categories for better management |
| 164 | +- **Custom Metadata**: Track documents with ID, hash, and category metadata |
| 165 | +- **State Tracking**: Monitor document states (PENDING, ACTIVE, FAILED) throughout their lifecycle |
| 166 | + |
| 167 | +### Background Upload Worker |
| 168 | +- **Asynchronous Processing**: Automatically processes pending uploads in the background |
| 169 | +- **Auto-start on Upload**: Worker automatically starts when new documents are uploaded |
| 170 | +- **Startup Processing**: Processes any pending uploads from previous sessions on extension startup |
| 171 | +- **Batch Processing**: Efficiently handles multiple documents in batches of 10 |
| 172 | +- **Automatic Metadata Updates**: Keeps filestore statistics up-to-date after uploads complete |
| 173 | + |
| 174 | +### Smart Synchronization |
| 175 | +- **Bidirectional Sync**: Identify documents missing from local or remote stores |
| 176 | +- **Metadata Validation**: Detect and fix metadata mismatches between local and remote |
| 177 | +- **Duplicate Detection**: Find and flag duplicate documents in remote stores |
| 178 | +- **State Management**: Automatically update document states based on sync results |
| 179 | +- **Detailed Reporting**: Comprehensive sync reports with counts and sample documents |
| 180 | + |
| 181 | +### Custom MIME Type Support |
| 182 | +- **Configurable Types**: Override MIME types for specific file extensions via environment variable |
| 183 | +- **Markdown Extensions**: Pre-configured support for mdx, l, ss, sc extensions as text/markdown |
| 184 | +- **Upload Optimization**: Ensures correct MIME types for better search indexing |
| 185 | + |
| 186 | +### Robust Error Handling |
| 187 | +- **Comprehensive Logging**: Track all operations with detailed debug information |
| 188 | +- **Error Recovery**: Gracefully handle failures and store error messages for review |
| 189 | +- **Retry Capability**: Manual retry endpoint for failed uploads |
| 190 | +- **ClientError Handling**: Proper handling of 404s and other Gemini API errors |
| 191 | + |
0 commit comments