Retrieval‑Augmented Generation (RAG) chatbot that lets you chat with your own PDFs and text files.
Documents are ingested, chunked, embedded, indexed with FAISS, and queried via a FastAPI backend with a Streamlit chat UI on top.
-
Domain‑agnostic RAG
Ingests any PDFs/TXT fromdata/pdf_files/anddata/text_files/and answers questions over that corpus. -
Modular RAG pipeline
- Document ingestion with LangChain loaders (PDF + text).
- Recursive character chunking.
- SentenceTransformers embeddings.
- FAISS inner‑product index for similarity search.
- Custom
RAGRetrieverabstraction and LLM wrapper.
-
Full‑stack app
- FastAPI backend exposing:
POST /query– ask a question, get an answer + supporting contexts.POST /upload_docs– upload new PDFs/TXT and rebuild the index.GET /stats– see corpus statistics (docs, chunks, sources).
- Streamlit frontend:
- Chat‑style interface (
st.chat_message) for conversational queries. - Sidebar with corpus overview and document upload.
- Chat‑style interface (
- FastAPI backend exposing:
-
LLM integration (Groq)
- Uses Groq’s
llama-3.1-8b-instantvia LangChain’sChatGroqfor fast, instruction‑following responses grounded in retrieved context.
- Uses Groq’s
-
Evaluation
- Offline evaluation script computing precision@5 (and recall variants) on a small labeled question set to verify retrieval quality.
-
Designed for resumes & real projects
- Clean, modular structure:
rag_files/(engine),api/(service),ui/(UI). - Easy to adapt to any domain: research papers, course notes, internal docs, etc.
- Clean, modular structure:
┌────────────────────┐
│ Documents │
│ (PDF, TXT, …) │
└────────┬───────────┘
│
▼
┌──────────────────────┐
│ Data Ingestion │
│ (LangChain loaders) │
└────────┬─────────────┘
│
▼
┌──────────────────────┐
│ Chunking │
│ Recursive splitter │
└────────┬─────────────┘
│
▼
┌──────────────────────┐
│ Embeddings │
│ SentenceTransformers │
└────────┬─────────────┘
│
▼
┌──────────────────────┐
│ Vector Store │
│ FAISS (IP index) │
└────────┬─────────────┘
│
▼
┌──────────────────────┐ ┌──────────────────────┐
│ RAG Retriever │ │ LLM (Groq) │
│ top‑k relevant │ ─────▶ │ ChatGroq, prompt │
└────────┬─────────────┘ └────────┬─────────────┘
│ │
└─────────────┬────────────────────┘
▼
Final Answer (FastAPI → Streamlit UI)
Back‑end: rag_files/ + api/
Front‑end: ui/streamlit_app.py
RAG_Chatbot/
├── api/
│ ├── __init__.py
│ └── main.py # FastAPI app: /query, /upload_docs, /stats
├── ui/
│ └── streamlit_app.py # Streamlit chat UI + uploads + corpus overview
├── rag_files/
│ ├── __init__.py
│ ├── data_ingestion.py # PDF/TXT loaders
│ ├── chunking.py # RecursiveCharacterTextSplitter
│ ├── embeddings.py # EmbeddingManager (SentenceTransformers)
│ ├── vector_store.py # VectorStore (FAISS IP index, docs)
│ ├── retriever.py # RAGRetriever
│ ├── llm.py # ChatGroq wrapper + prompt
│ ├── pipeline.py # RAGPipeline + get_pipeline + answer_question
│ └── eval.py # precision@k (and recall) evaluation
├── data/
│ ├── pdf_files/ # user PDFs (gitignored or small samples)
│ └── text_files/ # user TXT files
├── .env.example # example env file (no secrets)
├── requirements.txt
├── .gitignore
└── README.md
---
## ⚙️ Setup & Installation
### 1. Clone the repository
```bash
git clone https://github.com/ritikaugale/RAG_Chatbot.git
cd RAG_Chatbot
python -m venv venv
source venv/bin/activate # Windows: venv\Scripts\activatepip install -r requirements.txt# Set your Groq key
cp .env.example .env
# Edit .env and set:
GROQ_API_KEY=your_api_key_heremkdir -p data/pdf_files data/text_filesRun the backend and frontend in separate terminals (same virtual environment).
uvicorn api.main:app --reloadstreamlit run ui/streamlit_app.pyIn the Streamlit sidebar, Corpus Overview shows:
- Number of documents
- Number of chunks
- List of source paths (PDF/TXT filenames)
- Use “Upload PDFs or TXT” in the sidebar
- Select one or more
.pdf/.txtfiles - Click “Save uploaded files”
The backend will:
- Save them into
data/pdf_files/data/text_files - Rebuild the FAISS index on the next query
Type a question in the chat input
Example:
What is the SSD algorithm used for?
The app will:
- Embed your query
- Retrieve top-k relevant chunks via FAISS
- Send context + question to the Groq LLM
- Stream the answer back to the chat UI
Enable “Show retrieved contexts” to inspect the exact chunks used for answer generation.
Adjust the Top-K contexts slider in the sidebar (e.g., from 3 to 8).
- Higher
k→ better recall - Higher
k→ more noise + longer responses
Create a qrels.json file as shown in the example.
python -m rag_files.evalMIT License