How senthil-netxyper/techjays_rag_senthil works
Purpose and entry points
RAGVault is a Django server-rendered application for PDF-scoped question answering. Users upload PDFs, which are indexed locally for semantic retrieval; chat answers are generated through OpenAI. Primary runtime entry points are rag_project/manage.py, rag_project/rag_project/wsgi.py, and rag_project/rag_project/asgi.py; root routing is in rag_project/rag_project/urls.py.
Web and persistence boundary
The documents Django app owns HTTP workflows, HTML rendering, and relational records. Routes map upload, document listing, document chat, and deletion through rag_project/documents/urls.py and rag_project/documents/views.py. Templates in rag_project/documents/templates/documents/ provide the upload, management, and chat UI.
SQLite, managed through Django ORM, stores document metadata and durable chat history via rag_project/documents/models.py. Uploaded files are saved as Django media files. This relational store is separate from the vector index.
Ingestion transaction
Upload handling validates and creates a document record, then invokes the RAG ingestion path. PDF extraction and chunking occur in rag_project/rag/document_loader.py: PyMuPDF extracts text and LangChain’s recursive splitter emits 500-character chunks with 50-character overlap. Failures in extraction or indexing trigger cleanup of the relational record.
Embedding and vector-index layer
rag_project/rag/embedding.py loads the local Sentence Transformers all-MiniLM-L6-v2 model and produces 384-dimensional embeddings. rag_project/rag/vector_store.py persists chunk text, embeddings, IDs, and metadata in a local ChromaDB collection using ./chroma_db. Chunk metadata includes document_id, providing the critical tenancy/isolation boundary between documents.
Retrieval and generation pipeline
The chat view delegates question answering to rag_project/rag/rag_pipeline.py. The pipeline encodes the question, retrieves the top three semantically similar chunks restricted to the selected document, assembles their text as context, and requests an answer. Retrieval logic is isolated in rag_project/rag/retriever.py; OpenAI prompt construction and API invocation (gpt-4.1-mini, key from OPENAI_API_KEY) are in rag_project/rag/generator.py.
Query and history flow
For each chat request: browser → Django view → ask_question(question, document_id) → embedding/query against ChromaDB with a document-ID filter → grounded OpenAI completion → ChatMessage persistence → rendered chat history. The answer depends on both local retrieval infrastructure and the external OpenAI API; embeddings and ChromaDB operate locally.
Deletion consistency
Document deletion crosses both persistence systems: Django removes the document and associated chat messages through relational ownership, while vector-store operations delete that document’s indexed chunks. The deletion workflow is orchestrated from rag_project/documents/views.py and vector deletion is implemented in rag_project/rag/vector_store.py; these stores must remain synchronized to prevent stale retrieval data.
Main entry points: views.py Upload, chat & delete · rag_pipeline.py Question-answer pipeline · urls.py Root routing · models.py Document & chat records
Components 17
Django Runtime
- Django CLI
rag_project/manage.py - WSGI server
rag_project/rag_project/wsgi.py - ASGI server
rag_project/rag_project/asgi.py - Root routing
rag_project/rag_project/urls.py
Documents App
- Document routes
rag_project/documents/urls.py - Upload, chat & delete · Orchestrates document workflows.
rag_project/documents/views.py - Document UI · Upload, management, and chat pages.
- Document & chat records
rag_project/documents/models.py - SQLite · Metadata and durable chat history.
- PDF media files
Local RAG
- PDF extraction & chunking · PyMuPDF extraction; 500-character chunks with 50-character overlap.
rag_project/rag/document_loader.py - Local embeddings · all-MiniLM-L6-v2 produces 384-dimensional vectors.
rag_project/rag/embedding.py - Chroma vector store · Chunks are isolated by document_id metadata.
rag_project/rag/vector_store.py - Question-answer pipeline
rag_project/rag/rag_pipeline.py - Scoped retrieval · Returns top three chunks filtered by document ID.
rag_project/rag/retriever.py - Grounded generation · Builds prompts and invokes gpt-4.1-mini.
rag_project/rag/generator.py
Other components
- OpenAI API · Uses OPENAI_API_KEY.
Connections 21
- Django CLI → Root routing: runs app routing
- WSGI server → Root routing: serves
- ASGI server → Root routing: serves
- Root routing → Document routes: includes
- Document routes → Upload, chat & delete: dispatches
- Upload, chat & delete → Document UI: renders
- Upload, chat & delete → Document & chat records: creates, reads & deletes
- Document & chat records → SQLite: persists via ORM
- Upload, chat & delete → PDF media files: saves uploaded PDFs
- Upload, chat & delete → PDF extraction & chunking: indexes upload
- PDF extraction & chunking → Local embeddings: chunk text
- Local embeddings → Chroma vector store: stores chunk vectors
- Upload, chat & delete → Question-answer pipeline: ask_question(question, document_id)
- Question-answer pipeline → Local embeddings: embeds question
- Question-answer pipeline → Scoped retrieval: retrieves context
- Scoped retrieval → Chroma vector store: top 3; document_id filter
- Question-answer pipeline → Grounded generation: sends grounded context
- Grounded generation → OpenAI API: completion request
- Question-answer pipeline → Upload, chat & delete: answer
- Upload, chat & delete → Document & chat records: persists ChatMessage
- Upload, chat & delete → Chroma vector store: deletes document chunks