A clean backend architecture for multi-PDF Q&A with JWT auth, persistent chat history, and fast inference.
Why Build This?
Most RAG tutorials stop at a single-file script. For AI-RAG-Chatbot (GitHub), I wanted a modular backend with real authentication, document management, and fast LLM responses.
Architecture
- Auth & API Layer (
FastAPI+JWT): User registration/login withpasslibpassword hashing andpython-joseJWT tokens. - Document Ingestion (
pypdf+RecursiveCharacterTextSplitter): Uploaded PDFs are parsed, split into overlapping chunks, and embedded withHuggingFaceEmbeddings(sentence-transformers). - Vector & Chat Storage (
ChromaDB+SQLAlchemy): Embeddings live in ChromaDB for semantic retrieval, while user accounts and chat history are persisted in SQLAlchemy. - Fast Inference (
GroqviaChatGroq): Retrieved context is passed to Groq's LLM API for low-latency, grounded answers.
What I Learned
- Separate auth/persistence from RAG logic: Keeping
auth_service.py,pdf_service.py, andrag_service.pymodular makes testing and swapping vector stores or LLM providers trivial. - Chunking matters more than prompt tweaking: Tuning chunk size and overlap had a bigger impact on answer quality than changing the system prompt.
Check out the full code: AdarshVerma21/AI-RAG-Chatbot
