This project demonstrates an agentic Retrieval-Augmented Generation (RAG) application built using CrewAI and Streamlit. It allows users to upload a PDF document and then ask questions about its content, leveraging the power of Large Language Models (LLMs) and intelligent agents.
- PDF Document Upload: Users can upload PDF files directly through the Streamlit interface.
- PDF Indexing: The application indexes the uploaded PDF, making its content searchable.
- Agentic RAG: Employs a CrewAI-powered crew of agents to handle information retrieval and response generation.
- Web Search Fallback: If information is not found in the PDF, the system intelligently falls back to web search using the Serper API.
- Conversational Interface: Provides a user-friendly chat interface for interacting with the system.
- Clear Chat History: Users can easily clear the chat history and start fresh.
- Real-time Response: The application displays the LLM's response in a streaming fashion, providing a more engaging user experience.
- Local LLM Support: Uses Ollama to run a local LLM (deepseek-r1:14b)
The application uses a crew of two agents:
- Retriever Agent:
- Responsible for retrieving relevant information based on the user's query.
- Prioritizes searching the uploaded PDF.
- Falls back to web search if the PDF doesn't contain the answer.
- Uses
PDFSearchTool
andSerperDevTool
.
- Response Agent:
- Synthesizes the retrieved information into a clear and concise response.
- Handles cases where no relevant information is found.
These agents work together sequentially to provide accurate and helpful answers to user queries.
- CrewAI: A framework for orchestrating multi-agent systems.
- Streamlit: A Python library for creating interactive web applications.
- Ollama: For running the local LLM.
- Deepseek-r1:14b: The specific LLM used in this project.
- Serper API: For web search capabilities.
- PDFSearchTool: A custom tool for searching PDF documents.
- Python: The primary programming language.
- dotenv: For managing environment variables.
- Python 3.8+
- Ollama: You need to have Ollama installed and running locally.
- Serper API Key: You'll need a Serper API key for web search functionality.
- Required Python Packages:
pip install streamlit crewai crewai-tools python-dotenv
- Clone the Repository:
git clone <your-repository-url> cd <your-repository-directory>
- Install Dependencies:
(You can create a
pip install -r requirements.txt
requirements.txt
file with the following content:)streamlit crewai crewai-tools python-dotenv
- Set Environment Variables:
- Create a
.env
file in the project's root directory. - Add your Serper API key:
SERPER_API_KEY=your_serper_api_key_here
- Create a
- Run Ollama:
- Make sure you have Ollama installed and running.
- Pull the deepseek-r1:14b model:
ollama pull deepseek-r1:14b
- Run the Streamlit App:
streamlit run rag_app.py
- Upload a PDF: In the sidebar, use the file uploader to select and upload a PDF document.
- Wait for Indexing: The application will index the PDF. This may take a few moments.
- Ask Questions: In the chat interface, type your questions about the PDF content.
- View Responses: The system will provide answers based on the PDF content or, if necessary, from the web.
- Clear Chat: Use the "Clear Chat" button in the sidebar to reset the conversation.