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

  1. Auth & API Layer (FastAPI + JWT): User registration/login with passlib password hashing and python-jose JWT tokens.
  2. Document Ingestion (pypdf + RecursiveCharacterTextSplitter): Uploaded PDFs are parsed, split into overlapping chunks, and embedded with HuggingFaceEmbeddings (sentence-transformers).
  3. Vector & Chat Storage (ChromaDB + SQLAlchemy): Embeddings live in ChromaDB for semantic retrieval, while user accounts and chat history are persisted in SQLAlchemy.
  4. Fast Inference (Groq via ChatGroq): 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, and rag_service.py modular 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