How yash1802/on-device-research-assistant-powered-by-rag-and-live-web-search works
Project type and purpose
• This is a full-stack RAG (Retrieval-Augmented Generation) prototype with both a user interface (Streamlit) and multiple backend pipelines for Web scraping, PDF ingestion, retrieval, embedding storage, and optional LLM answer synthesis via Google Gemma.
• Purpose: allow end users to query the web and/or uploaded PDFs, retrieve relevant text chunks, embed them, and optionally feed a language model to produce grounded answers.
File structure
• Top-level UI:
• Streamlit_Driver.py – orchestrates UI, mode selection, invokes pipelines
• Backend pipelines:
• Web_RAG_Model.py – web-only RAG pipeline
• Pdf_RAG_Model.py – PDF-only RAG pipeline
• PDF_Web_RAG_Model.py – combined Web+PDF retrieval
• LLM_Pdf_Web_RAG.py – combined RAG retrieval + LLM answer synthesis
• LLM_Module.py – direct LLM querying (no RAG)
• Shared config:
• ImportsForModel.py – centralizes imports, device detection, quantization defaults
• Data storage (created at runtime):
• EmbeddingStorage/ – serialized embeddings (.pkl)
• cache/ – metadata about scraped URLs
• scraped_texts/ – raw text of scraped pages
• requirements.txt – lists external libraries: streamlit, sentence-transformers, PyMuPDF, faiss, bitsandbytes, etc.
README for additional insights
• Detailed description of web pipeline (googlesearch-python, BeautifulSoup, boilerplate removal, language filter, chunking)
• PDF pipeline (PyMuPDF, chapter detection, overlapping chunking)
• Retrieval algorithms: dot-product, cosine, Euclidean, FAISS, BM25+embeddings, cross-encoder reranking
• LLM integration: Google Gemma 2B/7B via HF Transformers, FlashAttention2, optional 4-bit quantization
• UI modes: five search modes selecting different pipelines or LLM paths
a. Main components
• User Interface (Streamlit Driver)
• Mode Router / Controller
• Web Scraper & Processor
• PDF Ingestion & Processor
• Chunking Module
• Embedding Module (all-mpnet-base-v2)
• Retrieval Engine(s):
• Similarity Search (dot, cos, Euclid)
• FAISS Index
• BM25 + Dense Hybrid
• Cross-Encoder Reranker
• LLM Module (Google Gemma via Transformers)
• Storage Layer (file system): EmbeddingStorage, cache, scraped_texts
• External Services: Google Search API, Websites, Hugging Face Hub
b. Relationships & data flow
1. UI → Controller: captures query, mode, PDF upload
2. Controller → appropriate pipeline module
3. Pipeline →
• If Web: call Web Scraper → clean HTML → chunk
• If PDF: call PDF Processor → extract text → chunk
• If combined: do both streams in parallel or sequence
4. Chunks → Embedding Module → persist/fetch embeddings in EmbeddingStorage
5. Embeddings → Retrieval Engine(s) → top k chunks
6. If LLM mode: top chunks → LLM Module → generate answer
7. Controller → UI: return chunks and/or LLM answer
c. Architectural patterns & principles
• Layered architecture: UI layer, application/controller layer, processing layer, storage layer
• Pipeline pattern: each data source → clean → chunk → embed → retrieve → (optional) generate
• Separation of concerns: distinct modules for Web, PDF, embeddings, retrieval, LLM
• Config-driven behavior: ImportsForModel centralizes hardware/quantization logic
d. Key technologies & libraries
• Streamlit for UI
• googlesearch-python, readability-lxml, BeautifulSoup4 for web
• PyMuPDF (fitz) for PDF
• spaCy or NLTK for sentence segmentation
• sentence-transformers (“all-mpnet-base-v2”) for embeddings
• faiss-cpu (or faiss-gpu) for ANN search
• rank-bm25 for lexical retrieval
• cross-encoder/ms-marco-MiniLM-L-6-v2 for reranking
• Hugging Face Transformers + bitsandbytes for Gemma LLM
Detail without over-modularizing
• That ImportsForModel underpins all model and hardware configuration steps.
• Runtime folder creation (cache/, scraped_texts/) as part of the storage component.
• Fallback paths (e.g., 4-bit quantization disabled → float16 path).