# faridghr/simple-rag-chatbot architecture

> Architecture diagram of the GitHub repository faridghr/simple-rag-chatbot, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-09-19). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/faridghr/simple-rag-chatbot
- Repository: https://github.com/faridghr/simple-rag-chatbot

## Overview

##### Project Type and Purpose
- This is a domain-specific full-stack Python application: a Retrieval-Augmented Generation (RAG) chat-bot.
- Frontend: Streamlit UI.
- Backend: LangChain RAG pipeline in Python.
- Data store: Pinecone vector database for embeddings.
- External service: OpenAI LLM for response generation.
- Purpose: Accept user chat input, retrieve relevant domain documents, and generate informed, context-aware responses.

##### File-Structure Analysis
- Top-level:
- .env (API keys)
- requirements.txt (dependencies)
- src/ (application code)
- report/, video/ (deliverables)
- src/:
- streamlitMain.py (entry point for UI)
- RAG_ChatBot.py (encapsulates RAG pipeline: ingestion, embedding, retrieval, generation)
- materials/ (domain documents loaded into vector store)

##### Key Architectural Components
a. Streamlit Frontend
- Serves HTML widgets, text-input, display of bot responses.
- Communicates over in-process API to RAG pipeline code.
b. RAG Pipeline (LangChain)
- Document Loader: reads materials from src/materials.
- Embedder: converts docs/text and user query to vector embeddings.
- Vector Store Interface: upserts/retrieves embeddings in Pinecone.
- RAG Chain: crafts prompt combining retrieved contexts and forwards to LLM.
c. Vector Database (Pinecone)
- Stores and indexes embeddings.
- Supports efficient similarity search on user queries.
d. LLM Service (OpenAI)
- Receives concatenated prompt + context.
- Returns generated answer.

##### Data Flow & Interactions
1. User types query → Streamlit UI
2. UI calls RAG_ChatBot.query(query)
3. RAG_ChatBot:
a. Query embedding → Pinecone.retrieve(top_k docs)
b. Build prompt with retrieved docs + query
c. Send prompt → OpenAI API → Receive response
4. Streamlit displays response

##### Architectural Patterns & Design Principles
- RAG pattern: explicit separation of retrieval (vector DB) and generation (LLM).
- Single-page app: UI & backend code packaged together via Streamlit.
- Configuration via .env for secrets (OpenAI & Pinecone keys).
- Modular code: RAG_ChatBot.py encapsulates all backend logic.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Local Application
    subgraph "Local Application"
        subgraph "Streamlit UI Layer"
            UI["Streamlit UI"]:::ui
        end

        subgraph "Backend RAG Pipeline"
            Loader["Document Loader"]:::processing
            Embedder["Embedder"]:::processing
            Retriever["Vector Store Interface"]:::processing
            PromptBuilder["Prompt Builder / RAG Chain"]:::processing
            LLMIntegration["LLM Service Integration"]:::processing
        end

        Config["Configurations (.env)"]:::config
        Req["Dependencies (requirements.txt)"]:::config
        Readme["Project Overview (README.md)"]:::config
    end

    %% External Services & Data Stores
    subgraph "Cloud Services"
        Pinecone["Pinecone Vector DB"]:::datastore
        OpenAI["OpenAI LLM API"]:::external
    end

    %% Materials Folder
    Materials["Domain Materials (src/materials/)"]:::datastore

    %% Data Flow
    UI -->|"query(query)"| PromptBuilder
    PromptBuilder -->|"embed query"| Embedder
    Embedder -->|"retrieve top_k docs"| Retriever
    Retriever -->|"fetch embeddings"| Pinecone
    Pinecone -->|"return vectors"| Retriever
    Retriever -->|"provide docs"| PromptBuilder
    PromptBuilder -->|"send prompt"| OpenAI
    OpenAI -->|"response text"| LLMIntegration
    LLMIntegration -->|"return response"| UI

    %% Ingestion Flow
    Loader -->|"read docs"| Materials
    Loader -->|"upsert docs"| Retriever
    Retriever -->|"store embeddings"| Pinecone

    %% Config Usage
    Config --> Retriever
    Config --> OpenAI

    %% Click Events
    click UI "https://github.com/faridghr/simple-rag-chatbot/blob/main/src/streamlitMain.py"
    click Loader "https://github.com/faridghr/simple-rag-chatbot/tree/main/src/materials/"
    click Embedder "https://github.com/faridghr/simple-rag-chatbot/blob/main/src/RAG_ChatBot.py"
    click Retriever "https://github.com/faridghr/simple-rag-chatbot/blob/main/src/RAG_ChatBot.py"
    click PromptBuilder "https://github.com/faridghr/simple-rag-chatbot/blob/main/src/RAG_ChatBot.py"
    click LLMIntegration "https://github.com/faridghr/simple-rag-chatbot/blob/main/src/RAG_ChatBot.py"
    click Config "https://github.com/faridghr/simple-rag-chatbot/blob/main/.env"
    click Req "https://github.com/faridghr/simple-rag-chatbot/blob/main/requirements.txt"
    click Readme "https://github.com/faridghr/simple-rag-chatbot/blob/main/README.md"

    %% Styles
    classDef ui fill:#cce5ff,stroke:#333,stroke-width:1px;
    classDef processing fill:#d4edda,stroke:#333,stroke-width:1px;
    classDef datastore fill:#fff3cd,stroke:#333,stroke-width:1px;
    classDef external fill:#e2e3e5,stroke:#333,stroke-width:1px;
    classDef config fill:#f8d7da,stroke:#333,stroke-width:1px;
```
