|
| 1 | +# Django PDF Chat with Google Gemini (RAG) |
| 2 | + |
| 3 | +A simple and powerful Django-based web application that allows users to upload PDF documents and chat with their content using Retrieval-Augmented Generation (RAG). Powered by **LangChain** and **Google Gemini AI**. |
| 4 | + |
| 5 | +## 🚀 Features |
| 6 | + |
| 7 | +- **PDF Upload**: Easily upload and manage multiple PDF documents. |
| 8 | +- **RAG Architecture**: Uses LangChain to split, embed, and store document context for accurate AI responses. |
| 9 | +- **Google Gemini Integration**: |
| 10 | + - **Embeddings**: `models/gemini-embedding-001` |
| 11 | + - **Chat LLM**: `models/gemini-flash-latest` |
| 12 | +- **Vector Store**: Local **FAISS** index for fast and efficient retrieval. |
| 13 | +- **Modern UI**: Sidebar for document selection and a real-time chat interface. |
| 14 | + |
| 15 | +## 🛠️ Prerequisites |
| 16 | + |
| 17 | +- Python 3.10 or higher |
| 18 | +- A Google Gemini API Key (get one at [aistudio.google.com](https://aistudio.google.com/)) |
| 19 | + |
| 20 | +## 📦 Installation & Setup |
| 21 | + |
| 22 | +1. **Clone the repository** (or navigate to the project folder). |
| 23 | + |
| 24 | +2. **Create and activate a virtual environment**: |
| 25 | + ```bash |
| 26 | + python3 -m venv venv |
| 27 | + source venv/bin/activate |
| 28 | + ``` |
| 29 | + |
| 30 | +3. **Install dependencies**: |
| 31 | + ```bash |
| 32 | + pip install -r requirements.txt |
| 33 | + ``` |
| 34 | + |
| 35 | +4. **Configure Environment Variables**: |
| 36 | + Create a `.env` file in the root directory (already initialized if you followed the setup): |
| 37 | + ```env |
| 38 | + GOOGLE_API_KEY=your_actual_gemini_api_key_here |
| 39 | + ``` |
| 40 | + |
| 41 | +5. **Run Migrations**: |
| 42 | + ```bash |
| 43 | + python manage.py makemigrations |
| 44 | + python manage.py migrate |
| 45 | + ``` |
| 46 | + |
| 47 | +6. **Start the server**: |
| 48 | + ```bash |
| 49 | + python manage.py runserver |
| 50 | + ``` |
| 51 | + |
| 52 | +7. **Access the app**: |
| 53 | + Open [http://127.0.0.1:8000](http://127.0.0.1:8000) in your browser. |
| 54 | + |
| 55 | +## 📂 Project Structure |
| 56 | + |
| 57 | +- `chat/`: Main Django app containing logic for PDF processing and chat. |
| 58 | +- `chat/utils.py`: Core LangChain RAG pipeline. |
| 59 | +- `vector_stores/`: Local storage for FAISS indices (ignored by git). |
| 60 | +- `media/pdfs/`: Uploaded PDF files (ignored by git). |
| 61 | +- `.env`: Stores sensitive API keys. |
| 62 | + |
| 63 | +## 🔧 Troubleshooting |
| 64 | + |
| 65 | +- **429 RESOURCE_EXHAUSTED**: You've hit the Google Gemini free tier rate limit. Wait 60 seconds and try again. |
| 66 | +- **404 NOT_FOUND**: This usually means the model name or API version is incorrect. The project is currently tuned to `models/gemini-flash-latest`. |
| 67 | +- **Vector store not found**: Ensure the PDF status shows as "Completed" in the sidebar before chatting. If it says "Failed", check the server console for errors. |
| 68 | + |
| 69 | +## 📝 License |
| 70 | +MIT |
0 commit comments