Skip to content

A curated collection of practical AI projects implementing OCR systems, RAG, AI agents, and other AI use cases.

Update: agentic RAG with o3-mini and DuckDuckGo

Tiioluwanifb12cf338cc1
diff --git a/agentic_rag_with_o-3-mini_and_duckduckgo/.env.example b/agentic_rag_with_o-3-mini_and_duckduckgo/.env.example
new file mode 100644
index 0000000..3cac181
--- /dev/null
+++ b/agentic_rag_with_o-3-mini_and_duckduckgo/.env.example
@@ -0,0 +1 @@
+OPENAI_API_KEY=your_openai_api_key_here
diff --git a/agentic_rag_with_o-3-mini_and_duckduckgo/.gitignore b/agentic_rag_with_o-3-mini_and_duckduckgo/.gitignore
new file mode 100644
index 0000000..a1f796e
--- /dev/null
+++ b/agentic_rag_with_o-3-mini_and_duckduckgo/.gitignore
@@ -0,0 +1,6 @@
+.env
+__pycache__/
+venv/
+.DS_Store
+lancedb_data/
+*.pyc
diff --git a/agentic_rag_with_o-3-mini_and_duckduckgo/README.md b/agentic_rag_with_o-3-mini_and_duckduckgo/README.md
index d4da541..667e540 100644
--- a/agentic_rag_with_o-3-mini_and_duckduckgo/README.md
+++ b/agentic_rag_with_o-3-mini_and_duckduckgo/README.md
@@ -1,73 +1,35 @@
-# PDF RAG Agent using Milvus, Agno, OpenAI & DuckDuckGo
+# Agentic PDF RAG (OpenAI & DuckDuckGo)
-A Streamlit application demonstrating a Retrieval-Augmented Generation (RAG) workflow using OpenAI (`gpt-4o-mini`), Agno, Milvus, and DuckDuckGo for web search.
+A smart document assistant that goes beyond basic search. This agent doesn't just find text—it analyzes your PDFs and proactively searches the web if your documents don't have the answer.
-## Features
+## Principal Functionalities
+- **Agentic Knowledge Retrieval**: The agent is programmed to prioritize your local PDF knowledge base but will automatically pivot to **DuckDuckGo** for real-time web context when needed.
+- **Deep Document Analysis**: Specifically designed to interpret complex PDF structures, providing citations including page numbers and section headers.
+- **Conversational Memory**: Maintains the context of your discussion, allowing for multi-turn questions about specific data points.
+- **Integrated Web Search**: Uses the Agno framework to coordinate between local vector data and live web results for a more comprehensive answer.
-- Upload & process PDF documents.
-- OpenAI embeddings & chat completion (`gpt-4o-mini`).
-- Milvus vector store for semantic search.
-- DuckDuckGo web search fallback.
-- Interactive Streamlit chat interface.
+## Technical Context
+- **Models**: OpenAI `o3-mini` (Reasoning) and OpenAI Embeddings.
+- **Vector Engine**: **LanceDB** (Serverless/Local). This project uses a local-first database that runs entirely in memory or on disk without requiring an external server setup.
+- **Backend**: Agno (formerly Phidata) for agent orchestration.
-## Prerequisites
+## Setup & Execution
-- Python 3.8+
-- OpenAI API Key
-- Docker (for Milvus)
-- Running Milvus Instance
+### 1. Requirements
+This project shares the root repository's `requirements.txt` and virtual environment. Ensure you have run:
+```bash
+pip install -r requirements.txt
+```
-## Setup
+### 2. Environment
+The application loads your `OPENAI_API_KEY` directly from the root `.env` file for a "plug-and-play" experience.
-1. **Clone Repository & Navigate:**
- ```bash
- git clone https://github.com/Sumanth077/awesome-ai-apps-and-agents.git
+### 3. Launch
+```bash
+streamlit run app.py
+```
- cd awesome-ai-apps-and-agents/agentic_rag_with_o-3-mini_and_duckduckgo
- ```
-
-2. **Environment & Dependencies:**
- ```bash
- python3 -m venv venv
-
- source venv/bin/activate # or venv\Scripts\activate on Windows
-
- pip install -r requirements.txt
- ```
- Ensure ollama is installed, with which you would need to download the corresponding model
- `ollama pull qwen3:1.7b`
-
-3. **OpenAI API Key:**
- Set the `OPENAI_API_KEY` environment variable or add it to your Streamlit secrets (`.streamlit/secrets.toml`).
-
-4. **Start Milvus:**
- Follow the official Milvus guide to start a standalone instance using Docker:
- [https://milvus.io/docs/install_standalone-docker.md](https://milvus.io/docs/install_standalone-docker.md)
- *Ensure it's accessible (usually `http://localhost:19530`).*
-
-## Usage
-
-1. **Ensure Milvus is running.**
-2. **Run the app:**
- ```bash
- streamlit run app.py
- ```
-3. Open the provided URL (e.g., `http://localhost:8501`).
-4. Upload a PDF, click "Process Document", and start chatting!
-
-## How it Works
-
-- PDF text is chunked and embedded using OpenAI.
-- Embeddings stored in Milvus.
-- User query triggers the Agno Agent:
- - Searches Milvus knowledge base first.
- - Uses DuckDuckGo if knowledge base results are insufficient.
- - `gpt-4o-mini` synthesizes information to generate the final response.
-
-## Contributing
-
-Contributions, issues, and feature requests are welcome. Please feel free to submit a Pull Request or open an issue.
-
-## License
-
-This project is licensed under the MIT License. See the LICENSE file for details (if one exists).
\ No newline at end of file
+## How to Use
+1. **Upload**: Drag and drop any PDF into the sidebar.
+2. **Profile**: Click "Process Document" to build the local search index.
+3. **Query**: Ask any question. Watch the sidebar to see the agent "thinking" and choosing whether to use the PDF or the web for its answer.
\ No newline at end of file
diff --git a/agentic_rag_with_o-3-mini_and_duckduckgo/app.py b/agentic_rag_with_o-3-mini_and_duckduckgo/app.py
index 5bc7d4b..2bfa492 100644
--- a/agentic_rag_with_o-3-mini_and_duckduckgo/app.py
+++ b/agentic_rag_with_o-3-mini_and_duckduckgo/app.py
@@ -5,10 +5,10 @@ from agno.embedder.openai import OpenAIEmbedder
# Removed Ollama imports
from agno.agent import Agent
from agno.knowledge.pdf import PDFKnowledgeBase
-from agno.vectordb.milvus import Milvus
+from agno.vectordb.lancedb import LanceDb
from agno.tools.duckduckgo import DuckDuckGoTools
import os
-from dotenv import load_dotenv
+from dotenv import load_dotenv, find_dotenv
from typing import Optional
import time
import base64
@@ -58,7 +58,7 @@ def apply_custom_css():
apply_custom_css()
# Load environment variables
-load_dotenv()
+load_dotenv(find_dotenv())
# Initialize session state
if "messages" not in st.session_state:
@@ -73,7 +73,7 @@ if "knowledge_base" not in st.session_state:
# Define the agent creation function using OpenAI with updated instructions
def get_rag_agent(
knowledge_base: PDFKnowledgeBase,
- model_id: str = "gpt-4o-mini",
+ model_id: str = "o3-mini",
debug_mode: bool = True,
) -> Agent:
"""Creates and configures an Agentic RAG Agent for PDF interaction using OpenAI."""
@@ -133,12 +133,12 @@ if not OPENAI_API_KEY:
st.error("OpenAI API Key not found. Please set the OPENAI_API_KEY environment variable or add it to Streamlit secrets.")
st.stop()
-# Configure Milvus with OpenAI Embedder
-MILVUS_URI = os.getenv("MILVUS_URI", "http://localhost:19530")
+# Configure LanceDb with OpenAI Embedder
+LANCE_DB_URI = "lancedb_data"
COLLECTION_NAME = "rag_documents_openai"
-vector_db = Milvus(
- collection=COLLECTION_NAME,
- uri=MILVUS_URI,
+vector_db = LanceDb(
+ table_name=COLLECTION_NAME,
+ uri=LANCE_DB_URI,
embedder=OpenAIEmbedder()
)
@@ -157,8 +157,16 @@ st.markdown("# PDF RAG Agent with Milvus and Agno 📄")
# Sidebar for document upload
with st.sidebar:
- st.markdown("## Add your documents!")
- uploaded_file = st.file_uploader("Choose your .pdf file", type=['pdf'], key="pdf_uploader")
+ st.header("📄 Upload Document")
+ uploaded_file = st.file_uploader("Choose a PDF file", type="pdf", key="pdf_uploader")
+
+ st.divider()
+ if st.button("🗑️ Clear Local Database"):
+ if os.path.exists("lancedb_data"):
+ import shutil
+ shutil.rmtree("lancedb_data")
+ st.success("Local database cleared. Please refresh the page.")
+ st.rerun()
if uploaded_file is not None:
temp_pdf_path = "temp_uploaded.pdf"
diff --git a/agentic_rag_with_o-3-mini_and_duckduckgo/requirements.txt b/agentic_rag_with_o-3-mini_and_duckduckgo/requirements.txt
index 43f92fc..64e8bd0 100644
--- a/agentic_rag_with_o-3-mini_and_duckduckgo/requirements.txt
+++ b/agentic_rag_with_o-3-mini_and_duckduckgo/requirements.txt
@@ -1,7 +1,7 @@
+agno==1.5.10
+openai==1.83.0
+lancedb
+streamlit
duckduckgo-search
-google-genai
-pymilvus
-agno>=1.4.2
-streamlit>=1.44.1
-pypdf>=5.4.0
-pydantic>=2.8.2
\ No newline at end of file
+python-dotenv
+pypdf
\ No newline at end of file