How amitgupta4407/rag works
Project Type and Purpose
• This is a full-stack, modular Retrieval-Augmented Generation (RAG) pipeline with:
• A Python backend that ingests PDF documents, chunks text, creates embeddings, stores/retrieves vectors, and generates answers via LLMs
• A Streamlit-based frontend for file upload, query input, and chat display
• It uses ChromaDB for vector storage and LangChain (plus Ollama/Gemini) for retrieval and generation.
Top-Level Components
a. UI Layer (Streamlit)
• streamlit_app.py (orchestrator)
• components/file_upload.py (PDF upload widget)
• components/chat_interface.py (chat history & response display)
• components/settings.py (model/embedding options)
• styles/main.css (styling)
b. Processing Layer
• pdf_processor.py (extract text from PDFs)
• text_chunker.py (split text into retrievable chunks)
c. Models Layer
• embedding_handler.py (call SBERT embeddings)
• llm_handler.py (wrap Ollama/Gemini APIs via LangChain)
d. RAG Orchestration Layer
• retriever.py (query vector store for relevant chunks)
• generator.py (feed chunks + user query to LLM for answer)
e. Storage Layer (ChromaDB)
• vector_store.py (persist and query embeddings)
• document_store.py (metadata and mapping from chunk to source)
f. Removed Modules (per instructions)
• config.py (configuration loader)
• utils/logger.py (logging utility)
Relationships and Data Flow
1. User uploads one or more PDF files via the UI
2. UI calls pdf_processor → text_chunker → embedding_handler
3. embedding_handler stores vectors & metadata in vector_store & document_store
4. User enters a query in the UI
5. UI forwards query to retriever → fetches top-K chunks from vector_store
6. retriever passes chunks + query to generator → llm_handler
7. llm_handler returns a grounded answer
8. UI displays answer in chat_interface
Architectural Patterns and Principles
• Pipeline pattern for document ingestion
• Separation of concerns: UI / Processing / Models / RAG / Storage
• Modular handlers to swap embedding or LLM backends
• Stateless services: each module receives input and returns output without global state (except ChromaDB)