# mosh98/rag_with_models architecture

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

- Interactive diagram: https://gitdiagram.com/mosh98/rag_with_models
- Repository: https://github.com/mosh98/rag_with_models

## Overview

##### Main components
- Notebooks organized by functional areas:
- Advanced RAG: Contains demos that showcase more complex RAG pipelines (e.g., using GPT-4o and Self-Querying methods).
- Simple RAG: Demonstrates straightforward RAG implementations with various LLMs and integration with tools like Langchain or Ollama. Notice a “chroma_db” folder that incarnates the vector store used for retrieving embeddings.
- Embeddings: Dedicated notebooks for extracting embeddings from different LLMs (Falcon2, Gemma2, Llama3/3.1, Mistral, Phi-3, Qwen2).
- Fine-Tune: Demonstrates fine-tuning approaches on models and their embeddings.
- Experiments: Some data formatting and preprocessing steps.
- Evaluation: Contains notebooks that test and generate test sets for evaluating the RAG pipelines.
- Underlying external components:
- LLMs: The various large language models are central actors.
- Vector Database: With the “chroma_db” folder, it’s clear that a vector storage mechanism (like Chroma) is used to store embeddings.
- Possibly libraries or frameworks (implied in notebook names) such as Langchain or Ollama for creating and managing RAG pipelines.

##### Relationships and data flows
- Data Preparation & Experimentation: Notebooks in the “Experiments” folder process and format data, setting the stage for subsequent models.
- Embeddings Extraction: Notebooks under “Embeddings” process input data through various LLMs to generate vector representations.
- Fine-Tuning: The “Fine-Tune” notebooks modify LLM parameters and possibly the embeddings space to better adapt the models for specific tasks.
- RAG Pipelines: Both “Simple RAG” and “Advanced RAG” notebooks act as orchestrators that combine query inputs, embeddings extraction, and retrieval from the vector database. They then integrate the responses from the LLMs.
- Evaluation: The “evaluation” notebooks test and validate the performance of the RAG pipelines, indicating a feedback loop to iteratively improve the system.

##### Architectural patterns and design principles
- Modular design: Each functional area is separated into its own folder, suggesting that components are designed to work independently before integration.
- Pipeline flow: Indicate that the data flows from processing/formatting, through embeddings generation, to fine-tuning (if applicable), and then into the RAG pipeline – with evaluation as an external validation loop.

##### Technologies, frameworks, and key libraries
- LLM Models: LLama 3, Mistral, Phi-3, Qwen2 and others.
- RAG orchestration possibly via Langchain or similar orchestration frameworks (as hinted by names such as Lanchain and Ollama).
- Vector stores: Chroma is used to store and quickly retrieve embeddings.
- Notebooks (Jupyter) serve as the interface for each component’s demonstration.

##### Be very detailed
- Don’t oversimplify – break down the system into every logical component based on the directory structure.
- Explicitly mention the interactions between fine-tuning, embeddings, and retrieval components.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Data Preparation Layer
    subgraph "Data Preparation"
        EXP("Experiments & Data Preparation"):::notebook
        EE("Embeddings Extraction"):::notebook
    end

    %% Model Training & Fine-Tuning Layer
    subgraph "Model Training & Fine-Tuning"
        FT("Fine-Tuning"):::notebook
    end

    %% Vector Store
    VC("Vector Database (Chroma)"):::database

    %% RAG Pipelines
    subgraph "RAG Pipelines"
        S_RAG("Simple RAG Pipeline"):::notebook
        A_RAG("Advanced RAG Pipeline"):::notebook
    end

    %% Evaluation Layer
    EV("Evaluation & Testing"):::notebook

    %% External LLM Models
    subgraph "LLM Models"
        LLM1("Llama3/3.1"):::external
        LLM2("Mistral"):::external
        LLM3("Phi-3"):::external
        LLM4("Qwen2"):::external
    end

    %% External Input
    UQ("User Query"):::external

    %% Data Flow Connections
    EXP --> EE
    EE --> VC
    EXP --> FT
    EE --> FT
    VC --> S_RAG
    FT --> S_RAG
    FT --> A_RAG
    UQ --> S_RAG
    UQ --> A_RAG
    S_RAG --> EV
    A_RAG --> EV
    S_RAG --> LLM1
    S_RAG --> LLM2
    S_RAG --> LLM3
    S_RAG --> LLM4
    A_RAG --> LLM1
    A_RAG --> LLM2
    A_RAG --> LLM3
    A_RAG --> LLM4
    EV --> FT

    %% Click Events
    click A_RAG "https://github.com/mosh98/rag_with_models/tree/main/Advanced RAG folder"
    click S_RAG "https://github.com/mosh98/rag_with_models/tree/main/Simple RAG folder"
    click VC "https://github.com/mosh98/rag_with_models/tree/main/Simple RAG/chroma_db folder"
    click EE "https://github.com/mosh98/rag_with_models/tree/main/Embeddings folder"
    click FT "https://github.com/mosh98/rag_with_models/tree/main/Fine-Tune folder"
    click EXP "https://github.com/mosh98/rag_with_models/blob/main/Experiments/Formatting_Data.ipynb"
    click EV "https://github.com/mosh98/rag_with_models/tree/main/evaluation folder"

    %% Styles
    classDef notebook fill:#A8DADC,stroke:#457B9D,stroke-width:2px;
    classDef database fill:#F1FAEE,stroke:#1D3557,stroke-width:2px,stroke-dasharray: 5 5;
    classDef external fill:#F4A261,stroke:#E76F51,stroke-width:2px;
```
