Skip to content

Commit acda12f

Browse files
committed
Add gemini extension docs
1 parent 53809d6 commit acda12f

14 files changed

Lines changed: 197 additions & 2 deletions

content/docs/extensions/gemini.mdx

Lines changed: 191 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,191 @@
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+

content/docs/extensions/meta.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"server",
77
"ui",
88
"tools",
9-
"core-tools"
9+
"core-tools",
10+
"gemini"
1011
]
1112
}

content/docs/extensions/tools.mdx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,9 @@ All available tools are maintained in the GitHub [llmspy organization](https://g
118118

119119
| Tool | Description |
120120
|------|-------------|
121+
| `gemini` | Google Gemini RAG file search with document management, auto-upload, and sync capabilities |
121122
| `duckduckgo` | Add web search tool capabilities using Duck Duck Go |
123+
| `xmas` | Example of utilizing the Extensions APIs to give llms.py some Christmas spirit |
122124

123125
**List available extensions:**
124126

content/docs/v3.mdx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ description: Major release focused on extensibility, expanded provider support,
4545

4646
## Install
4747

48-
Get instant access to 530+ models from 23 providers with extensibility at its core:
48+
Get instant access to 530+ models from 24 providers with extensibility at its core:
4949

5050
<ShellCommand>pip install llms</ShellCommand>
5151

@@ -75,6 +75,7 @@ The switch to [models.dev](https://models.dev) greatly expands the model selecti
7575
| Fireworks AI | 12 | Moonshot AI | 5 |
7676
| GitHub Copilot | 27 | Nvidia | 24 |
7777
| GitHub Models | 55 | Zai | 6 |
78+
| Cerebras | 3 | | |
7879
| LMStudio | local | Ollama | local |
7980

8081
Non OpenAI Compatible LLM and Image generation providers are maintained in the [providers](https://github.com/ServiceStack/llms/tree/main/llms/extensions/providers) extension, registered using the `ctx.add_provider()` API.
18.5 KB
Loading
27.3 KB
Loading
55.3 KB
Loading
32.9 KB
Loading

public/img/gemini-filestores.webp

21.3 KB
Loading
56.5 KB
Loading

0 commit comments

Comments
 (0)