A proof-of-concept Retrieval-Augmented Generation (RAG) playground built with Flask, LangChain, and OpenAI/Tavily. This project demonstrates how to combine PDF retrieval, web search, and conversational agents into a simple chat interface.
AgenticRAG: loads PDFs, applies adaptive chunking, builds a FAISS vector store, and uses a LangChain agent with tool support.- PDF search tool for retrieving relevant document chunks.
- Web search tool powered by Tavily for up-to-date answers when PDFs do not contain enough information.
- Conversation memory for chat history and context.
- Simple Flask frontend with a chat UI at
/. - Additional hybrid retrieval utilities for BM25 and metrics evaluation.
app.py- Flask web app exposing chat, clear memory, and history endpoints.agenticrag.py- Main RAG implementation using LangChain agents and tools.adaptivechunking.py- Adaptive text chunking utility for document splitting.hybridrag.py- Hybrid retrieval support combining FAISS and BM25.ragmetrics.py- Evaluation metrics for RAG retrieval performance.templates/chat.html- Web UI for chat interaction.requirements.txt- Python dependencies.
- Python 3.10+ recommended
pipfor package installation- OpenAI API key
- Tavily API key
- Create a Python virtual environment:
python3 -m venv .venv
source .venv/bin/activate- Install dependencies:
pip install -r requirements.txt-
Add your API keys inside
app.pyor via environment variables. -
Place your PDF documents in the repository root or update the
pdf_fileslist inapp.py.
Start the Flask server:
python app.pyThen open http://127.0.0.1:5000 in your browser to use the chat UI.
- Ask questions in the chat box.
- The agent will search uploaded PDFs first and fallback to web search if needed.
- Use the
/clearendpoint to reset conversation memory. - The
/historyendpoint returns chat history as JSON.
Update the PDF files and keys in app.py:
rag = AgenticRAG(
pdf_files=["./document1.pdf", "./document2.pdf"],
openai_api_key="YOUR_OPENAI_API_KEY",
tavily_api_key="YOUR_TAVILY_API_KEY",
verbose=False,
)Then run the app and ask questions about the uploaded documents.
- The app currently expects PDF files in the root folder.
- This project is designed for experimentation and demonstration, not production deployment.
hybridrag.pyandragmetrics.pyprovide additional retrieval and evaluation tools for advanced RAG experimentation.
This repository does not include a license file. Add one if you intend to open source or share the project.