# leokwsw/local-rag architecture

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

- Interactive diagram: https://gitdiagram.com/leokwsw/local-rag
- Repository: https://github.com/leokwsw/local-rag

## Overview

##### Main Components
- Python Application: Represent the core “local_RAG.py” script, which acts as the backbone of the application logic – handling document ingestion, pre-processing with the Unstructured library, and orchestrating the retrieval and generation workflow.
- Document Ingestion & Pre-processing: Indicate the Unstructured library that is integrated in the Python code to ingest and process documents.
- Vector Database (Weaviate): Illustrate the Weaviate vector database that is started via Docker Compose (as indicated in the Docker instructions). This component stores indexed document embeddings.
- Llama2 Model Inference Engine: Include the locally installed Llama2 model (obtained using llama-cpp-python) used for generating responses based on the information retrieved from the vector database.

##### Relationships and Data Flow
- For the query or retrieval process, show a reverse flow: from the user or an “Application Query” component to the vector database to fetch relevant documents.

##### Architectural Patterns and Design Components
- Separation of concerns: the ingestion/pre-processing is decoupled from the data storage (Weaviate) and from the generation logic.
- Stress that the design is self-contained, meaning that each component is deployed locally (the Weaviate DB runs as a Docker container and the Llama model is installed locally).

##### Relevant Technologies
- Python (with details like version 3.9+ and virtual environment usage)
- Unstructured (the library for document processing)
- Docker & Docker Compose (for spinning up the Weaviate container)
- Weaviate (for the Vector Database)
- llama-cpp-python with Llama2 model files (for text generation)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Ingestion Pipeline
    A["Input Documents"]:::ingestion
    B["Document Ingestion & Pre-processing"]:::python
    C["Python Application (Core RAG Script)"]:::python

    %% Data Storage & Retrieval
    D["Vector Database (Weaviate)"]:::db

    %% Query and Generation Pipeline
    E["Application Query"]:::query
    F["Llama2 Model Inference Engine"]:::model
    G["Generated Response"]:::response

    %% Flow Connections - Ingestion to Storage
    A -->|"ingests"| B
    B -->|"triggers"| C
    C -->|"stores embeddings"| D

    %% Flow Connections - Retrieval to Generation
    E -->|"requests retrieval"| D
    D -->|"returns contexts"| F
    F -->|"generates"| G

    %% Click Events from Component Mapping
    click C "https://github.com/leokwsw/local-rag/blob/main/local_RAG.py"
    click B "https://github.com/leokwsw/local-rag/blob/main/local_RAG.py"
    click D "https://github.com/leokwsw/local-rag/blob/main/.env.example"
    click F "https://github.com/leokwsw/local-rag/blob/main/requirements.txt"

    %% Styles
    classDef ingestion fill:#577590,stroke:#333,stroke-width:2px,color:#fff;
    classDef python fill:#f9c74f,stroke:#333,stroke-width:2px,color:#000;
    classDef db fill:#90be6d,stroke:#333,stroke-width:2px,color:#000;
    classDef query fill:#277da1,stroke:#333,stroke-width:2px,color:#fff;
    classDef model fill:#f3722c,stroke:#333,stroke-width:2px,color:#fff;
    classDef response fill:#43aa8b,stroke:#333,stroke-width:2px,color:#fff;
```
