How reni-renisha/study_guide works
1. This repo is a small, self-contained local RAG application. The architecture is centered on a single Python backend (main.py) and a single-page frontend (index.html), with no separate services besides local Ollama and the local vector store.
2. The user-facing boundary is the browser UI. The HTML/vanilla JS page lets a user upload PDFs, view indexed documents, delete documents, and submit questions. It talks only to the FastAPI backend over HTTP.
3. The backend boundary is main.py, which exposes the API described in the README:
- POST /upload for PDF ingestion
- GET /documents for listing indexed files
- DELETE /documents/{doc_id} for removal
- POST /ask for retrieval-augmented Q&A
4. Document ingestion flow: uploaded PDFs are parsed locally with PyMuPDF. The backend extracts text from each PDF page, associates content with filename/page metadata, and prepares it for indexing. This is the first major processing pipeline.
5. Indexing and persistence are handled by ChromaDB running locally in persistent mode. Parsed text is converted into embeddings using sentence-transformers with the MiniLM-L6-v2 model, then stored in the vector index along with document/page metadata so later answers can cite sources.
6. Query flow: when a user asks a question, the backend embeds the query with the same sentence-transformers model, performs cosine-similarity retrieval against ChromaDB, and selects the most relevant chunks/pages. This retrieval layer is the key bridge between the documents and the generated answer.
7. Answer generation is delegated to a local LLM through Ollama. The README specifies mistral running locally, so the backend sends the retrieved context plus the question to Ollama, then formats the result into a grounded response.
8. Grounding is an explicit architectural constraint. The assistant is designed to answer strictly from retrieved document content and to return “Answer not found in documents.” when the retrieved context is insufficient. That means the retrieval step is not optional; it is the gatekeeper for response generation.
9. Source attribution is part of the API contract and response shape. Answers include filename, page number, similarity score, and a snippet, which means the retrieval layer must preserve page-level provenance all the way through to the frontend.
10. Document management is a second data lifecycle path besides Q&A. The /documents and /documents/{doc_id} endpoints imply there is document identity and cleanup logic in the backend so users can inspect and remove indexed content without rebuilding the entire store.
11. Deployment/runtime is intentionally local-first:
- Python backend via FastAPI and Uvicorn
- local embedding model from sentence-transformers
- local vector persistence via ChromaDB
- local generation via Ollama
This keeps the full system offline and avoids external cloud dependencies.
12. At the diagram level, the main flows to show are:
- Browser UI → FastAPI API
- Upload PDF → parse/extract text → embed → store in ChromaDB
- Ask question → embed query → retrieve relevant chunks → send to Ollama → return grounded answer with citations
- List/delete document → backend metadata/store update
Main entry points: main.py FastAPI API · index.html Browser
Components 13
Browser UI
Single-page upload, document, and Q&A interface
- Browser · User-facing interface in the browser
index.html - Upload PDFs · PDF upload action and document submission
index.html - Documents View · Lists indexed files and supports deletion
index.html - Ask Question · Question entry and answer display
index.html
FastAPI Backend
Main application and data flow orchestration
- FastAPI API · Backend HTTP boundary for upload, document management, and Q&A
main.py - Ingest Pipeline · Parses uploaded PDFs and prepares page-level text for indexing
main.py - Doc Metadata · Tracks document identity, filename, page provenance, and cleanup state
main.py - Retrieval Layer · Embeds queries and selects relevant document chunks from the vector store
main.py - Answer Formatter · Packages grounded answers with citations and fallback messaging
main.py
Local Services
Embedded model, vector store, and local generation runtime
- PyMuPDF · Local PDF text extraction from uploaded pages
- MiniLM Embedder · Sentence-transformers MiniLM-L6-v2 embeddings for documents and queries
- ChromaDB · Persistent local vector index with similarity search and stored metadata
- Ollama LLM · Local mistral-backed generation using retrieved context
Connections 18
- Browser → FastAPI API: HTTP requests · Browser actions call the backend API
- Upload PDFs → FastAPI API: POST /upload · Send uploaded PDFs to the backend
- Documents View → FastAPI API: GET/DELETE docs · Load and remove indexed documents
- Ask Question → FastAPI API: POST /ask · Submit a question for grounded answering
- FastAPI API → Ingest Pipeline: upload flow · Route PDF uploads into the ingestion pipeline
- Ingest Pipeline → PyMuPDF: extract text · Parse PDF pages locally into text
- Ingest Pipeline → MiniLM Embedder: embed pages · Convert page text into vector embeddings
- MiniLM Embedder → ChromaDB: store vectors · Persist embeddings and page metadata in ChromaDB
- FastAPI API → Doc Metadata: manage docs · Track document listing and deletion state
- FastAPI API → Retrieval Layer: question flow · Start retrieval for incoming user questions
- Retrieval Layer → MiniLM Embedder: embed query · Create query embedding with the same model
- Retrieval Layer → ChromaDB: similarity search · Find the most relevant stored chunks/pages
- Retrieval Layer → Answer Formatter: ground context · Pass retrieved evidence into answer assembly
- Answer Formatter → Ollama LLM: generate answer · Send context and question to the local LLM
- Answer Formatter → FastAPI API: citations · Return answer text with filename, page, score, and snippet
- Doc Metadata → Answer Formatter: source data · Provide provenance for citation formatting
- ChromaDB → Doc Metadata: page provenance · Keep document and page references attached to stored chunks
- Retrieval Layer → Answer Formatter: insufficient context · Trigger the fallback when retrieval is not strong enough