🏗️ Architecture — How RAG Works
INGEST (one-time setup):
documents/ → loader.py → chunker.py → embedder.py → chroma_db/
PDFs/TXT Load text Split into Convert to Vector DB
+ metadata ~500 char 768-dim (persistent)
chunks w/ vectors via overlap Ollama
ASK (per question):
Question → embedder.py → retriever.py → generator.py → Answer + Citations
"What is Convert question Search Chroma Send context + "Revenue is
revenue?" to vector for top 5 question to Rs 45 lakhs
(same model) similar chunks GLM-5.2 LLM (Source: report)"
🧠 Key Concepts for Students
Why chunking? A 50-page PDF as one vector = a "blur" — close to everything, specific to nothing. Breaking into ~500 char chunks makes search precise. Each chunk covers one topic, so "revenue" chunks are separate from "hiring" chunks.
Why overlap? If you cut at exactly 500 chars, you might split a sentence: "...revenue is based on" | "subscription fees...". The answer is at the boundary. Overlap (50 chars) ensures boundary info survives in both chunks.
Why embeddings? Computers can't "search" text. Embeddings convert text to numbers where similar MEANING = similar numbers. "Revenue" and "money" have similar vectors even though they're different words. This is semantic search.
Why "answer only from context"? Without this instruction, the LLM mixes its training data with your documents and hallucinates. The system prompt forces it to answer from retrieved chunks only — and cite sources. This is what makes RAG reliable.
Why same embedding model for questions and docs? If documents use model A and questions use model B, the vectors live in different "spaces" — similarity search is meaningless. Same model = same space = meaningful search.
🚀 Quick Start
git clone https://github.com/nagarjunak-pixel/rag-chat-docs.git
cd rag-chat-docs
python3 -m venv venv
source venv/bin/activate
pip install chromadb pymupdf requests fastapi
ollama pull nomic-embed-text
ollama serve
cd app
python main.py ingest
python main.py ask "What is the revenue model?"
python web_app.py