# amitkumarshorthillsai/rag-project---amit-kumar architecture

> Architecture diagram of the GitHub repository amitkumarshorthillsai/rag-project---amit-kumar, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-17). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/amitkumarshorthillsai/rag-project---amit-kumar
- Repository: https://github.com/amitkumarshorthillsai/rag-project---amit-kumar

## Overview

##### Project type and purpose
- This is a full-pipeline Retrieval-Augmented Generation (RAG) system specialized for Wikipedia Q&A.
- It combines:
- A data-ingestion (scraper) service
- A processing/embedding pipeline
- A vector store (FAISS)
- A retrieval + generation service (RAG)
- A Streamlit-based front-end
- Offline evaluation modules (traditional and LLM-based)

##### Top-level directory analysis
- app/
- ui_app.py: Streamlit chatbot UI
- test_chatbot_ui.py & test_result_chatbot_ui/: UI tests & logs
- scrapers/
- wiki_scraper.py: crawl & JSON-dump Wikipedia pages
- test_scraper.py & logs: unit tests & execution logs
- src/
- rag_pipeline.py: chunk → embed → index into FAISS
- mini_rag.py: minimal end-to-end demo
- embeddings/: serialized FAISS indexes
- GroundTruth_Context_Generation/
- groundTruth_context.py: enrich Q&A with contexts
- bert_evaluation/
- bert_score_eval.py: computes BLEU, ROUGE, BERTScore
- outputs/: results and logs
- ragas_eval_custom/
- evaluate.py, gemini_client.py, prompts.py: custom LLM evaluation via Gemini
- requirements.txt, .env, .gitignore

##### README insights
- Clearly spells out:
- Scraping → chunking → embedding → FAISS storage → reranking → generation via LLaMA3/Ollama → UI
- Two evaluation paths: traditional (BERTScore, ROUGE, BLEU) and LLM-based (Gemini)
- Technologies: WikipediaAPI, BeautifulSoup, RecursiveCharacterTextSplitter, HuggingFace, FAISS, Ollama, Streamlit

##### Components & interactions
a. Components
1) Scraper Service
- wiki_scraper.py
- External: WikipediaAPI, BeautifulSoup
- Output: raw JSON → scrapers/data/raw_scraped/
2) Chunking & Embedding Pipeline
- rag_pipeline.py
- RecursiveCharacterTextSplitter → embeddings via BAAI/bge-large-en-v1.5
- Output: FAISS index stored in src/embeddings/
3) Vector Store (FAISS)
- High-dimensional index on disk/in-memory
4) Reranker
- cross-encoder/ms-marco-MiniLM-L-6-v2
- Re-orders top-k retrieved chunks
5) Generation Service
- llama3:8b via Ollama
- Accepts reranked context + question → produces answer
6) Streamlit UI
- app/ui_app.py
- Fetches from RAG service, logs to app/test_result_chatbot_ui/
7) Ground-Truth Context Generation
- groundTruth_context.py
- Generates enriched Q&A for evaluation
8) Evaluation Modules
- Traditional metrics: bert_score_eval.py → outputs to bert_evaluation/bert_eval_output/
- LLM-based: evaluate.py → uses Gemini-2.0-flash, logs under ragas_eval_custom/

b. Data flow & dependencies
- Scraper → Raw JSON → Pipeline
- Pipeline → FAISS index
- UI / RAG service → Query → FAISS → Reranker → LLaMA3 → Response → UI
- GroundTruth script + generated answers → Evaluation modules → Reports

c. Architectural patterns
- Modular ETL + retrieval pipeline
- Clear separation of concerns (ingestion, processing, storage, serving, evaluation)
- Pluggable embedding & reranking models
- Service-oriented structure (could be isolated as microservices)

d. Key technologies & libraries
- Data ingestion: WikipediaAPI, BeautifulSoup
- Chunking: LangChain’s RecursiveCharacterTextSplitter
- Embedding: HuggingFace Transformers (BAAI/bge-large-en-v1.5)
- Vector DB: FAISS
- Reranker: cross-encoder/ms-marco-MiniLM-L-6-v2
- Generation: LLaMA3 via Ollama
- UI: Streamlit
- Evaluation: BERTScore, ROUGE, BLEU, Google Gemini

##### Final recommendations
- As many logical components as possible without clutter
- Modularity: each folder → separate service
- Keep it high-level but annotate major sub-steps (scrape, chunk, embed, index, retrieve, rerank, generate, evaluate)

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Ingestion Layer
    subgraph "Ingestion Layer"
        direction TB
        Scraper["Scraper Service\n(scrapers/wiki_scraper.py)"]:::compute
        Tests1["Scraper Tests & Logs\n(test_scraper.py, test_result_scraper/log.json)"]:::compute
    end

    %% Processing Layer
    subgraph "Processing Layer"
        direction TB
        Pipeline["Chunking & Embedding Service\n(src/rag_pipeline.py)"]:::compute
        MiniDemo["Mini RAG Demo\n(src/mini_rag.py)"]:::compute
        Tests2["Pipeline Tests\n(src/test_ragPipeline.py)"]:::compute
    end

    %% Storage Layer
    subgraph "Storage Layer"
        direction TB
        RawJSON["Raw JSON Data\n(scrapers/data/raw_scraped/)"]:::datastore
        FAISS["FAISS Index\n(src/embeddings/)"]:::datastore
    end

    %% Retrieval & Generation
    subgraph "Retrieval & Generation"
        direction TB
        Reranker["Reranker\n(cross-encoder/ms-marco-MiniLM-L-6-v2)"]:::compute
        Generator["Generation Service\n(LLaMA3 via Ollama)"]:::compute
    end

    %% Front-End
    subgraph "Front-End"
        direction TB
        UI["Streamlit UI\n(app/ui_app.py)"]:::frontend
        UITests["UI Tests & Logs\n(app/test_chatbot_ui.py, app/test_result_chatbot_ui/)"]:::frontend
    end

    %% Evaluation Layer
    subgraph "Evaluation Layer"
        direction TB
        GroundTruth["GroundTruth Context Generation\n(GroundTruth_Context_Generation/groundTruth_context.py)"]:::compute
        GTData["Ground-Truth Data Files\n(eval_data.csv, eval_data_enriched.csv)"]:::datastore
        subgraph "Traditional Evaluation"
            direction TB
            TradEval["Traditional Eval Module\n(bert_score_eval.py)"]:::evaluation
            TradIO["Inputs & Outputs\n(input.csv, bert_eval_output/)"]:::datastore
        end
        subgraph "LLM-Based Evaluation"
            direction TB
            LLMEval["LLM-Based Eval Module\n(evaluate.py)"]:::evaluation
            GeminiClient["Gemini Client & Prompts\n(gemini_client.py, prompts.py)"]:::compute
            LLMEIO["Inputs, Scores & Logs\n(enriched_eval_data.csv, enriched_eval_with_scores.csv, logs/gemini_logs.log)"]:::datastore
        end
    end

    %% External Dependencies
    WikipediaAPI["Wikipedia API"]:::external
    BeautifulSoup["BeautifulSoup"]:::external
    Ollama["Ollama (LLaMA3)"]:::external
    GeminiAPI["Gemini API"]:::external

    %% Asset & Config
    Assets["Static Assets\n(assets/)"]:::datastore
    Config["Project Config & Dependencies\n(requirements.txt, .env, .gitignore, README.md)"]:::external

    %% Connections
    Scraper -->|"outputs raw JSON"| RawJSON
    RawJSON -->|"feeds"| Pipeline
    Pipeline -->|"builds index"| FAISS
    MiniDemo --> FAISS
    FAISS -->|"retrieval"| Reranker
    Reranker -->|"reranked context"| Generator
    Generator -->|"answer"| UI
    UI -->|"query"| FAISS

    GroundTruth --> GTData
    UI -->|"generated answers"| TradEval
    GTData --> TradEval
    TradEval --> TradIO

    GTData --> LLMEval
    LLMEval --> LLMEIO
    GeminiClient --> LLMEval
    GroundTruth --> LLMEval

    %% App tests dependencies
    Scraper --> Tests1
    Pipeline --> Tests2
    UI --> UITests

    %% External dependency edges
    Scraper --> WikipediaAPI
    Scraper --> BeautifulSoup
    Generator --> Ollama
    LLMEval --> GeminiAPI

    %% Click Events
    click Scraper "https://github.com/amitkumarshorthillsai/rag-project---amit-kumar/blob/master/scrapers/wiki_scraper.py"
    click Tests1 "https://github.com/amitkumarshorthillsai/rag-project---amit-kumar/blob/master/scrapers/test_scraper.py"
    click Pipeline "https://github.com/amitkumarshorthillsai/rag-project---amit-kumar/blob/master/src/rag_pipeline.py"
    click MiniDemo "https://github.com/amitkumarshorthillsai/rag-project---amit-kumar/blob/master/src/mini_rag.py"
    click Tests2 "https://github.com/amitkumarshorthillsai/rag-project---amit-kumar/blob/master/src/test_ragPipeline.py"
    click UI "https://github.com/amitkumarshorthillsai/rag-project---amit-kumar/blob/master/app/ui_app.py"
    click UITests "https://github.com/amitkumarshorthillsai/rag-project---amit-kumar/blob/master/app/test_chatbot_ui.py"
    click GroundTruth "https://github.com/amitkumarshorthillsai/rag-project---amit-kumar/blob/master/GroundTruth_Context_Generation/groundTruth_context.py"
    click TradEval "https://github.com/amitkumarshorthillsai/rag-project---amit-kumar/blob/master/bert_evaluation/bert_score_eval.py"
    click TradIO "https://github.com/amitkumarshorthillsai/rag-project---amit-kumar/blob/master/bert_evaluation/input.csv"
    click LLMEval "https://github.com/amitkumarshorthillsai/rag-project---amit-kumar/blob/master/ragas_eval_custom/evaluate.py"
    click GeminiClient "https://github.com/amitkumarshorthillsai/rag-project---amit-kumar/blob/master/ragas_eval_custom/gemini_client.py"
    click LLMEIO "https://github.com/amitkumarshorthillsai/rag-project---amit-kumar/blob/master/ragas_eval_custom/input/enriched_eval_data.csv"
    click Assets "https://github.com/amitkumarshorthillsai/rag-project---amit-kumar/tree/master/assets/"
    click Config "https://github.com/amitkumarshorthillsai/rag-project---amit-kumar/blob/master/requirements.txt"

    %% Styles
    classDef compute fill:#c7f9cc,stroke:#2d6a4f,stroke-width:1px
    classDef datastore fill:#ade8f4,stroke:#0077b6,stroke-width:1px
    classDef frontend fill:#e0c3fc,stroke:#6a0dad,stroke-width:1px
    classDef evaluation fill:#ffd6a5,stroke:#ff5200,stroke-width:1px
    classDef external fill:#f0f0f0,stroke:#999999,stroke-width:1px,stroke-dasharray: 5 5
```
