How arshnoor-singh-sohi/advanced-rag-system works
Project Type and Purpose
• This is a full‐stack Retrieval‐Augmented Generation (RAG) knowledge management system combined with an experimentation and analysis platform.
• The “src/app” directory hosts both a CLI demo (rag_app.py) and a Streamlit web UI (streamlit_app.py).
• The “src/components” folder implements the core RAG pipeline (chunking, embedding, retrieval, query processing, reranking, generation).
• The “experiments” folder contains scripts to systematically vary RAG subcomponents and log results.
• The “analysis” folder processes experiment outputs into figures and paper tables for academic reporting.
Core Architectural Layers
A. Presentation / UI Layer
• CLI interface (rag_app.py)
• Web interface (streamlit_app.py)
B. Application / Service Layer (RAG Pipeline)
• Document chunking strategies
• Embedding providers
• Retrieval methods
• Query processing (expansion, HyDE)
• Reranking mechanisms
• Generation/prompting
C. Data & Storage Layer
• Corpus loader (data/, pickled files)
• Vectorstore handler (FAISS index & metadata)
• File‐based results storage (results/)
• Figures & paper tables (figures/, paper_figures/)
D. Experimentation Orchestration
• run_experiments.py driver
• Individual experiment modules (experiments/*.py)
• Experiment tracking & logging (src/utils/experiment_tracker.py, experiment_run.log)
E. Analysis & Reporting
• analysis/analyze_results.py
• analysis/paper_figures.py
• Generates CSVs, charts, LaTeX tables
Component Interactions and Data Flow
1. User submits a query via CLI or Web UI
2. UI invokes the RAG pipeline service
– Input documents are chunked → embeddings generated → vector search (and/or BM25) → candidate passages
– Query transformations or HyDE may augment the query
– Reranking stage refines top candidates
– Prompt + context sent to LLM (OpenAI/HuggingFace) for final answer
3. Answer returned to UI and logged if in “demo” mode
4. In experiment mode, run_experiments.py loops over component configurations, invokes the pipeline, writes JSON/CSV to results/
5. Analysis scripts consume results/ → produce recommendation JSONs + performance CSVs in figures/ → optionally generate IEEE‐style tables in paper_figures/
Architectural Patterns & Design Principles
• Layered architecture separating UI, service, data, experiment, and analysis
• Pipeline pattern: data flows through a fixed sequence of modular components
• Single source of truth for configuration (user_config.json, CLI flags)
• Clear directory separation: src/components, experiments, analysis, results
Key Technologies & Frameworks
• Python 3.x
• Streamlit for web UI
• FAISS for vector indexing
• SentenceTransformers, HuggingFace, OpenAI APIs for embeddings/LLM calls
• JSON/CSV for config & results
• Experiment tracking via custom experiment_tracker.py
• Matplotlib/Seaborn or similar in analysis for chart generation