# sankethsj/phi3-rag-application architecture

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

- Interactive diagram: https://gitdiagram.com/sankethsj/phi3-rag-application
- Repository: https://github.com/sankethsj/phi3-rag-application

## Overview

##### Project Type and Purpose
- The project is a Retrieval-Augmented Generation (RAG) application. It reads PDF documents, generates embeddings (using the Alibaba-NLP/gte-large-en-v1.5 model), stores them in ChromaDB, and then leverages these embeddings during query processing through an LLM layer to provide contextual responses.
- It is a full-stack tool in a sense—but it’s focused on data processing (PDF ingestion and embedding) and AI-based retrieval augmented generation rather than a typical web frontend/backend split.

##### File Structure
- Key project entry point: “main.py” which likely orchestrates the workflow.
- Notebooks: “RAG-Workbook.ipynb” for demonstration or interactive data processing steps.
- Code organization: The “rag” directory contains core modules:
- document_loader.py: Responsible for reading and extracting text from PDF documents.
- keyword_generator.py: Likely handles processing of text (e.g., generating keywords or assisting with feature extraction).
- db.py: Encapsulates interactions with ChromaDB for storing and retrieving embeddings.
- llm.py: Interfaces with the Phi3 (and maybe Ollama for local LLM execution) to generate responses based on retrieved information.
- Supporting files: requirements.txt (dependencies), LICENSE, and docs (with a project report that may provide further context).

##### Extract Insights from the README
- The README details the functionality:
- PDF reading and extraction.
- Embedding generation using an NLP model.
- Storage of embeddings in ChromaDB.
- Retrieval of context and generation (augmented generation).

a. Main Components:
- Entry Point: main.py
- PDF Document Ingestion: Module “document_loader.py”
- Embedding Generation & Keyword Extraction: Partly in “keyword_generator.py” (and possibly integrated with document_loader.py)
- Database Storage: Module “db.py” managing ChromaDB integration.
- Retrieval and Generation: Module “llm.py” which interacts with the local LLM (via Ollama) to generate responses.

b. Visualizing Relationships and Data Flow:
- The process begins with PDF ingestion (document_loader.py) that extracts text.
- The extracted text is sent into the Embedding Generation module (supported by keyword generation if needed).
- Generated embeddings are passed into the database storage (db.py interaction with ChromaDB).
- When a query comes in, the system retrieves relevant embeddings from the database.
- Retrieved contextual data is then sent to the LLM (llm.py) to produce an augmented generation response.

c. Architectural Patterns and Design Principles:
- Modular separation: Each core functionality is isolated in its own module.
- Clean separation of concerns: Document processing, embedding storage, and natural language processing components are distinct.
- Data flow is linear – from PDF ingestion/processing, to embedding storage, then to retrieval and generation.

d. Relevant Technologies, Frameworks, and Libraries:
- Alibaba-NLP/gte-large-en-v1.5 for embeddings.
- ChromaDB for storing and retrieving embeddings.
- Ollama (as per README) for running the local LLM.
- Python’s ecosystem (suggested by the project structure and use of virtual environments).

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "User Interaction"
        U["User/Client"]:::external
    end

    subgraph "Main Workflow"
        MA["Main Application (main.py)"]:::center
    end

    U -->|"starts"| MA

    subgraph "Ingestion Workflow"
        DL["Document Loader (rag/document_loader.py)"]:::ingestion
        KG["Embedding/Keyword Generator (rag/keyword_generator.py)"]:::processing
        DB["Database Manager – ChromaDB (rag/db.py)"]:::storage
    end

    MA -->|"trigger_ingestion"| DL
    DL -->|"extracts_text"| KG
    KG -->|"generates_embeddings"| DB

    subgraph "Query Workflow"
        LLM["LLM Processor (rag/llm.py)"]:::generation
    end

    U -->|"sends_query"| MA
    DB -->|"retrieves_context"| LLM
    LLM -->|"responds"| U

    click MA "https://github.com/sankethsj/phi3-rag-application/blob/master/main.py"
    click DL "https://github.com/sankethsj/phi3-rag-application/blob/master/rag/document_loader.py"
    click KG "https://github.com/sankethsj/phi3-rag-application/blob/master/rag/keyword_generator.py"
    click DB "https://github.com/sankethsj/phi3-rag-application/blob/master/rag/db.py"
    click LLM "https://github.com/sankethsj/phi3-rag-application/blob/master/rag/llm.py"

    classDef external fill:#FDEBD0,stroke:#D35400,stroke-width:2px;
    classDef center fill:#D7BDE2,stroke:#6C3483,stroke-width:2px;
    classDef ingestion fill:#AED6F1,stroke:#1B4F72,stroke-width:2px;
    classDef processing fill:#A9DFBF,stroke:#239B56,stroke-width:2px;
    classDef storage fill:#F9E79F,stroke:#B7950B,stroke-width:2px;
    classDef generation fill:#F5B7B1,stroke:#C0392B,stroke-width:2px;
```
