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 Qwen and Firecrawl

Tiioluwani83604e9d5c74
diff --git a/agentic_rag_with_qwen_and_firecrawl/.env.example b/agentic_rag_with_qwen_and_firecrawl/.env.example
new file mode 100644
index 0000000..d167fe9
--- /dev/null
+++ b/agentic_rag_with_qwen_and_firecrawl/.env.example
@@ -0,0 +1,2 @@
+OPENAI_API_KEY=your_openai_api_key_here
+FIRECRAWL_API_KEY=your_firecrawl_api_key_here
diff --git a/agentic_rag_with_qwen_and_firecrawl/.gitignore b/agentic_rag_with_qwen_and_firecrawl/.gitignore
new file mode 100644
index 0000000..a1f796e
--- /dev/null
+++ b/agentic_rag_with_qwen_and_firecrawl/.gitignore
@@ -0,0 +1,6 @@
+.env
+__pycache__/
+venv/
+.DS_Store
+lancedb_data/
+*.pyc
diff --git a/agentic_rag_with_qwen_and_firecrawl/README.md b/agentic_rag_with_qwen_and_firecrawl/README.md
index 6d1044f..e1ac783 100644
--- a/agentic_rag_with_qwen_and_firecrawl/README.md
+++ b/agentic_rag_with_qwen_and_firecrawl/README.md
@@ -1,72 +1,35 @@
-# PDF RAG Agent with Milvus, Agno, Qwen and FireCrawl
+# Web-Aware Agentic RAG (OpenAI & Firecrawl)
-A Streamlit application demonstrating a Retrieval-Augmented Generation (RAG) workflow using Qwen3:8b, Agno, Milvus, and FireCrawl for crawling through relevant websites.
+A research-heavy RAG agent designed to bridge the gap between static documents and the live web. It uses professional-grade web crawling to supplement your PDF data.
-## Features
+## Principal Functionalities
+- **Advanced Web Crawling**: Integrated with **Firecrawl**, this agent can perform deep-web searches and scrapes to provide context that your uploaded PDFs might be missing.
+- **Intelligent Fallback**: The agent prioritizes your document but is "self-aware"—if it detects an information gap, it will autonomously trigger a web crawl to find the missing facts.
+- **Concise Research Reporting**: Optimized for speed and clarity, providing direct answers with clear source attribution.
+- **Dynamic Indexing**: Real-time processing of PDFs into a local vector database for immediate querying.
-- Upload PDFs & process PDF documents.
-- Generate BGE embeddings (`bge-small-en-v1.5`).
-- Uses Qwen model (via Ollama) for LLM responses.
-- Milvus vector store for semantic search.
-- Firecrawl API integration for structured and up-to-date web search.
-- Interactive Streamlit chat interface.
+## Technical Context
+- **Models**: OpenAI `gpt-4o-mini` for stable reasoning and high-speed response.
+- **Web Engine**: **Firecrawl** (for high-fidelity web scraping).
+- **Vector Engine**: **LanceDB** (Serverless/Local). Runs entirely within the project without background services.
-## Prerequisites
+## Setup & Execution
-- Python 3.8+
-- FireCrawl API Key
-- Docker (for Milvus)
-- Running Milvus Instance
+### 1. Requirements
+This project utilizes the shared repository environment. Ensure you have installed the root dependencies:
+```bash
+pip install -r requirements.txt
+```
-## Setup
+### 2. Environment
+The tool automatically pulls `OPENAI_API_KEY` and `FIRECRAWL_API_KEY` from the root `.env` file.
-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_qwen_and_firecrawl
- ```
-
-2. **Environment & Dependencies:**
- ```bash
- python3 -m venv venv
-
- source venv/bin/activate # Or venv\Scripts\activate on Windows
-
- pip install -r requirements.txt
- ```
-
-3. **FireCrawl API Key:**
- Set the `FIRECRAWL_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 `bge-small-en-v1.5` from SentenceTransformers.
-- Embeddings are stored in Milvus for semantic retrieval.
-- User query triggers the Agno Agent:
- - Searches Milvus vector store for relevant context.
- - Falls back to Firecrawl for live web results if context is weak or missing.
- - Uses the locally hosted Qwen model via Ollama to synthesize a 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**: Use the sidebar to load your technical document or research paper.
+2. **Index**: The system will automatically build a searchable index using LanceDB.
+3. **Analyze**: Ask questions that require both document knowledge and current event context. The agent will show you when it decides to "crawl the web" to find a more complete answer.
\ No newline at end of file
diff --git a/agentic_rag_with_qwen_and_firecrawl/app.py b/agentic_rag_with_qwen_and_firecrawl/app.py
index c45ca78..908a01f 100644
--- a/agentic_rag_with_qwen_and_firecrawl/app.py
+++ b/agentic_rag_with_qwen_and_firecrawl/app.py
@@ -1,68 +1,43 @@
import streamlit as st
-from agno.models.ollama import Ollama
+from agno.models.openai import OpenAIChat
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.embedder.openai import OpenAIEmbedder
from agno.tools.firecrawl import FirecrawlTools
import os
-from dotenv import load_dotenv
+from dotenv import load_dotenv, find_dotenv
import base64
-from sentence_transformers import SentenceTransformer
+import torch
import concurrent.futures
import time
from datetime import datetime
from queue import Queue
-
-import torch
+# Disable torch classes path to avoid some common streamlit/torch conflicts
torch.classes.__path__ = []
-# --- Caching for performance ---
[email protected]_resource(show_spinner=False)
-def get_embedding_model():
- return SentenceTransformer("BAAI/bge-small-en-v1.5")
-# @st.cache_resource(show_spinner=False)
-# def get_embedding_model():
-# return SentenceTransformer("BAAI/bge-small-en-v1.5")
+# Using GeminiEmbedder instead of local SentenceTransformer
-# Custom Embedder using cached model
-class CustomEmbedder:
- def __init__(self):
- self.model = get_embedding_model()
- self.dimensions = 384 # Required by agno Milvus wrapper
-
- def get_embedding(self, text: str) -> list[float]:
- return self.model.encode([text])[0].tolist()
-
- def embed(self, texts: list[str]) -> list[list[float]]:
- return self.model.encode(texts, show_progress_bar=False).tolist()
-
- def get_embedding_and_usage(self, texts: list[str]):
- embeddings = self.embed(texts)
- usage = {
- "input_tokens": sum(len(t.split()) for t in texts),
- "output_vectors": len(embeddings),
- }
- return embeddings, usage
-
-load_dotenv()
+load_dotenv(find_dotenv())
firecrawl_api_key = os.getenv("FIRECRAWL_API_KEY")
-# Milvus Vector DB
-MILVUS_URI = os.getenv("MILVUS_URI", "http://localhost:19530")
+# LanceDb Vector DB
+LANCE_DB_URI = "lancedb_data_qwen"
COLLECTION_NAME = "rag_documents_local"
-# Configure Milvus with the custom embedder
-vector_db = Milvus(
- collection=COLLECTION_NAME,
- uri=MILVUS_URI,
- embedder=CustomEmbedder()
+# Configure LanceDb with the custom embedder
+# Configure LanceDb with OpenAIEmbedder
+vector_db = LanceDb(
+ table_name=COLLECTION_NAME,
+ uri=LANCE_DB_URI,
+ embedder=OpenAIEmbedder()
)
-def get_rag_agent(knowledge_base: PDFKnowledgeBase, model_id="qwen3:1.7b", debug_mode=True):
- model = Ollama(id=model_id)
+def get_rag_agent(knowledge_base: PDFKnowledgeBase, model_id="gpt-4o-mini", debug_mode=True):
+ model = OpenAIChat(id=model_id)
instructions = [
"You are concise, quick and to the point. Don't display your thinking process.",
"Do not show your reasoning, thoughts, or internal process to the user.",
@@ -226,9 +201,20 @@ for key in ["messages", "document_loaded", "agent", "knowledge_base", "processin
else:
st.session_state[key] = None
-# --- Sidebar: Upload PDF ---
+# ---# Sidebar: App Settings and Upload
with st.sidebar:
- with st.expander("Upload and Process PDF", expanded=True):
+ st.title("Settings")
+
+ st.divider()
+ if st.button("🗑️ Clear Local Database"):
+ if os.path.exists("lancedb_data_qwen"):
+ import shutil
+ shutil.rmtree("lancedb_data_qwen")
+ st.success("Local database cleared. Please refresh the page.")
+ st.rerun()
+
+ st.header("Upload Document")
+ with st.expander("d Process PDF", expanded=True):
if st.session_state.processing:
progress_container = st.empty()
progress_bar = progress_container.progress(0)
@@ -310,10 +296,11 @@ else:
try:
full_response = ""
for chunk in st.session_state.agent.run(prompt):
- if hasattr(chunk, 'content'):
- full_response += chunk.content
+ if hasattr(chunk, 'content') and chunk.content is not None:
+ full_response += str(chunk.content)
msg_box.markdown(f'<div class="assistant-bubble"><div class="message-content">{full_response}</div></div>', unsafe_allow_html=True)
- else:
+ elif chunk is not None and not hasattr(chunk, 'content'):
+ # Fallback if chunk itself is a string or other type
full_response += str(chunk)
msg_box.markdown(f'<div class="assistant-bubble"><div class="message-content">{full_response}</div></div>', unsafe_allow_html=True)
content = full_response
diff --git a/agentic_rag_with_qwen_and_firecrawl/requirements.txt b/agentic_rag_with_qwen_and_firecrawl/requirements.txt
index 71b00ba..48d6b4f 100644
--- a/agentic_rag_with_qwen_and_firecrawl/requirements.txt
+++ b/agentic_rag_with_qwen_and_firecrawl/requirements.txt
@@ -1,94 +1,7 @@
agno==1.5.10
-aiohappyeyeballs==2.6.1
-aiohttp==3.12.12
-aiosignal==1.3.2
-altair==5.5.0
-annotated-types==0.7.0
-anyio==4.9.0
-async-timeout==5.0.1
-attrs==25.3.0
-blinker==1.9.0
-cachetools==5.5.2
-certifi==2025.4.26
-charset-normalizer==3.4.2
-click==8.2.1
-colorama==0.4.6
-docstring_parser==0.16
-exceptiongroup==1.3.0
-filelock==3.18.0
-firecrawl-py==2.8.0
-frozenlist==1.7.0
-fsspec==2025.5.1
-gitdb==4.0.12
-GitPython==3.1.44
-grpcio==1.67.1
-h11==0.16.0
-httpcore==1.0.9
-httpx==0.28.1
-huggingface-hub==0.32.4
-idna==3.10
-Jinja2==3.1.6
-joblib==1.5.1
-jsonschema==4.24.0
-jsonschema-specifications==2025.4.1
-markdown-it-py==3.0.0
-MarkupSafe==3.0.2
-mdurl==0.1.2
-mpmath==1.3.0
-multidict==6.4.4
-narwhals==1.42.0
-nest-asyncio==1.6.0
-networkx==3.4.2
-numpy==2.2.6
-ollama==0.5.1
-packaging==24.2
-pandas==2.3.0
-pillow==11.2.1
-propcache==0.3.2
-protobuf==6.31.1
-pyarrow==20.0.0
-pydantic==2.11.5
-pydantic-settings==2.9.1
-pydantic_core==2.33.2
-pydeck==0.9.1
-Pygments==2.19.1
-pymilvus==2.5.11
-pypdf==5.6.0
-python-dateutil==2.9.0.post0
-python-dotenv==1.1.0
-python-multipart==0.0.20
-pytz==2025.2
-PyYAML==6.0.2
-referencing==0.36.2
-regex==2024.11.6
-requests==2.32.4
-rich==14.0.0
-rpds-py==0.25.1
-safetensors==0.5.3
-scikit-learn==1.7.0
-scipy==1.15.3
-sentence-transformers==4.1.0
-shellingham==1.5.4
-six==1.17.0
-smmap==5.0.2
-sniffio==1.3.1
-streamlit==1.45.1
-sympy==1.14.0
-tenacity==9.1.2
-threadpoolctl==3.6.0
-tokenizers==0.21.1
-toml==0.10.2
-tomli==2.2.1
-torch==2.7.1
-tornado==6.5.1
-tqdm==4.67.1
-transformers==4.52.4
-typer==0.16.0
-typing-inspection==0.4.1
-typing_extensions==4.14.0
-tzdata==2025.2
-ujson==5.10.0
-urllib3==2.4.0
-watchdog==6.0.0
-websockets==15.0.1
-yarl==1.20.1
+openai==1.83.0
+lancedb
+firecrawl-py
+streamlit
+python-dotenv
+pypdf