Skip to content

Commit 1ebbfb9

Browse files
committed
add agentic rag
1 parent 2225c77 commit 1ebbfb9

File tree

13 files changed

+652
-0
lines changed

13 files changed

+652
-0
lines changed

agentic_rag/.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
*.py[cod]
2+
__pycache__/
3+
*.db
4+
.web
5+
assets/external/

agentic_rag/LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2023 Pynecone, Inc.
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

agentic_rag/README.md

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

agentic_rag/chat/__init__.py

Whitespace-only changes.

agentic_rag/chat/chat.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import reflex as rx
2+
from chat.components.chat import State, chat, action_bar, sidebar
3+
4+
def index() -> rx.Component:
5+
"""The main app."""
6+
return rx.box(
7+
sidebar(),
8+
rx.box(
9+
rx.vstack(
10+
rx.hstack(
11+
rx.heading("Agentic RAG 🔥"),
12+
rx.button(
13+
"New Chat",
14+
on_click=State.create_new_chat,
15+
margin_left="auto",
16+
),
17+
),
18+
chat(),
19+
action_bar(),
20+
spacing="4",
21+
align_items="center",
22+
height="100vh",
23+
padding="4em",
24+
),
25+
margin_left="300px",
26+
width="calc(100% - 300px)",
27+
),
28+
width="100%",
29+
height="100vh",
30+
background_color=rx.color("mauve", 1),
31+
)
32+
33+
34+
app = rx.App()
35+
app.add_page(index)

0 commit comments

Comments
 (0)