# ashishkumar0724/simple_rag_chat architecture

> Architecture diagram of the GitHub repository ashishkumar0724/simple_rag_chat, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-22). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/ashishkumar0724/simple_rag_chat
- Repository: https://github.com/ashishkumar0724/simple_rag_chat

## Overview

##### Project Type and Purpose
- This is a lightweight Retrieval‑Augmented Generation (RAG) application: a single‑page Streamlit web app that lets a user chat with local PDF documents.
- It leverages Deepseek for embeddings, LangChain as the orchestration layer, and Ollama (running a local LLM: deepseek‑r1:1.5b) for answer generation.

##### File Structure Highlights
- main.py: contains the entire app logic (UI + pipeline).
- requirements.txt: lists Python dependencies (streamlit, langchain, deepseek, ollama).
- README.md: usage instructions.
- zhang2021.pdf: example document.

##### Key Components
a. Frontend (Streamlit UI)
b. PDF Loader & Text Splitter
c. Embedding Service (Deepseek via Ollama)
d. Vector Store (in‑memory or disk)
e. RAG Chain (LangChain orchestrator)
f. LLM Inference (Ollama running deepseek‑r1:1.5b)
g. User’s Local PDF Files

##### Relationships & Data Flow
1) User enters a query in the Streamlit UI
2) The app loads the selected PDF(s) → splits into chunks
3) Each chunk is sent to Deepseek to produce embeddings
4) Embeddings are saved in a local vector store
5) On query, retrieve top‑k relevant chunks from the vector store
6) LangChain RAG chain constructs a prompt with retrieved chunks
7) Prompt is sent to Ollama (deepseek‑r1:1.5b) → returns an answer
8) Streamlit displays the response back to the user

##### Architectural Patterns & Principles
- Pipeline pattern: stages (load → embed → store → retrieve → generate)
- Separation of concerns: UI vs data processing vs model inference
- Local-first design: PDFs and model run on the user’s machine
- Orchestration via LangChain simplifies the glue code

##### Technologies & Frameworks
- Streamlit: Rapid UI development
- LangChain: Chain-of-thought orchestration
- Deepseek: Embedding model, served via Ollama
- Ollama: Local LLM hosting
- Python: single‑script implementation

##### Essential Elements
- Component names
- Notes on local dependencies (PDF folder, Ollama model)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% User Interaction
    User["User"]:::external
    User -->|"enter query"| Streamlit

    %% UI Layer
    subgraph "UI Layer"
        Streamlit["Streamlit UI"]:::ui
    end

    %% Processing Layer
    subgraph "Processing Layer"
        Loader["PDF Loader & Text Splitter"]:::processing
        Embed["Embedding Service (Deepseek)"]:::processing
        Chain["LangChain RAG Chain"]:::processing
    end

    %% Storage Layer
    subgraph "Storage Layer"
        Vector["Vector Store"]:::storage
    end

    %% Model Layer
    subgraph "Model Layer"
        LLM["LLM Inference (Ollama: deepseek‑r1:1.5b)"]:::model
    end

    %% Local Documents
    LocalPDF["Local PDF Files\n(zhang2021.pdf)"]:::doc

    %% Artifacts
    Requirements["requirements.txt"]:::artifact
    Readme["README.md"]:::artifact

    %% Data Flow
    Streamlit -->|"load PDFs & split"| Loader
    LocalPDF -->|"source PDFs"| Loader
    Loader -->|"chunk & embed"| Embed
    Embed -->|"store embeddings"| Vector
    Streamlit -->|"query trigger"| Vector
    Vector -->|"retrieve top‑k"| Chain
    Chain -->|"construct prompt"| LLM
    LLM -->|"return answer"| Chain
    Chain -->|"send response"| Streamlit

    %% Click Events
    click Streamlit "https://github.com/ashishkumar0724/simple_rag_chat/blob/main/main.py"
    click Loader "https://github.com/ashishkumar0724/simple_rag_chat/blob/main/main.py"
    click Embed "https://github.com/ashishkumar0724/simple_rag_chat/blob/main/main.py"
    click Vector "https://github.com/ashishkumar0724/simple_rag_chat/blob/main/main.py"
    click Chain "https://github.com/ashishkumar0724/simple_rag_chat/blob/main/main.py"
    click LLM "https://github.com/ashishkumar0724/simple_rag_chat/blob/main/main.py"
    click LocalPDF "https://github.com/ashishkumar0724/simple_rag_chat/blob/main/zhang2021.pdf"
    click Requirements "https://github.com/ashishkumar0724/simple_rag_chat/blob/main/requirements.txt"
    click Readme "https://github.com/ashishkumar0724/simple_rag_chat/blob/main/README.md"

    %% Styling
    classDef ui fill:#cfe2f3,stroke:#000
    classDef processing fill:#d9ead3,stroke:#000
    classDef storage fill:#f9cb9c,stroke:#000
    classDef model fill:#d9d2e9,stroke:#000
    classDef doc fill:#fff2cc,stroke:#000
    classDef artifact fill:#f2f2f2,stroke:#000
    classDef external fill:#ffffff,stroke:#000,stroke-dasharray: 5 5
```
