# anujsonawane60/rag_pipeline_v3 architecture

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

- Interactive diagram: https://gitdiagram.com/anujsonawane60/rag_pipeline_v3
- Repository: https://github.com/anujsonawane60/rag_pipeline_v3

## Overview

##### Main components
- Server/Backend: Represent the FastAPI application (main.py) running through Uvicorn that handles API endpoints. This is responsible for chatbot management, file uploads, and routing user requests.
- OpenAI, Cohere, and TogetherAI for handling LLM responses.
- Pinecone to manage and search through vectorized document representations.
- Data Storage: Although not explicitly indicated by a database file, include a component for storing chat history and uploaded documents (implying persistence, possibly an internal or external datastore).
- File Upload/Processing Module: Show a module that handles file validation and processing (via libraries like PyPDF2 and docx).

##### Relationships and interactions
- Clients interact via the Static Frontend (browser) which sends requests to the FastAPI backend.
- The FastAPI backend (running with Uvicorn) receives HTTP requests to create/manage chatbots, process file uploads, and route chat messages.
- When a chatbot request needs an LLM response, the backend communicates with the chosen LLM APIs (OpenAI, Cohere, TogetherAI) based on user configuration.
- The backend uses Pinecone for vector searches when integrating uploaded documents for context.
- The file upload component validates file types and sizes before processing their content.

##### Architectural patterns and design principles
- API-based architecture: The system follows a clear separation between backend API (FastAPI) and frontend (static HTML).
- Modular integration: Note the clear boundary for integrations with external services like LLM providers and Pinecone.
- Extensible design: Since multiple language models can be used interchangeably, there’s an abstraction layer for interfacing with these external APIs.
- Data processing pipeline: Include the validation and document parsing steps to underline how documents are used for retrieval augmentation.

##### Relevant technologies and frameworks
- FastAPI & Uvicorn: The backbone for the server and API routing.
- LLM APIs: OpenAI, Cohere, and TogetherAI (use logos or labels for clarity).
- Pinecone: For vector storage and retrieval.
- Python libraries: PyPDF2, docx (to denote document parsing and validation).
- Static HTML: Represent the user interface components.

- Each major component should be clearly delineated and labeled.
- Annotations (if needed) to explain functions like file validation, document processing, and chat history management.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Subgraph
    subgraph "Frontend"
        FE1["index.html"]:::frontend
        FE2["chatbot.html"]:::frontend
    end

    %% Backend Subgraph
    subgraph "Backend"
        BE1["FastAPI Server"]:::backend
        BE2["File Upload Module"]:::fileModule
    end

    %% External LLM APIs Subgraph
    subgraph "LLM APIs"
        LO["OpenAI"]:::external
        LC["Cohere"]:::external
        LT["TogetherAI"]:::external
    end

    %% External Services and Data Storage
    PC["Pinecone"]:::external
    DS(("Data Storage")):::storage

    %% Connections: Frontend to Backend
    FE1 -->|"HTTP_request"| BE1
    FE2 -->|"HTTP_request"| BE1

    %% File Upload Flow
    FE2 -->|"upload_file"| BE2
    BE2 -->|"process_upload"| BE1

    %% Backend to External LLM APIs
    BE1 -->|"LLM_call"| LO
    BE1 -->|"LLM_call"| LC
    BE1 -->|"LLM_call"| LT

    %% Backend to Pinecone for vector search
    BE1 -->|"Vector_search"| PC

    %% Backend to Data Storage for chat history and document storage
    BE1 -->|"Store_data"| DS

    %% Click Events
    click BE1 "https://github.com/anujsonawane60/rag_pipeline_v3/blob/main/main.py"
    click FE1 "https://github.com/anujsonawane60/rag_pipeline_v3/blob/main/static/index.html"
    click FE2 "https://github.com/anujsonawane60/rag_pipeline_v3/blob/main/static/chatbot.html"

    %% Styles
    classDef frontend fill:#cce5ff,stroke:#333,stroke-width:2px;
    classDef backend fill:#d4edda,stroke:#333,stroke-width:2px;
    classDef external fill:#f8d7da,stroke:#333,stroke-width:2px;
    classDef fileModule fill:#fff3cd,stroke:#333,stroke-width:2px;
    classDef storage fill:#d1ecf1,stroke:#333,stroke-width:2px;
```
