How aunraza19/rag-pipline-chatbot works
Project Type and Purpose
• This is a specialized full-stack RAG (Retrieval-Augmented Generation) chatbot designed to answer university academic policy questions. It consists of two major workflows:
a. Data Ingestion Pipeline (batch job) to process and index the PDF manual.
b. Query-Response Service (interactive Streamlit UI) to serve students in real time.
High-Level Components
A. Source Document
• academic_manual.pdf (the raw policy PDF)
B. Ingestion Pipeline
• ingest.py:
• Uses PyPDFLoader to parse the PDF into text chunks
• Generates embeddings via BAAI/bge-small-en-v1.5 (HuggingFaceEmbeddings)
• Persists embeddings and metadatas in ChromaDB (./chroma_db)
C. Configuration
• config.py + .env: centralize API keys (GROQ_API_KEY, optional HUGGINGFACEHUB_API_TOKEN) and constants
D. Utility Layer
• utils.py: wraps calls to embedding model, vector store client, and LLM client (Groq API via LangChain)
E. Frontend & Orchestration
• app.py (Streamlit):
• Takes user query
• Uses utils to convert query → embedding → vector search → retrieve top-k chunks
• Feeds context + query to Groq LLM → obtains generated answer
• Renders chat interface with answer and source attributions
F. External Services & Dependencies
• Groq LLM API (llama-3.1-8b-instant) for answer generation
• HuggingFaceEmbeddings for vector encoding (if token required)
• LangChain library to orchestrate retrieval and generation
• Streamlit runtime for UI
Interactions & Data Flow
1. One-Time Ingestion
academic_manual.pdf → ingest.py → text chunks → embeddings (HuggingFace) → ChromaDB
2. Query Flow (per user request)
Streamlit UI (app.py)
↓ user question
utils.py embedding call → embedding vector
↓
ChromaDB vector search → top-N relevant chunks
↓
utils.py LLM call via LangChain → Groq API (context + prompt)
↓
LLM returns answer → Streamlit displays answer with source snippets
Architectural Patterns & Principles
• Modular Separation: clear divide between ingestion (offline batch) and serving (online interactive)
• Single Responsibility: each script has one focused role (ingest, config, utils, UI)
• Externalized Configuration: secrets/config in .env + config.py
• Layered Design:
• Data Layer (PDF, ChromaDB)
• Logic Layer (utils + LangChain orchestrator)
• Presentation Layer (Streamlit)