|
| 1 | +# Agentic RAG with Gemini 2.0 Flash |
| 2 | + |
| 3 | +This is not just a simple "Chat with PDF" app. It's an **Agentic RAG (Retrieval Augmented Generation)** system powered by **Gemini 2.0 Flash**. The app first searches through the uploaded document for relevant information. If the required information is not found in the document, it seamlessly searches the web and returns a comprehensive response. |
| 4 | + |
| 5 | +--- |
| 6 | + |
| 7 | +## Features |
| 8 | +- **Upload PDF Documents:** Easily upload any PDF document to start querying. |
| 9 | +- **Agentic RAG Workflow:** Combines document retrieval with web search for accurate and comprehensive answers. |
| 10 | +- **Interactive Q&A:** Ask questions about the content of the uploaded PDF or general queries. |
| 11 | +- **Powered by Gemini 2.0 Flash:** Utilizes Google's Gemini 2.0 Flash model for fast and accurate responses. |
| 12 | +- **Web Search Integration:** If the document doesn't contain the required information, the app searches the web and provides relevant results. |
| 13 | + |
| 14 | +--- |
| 15 | + |
| 16 | +## Getting Started |
| 17 | + |
| 18 | +### 1. Clone the Repository |
| 19 | +Clone the GitHub repository to your local machine: |
| 20 | +```bash |
| 21 | +git clone https://github.com/reflex-dev/reflex-llm-examples.git |
| 22 | +cd reflex-llm-examples/agentic_rag |
| 23 | +``` |
| 24 | + |
| 25 | +### 2. Install Dependencies |
| 26 | +Install the required dependencies: |
| 27 | +```bash |
| 28 | +pip install -r requirements.txt |
| 29 | +``` |
| 30 | + |
| 31 | +### 3. Set Up Gemini API Key |
| 32 | +To use the Gemini 2.0 Flash model, you need a **Google API Key**. Follow these steps: |
| 33 | +Go to [Google AI Studio](https://aistudio.google.com/apikey), get your API Key an set the API key as an environment variable: |
| 34 | + ```bash |
| 35 | + export GOOGLE_API_KEY="your-api-key-here" |
| 36 | + ``` |
| 37 | + |
| 38 | +### 4. Run PgVector |
| 39 | +The app uses **PgVector** for vector storage and retrieval. Follow these steps to set it up: |
| 40 | + |
| 41 | +Install Docker Desktop first, then run: |
| 42 | +```bash |
| 43 | +docker run -d \ |
| 44 | + -e POSTGRES_DB=ai \ |
| 45 | + -e POSTGRES_USER=ai \ |
| 46 | + -e POSTGRES_PASSWORD=ai \ |
| 47 | + -e PGDATA=/var/lib/postgresql/data/pgdata \ |
| 48 | + -v pgvolume:/var/lib/postgresql/data \ |
| 49 | + -p 5532:5432 \ |
| 50 | + --name pgvector \ |
| 51 | + agnohq/pgvector:16 |
| 52 | +``` |
| 53 | + |
| 54 | +### 5. Run the Reflex App |
| 55 | +Start the application to begin interacting with your PDF: |
| 56 | +```bash |
| 57 | +reflex run |
| 58 | +``` |
| 59 | + |
| 60 | +--- |
| 61 | + |
| 62 | +## How It Works |
| 63 | +1. **Upload a PDF:** The app processes the document and creates a searchable knowledge base. |
| 64 | +2. **Ask Questions:** The app first searches the uploaded document for relevant information. |
| 65 | +3. **Web Search Fallback:** If the document doesn't contain the required information, the app searches the web using **DuckDuckGo** and returns the most relevant results. |
| 66 | +4. **Comprehensive Responses:** The app combines information from the document and the web to provide accurate and detailed answers. |
| 67 | + |
| 68 | +--- |
| 69 | + |
| 70 | +## Why Agentic RAG? |
| 71 | +- **Document-Centric:** Focuses on extracting information from the uploaded PDF. |
| 72 | +- **Web-Augmented:** Ensures no query goes unanswered by leveraging web search when needed. |
| 73 | +- **Efficient and Accurate:** Combines the best of both worlds for a seamless experience. |
| 74 | + |
| 75 | +--- |
| 76 | + |
| 77 | +## Troubleshooting |
| 78 | +- **Gemini API Key Not Set:** Ensure the `GOOGLE_API_KEY` environment variable is set correctly. |
| 79 | +- **PgVector Not Running:** Verify that the PgVector Docker container is running and accessible on port `5532`. |
| 80 | +--- |
| 81 | + |
| 82 | +## Contributing |
| 83 | +Contributions are welcome! Feel free to open issues or submit pull requests to improve the app. |
| 84 | + |
| 85 | +--- |
0 commit comments