Chat with your documents using Google Gemini 2.5 FileSearch and FastAPI
- 📄 Multi-format Support - Upload PDF, TXT, or MD files
- 💬 Bilingual Chat - Works with both Thai and English
- 🔍 RAG-Powered - Accurate answers using Google FileSearch
- 🎨 Beautiful UI - Modern, responsive design with gradient backgrounds
- 📊 Smart Formatting - Automatic table and markdown rendering
- 🚀 Fast & Lightweight - Built with FastAPI for high performance
- Backend: FastAPI + Uvicorn
- AI Model: Google Gemini 2.5 Flash
- RAG: Google FileSearch API
- Frontend: Vanilla JavaScript (No frameworks!)
- Styling: Custom CSS3 with responsive design
- Python 3.11 or higher
- Google API Key (Get one here)
-
Clone the repository
git clone https://github.com/spped2000/gemini-filesearch-chat.git cd gemini-filesearch-chat -
Create virtual environment
python -m venv .venv source .venv/bin/activate # On Windows: .venv\Scripts\activate
-
Install dependencies
pip install fastapi uvicorn python-multipart aiofiles google-genai python-dotenv
-
Configure environment variables
cp .env.example .env # Edit .env and add your Google API key -
Run the application
python app.py
-
Open your browser
http://localhost:8000
-
Upload a Document:
- Drag and drop a file onto the upload area, or
- Click "Or Browse Files" to select a file from your computer
- Supported formats: PDF, TXT, MD
-
Chat with Your Document:
- Once uploaded, you'll be taken to the chat interface
- Type your question in the input field
- Press Enter or click the send button
- The AI will search through your document and provide relevant answers
-
Start Over:
- Click the × button next to the document name to close and upload a new document
- Framework: FastAPI with async/await support
- Server: Uvicorn ASGI server
- File Handling: python-multipart + aiofiles for async file operations
- Environment: python-dotenv for configuration
- Model: Google Gemini 2.5 Flash
- RAG System: Google FileSearch API
- Document Processing: Automatic file upload and indexing
- Search: Vector-based document retrieval
- Vanilla JavaScript - No frameworks, pure JS
- Modern CSS3 - Gradient backgrounds, animations
- Responsive Design - Works on desktop and mobile
- Markdown Rendering - Smart formatting for tables and structured data
- Drag & Drop: Native HTML5 drag-drop API
- File Upload: FormData with async fetch
- Chat Interface: Real-time message streaming
- Table Formatting: Markdown to HTML conversion
- Bilingual Support: Automatic Thai/English detection
GET /- Main application interfacePOST /upload- Upload a document and create a file search storePOST /chat- Send a message and get AI responseGET /stores- List all uploaded documentsDELETE /store/{store_id}- Delete a document store
file_search_test/
├── app.py # FastAPI backend
├── test_filesearch.py # Original test script
├── .env # Environment variables
├── static/
│ ├── index.html # Main UI
│ ├── styles.css # Styling
│ └── script.js # Frontend logic
└── uploads/ # Uploaded files directory
- Files are automatically renamed to ASCII-safe names to avoid encoding issues
- Each document upload creates a unique file search store
- Chat history is maintained per session but not persisted
- The application runs on port 8000 by default

