# tdtheautomator/local-llm-01 architecture

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

- Interactive diagram: https://gitdiagram.com/tdtheautomator/local-llm-01
- Repository: https://github.com/tdtheautomator/local-llm-01

## Overview

##### Project Type & Purpose
- This is a CLI + Gradio demo application that runs entirely locally.
- It implements a two‑phase Retrieval‑Augmented Generation (RAG) pipeline:
a. Embedding Creation (ingest PDFs → vector store)
b. Query/Chat (retrieve relevant embeddings → local LLM → answers)
- Uses Ollama to serve models, ChromaDB for vector storage, LangChain library for orchestration, and Gradio for UI.

##### File Structure
- Root scripts:
- create_embeddings.py → loads PDFs (docs/) with pypdf, calls mxbai-embed-large to compute embeddings, stores them in ChromaDB.
- query01.py / query02.py → CLI interfaces for RAG queries (different prompts or flows).
- chatbot_gradio_context.py → Gradio app for interactive chat.
- docs/ → source PDF files to index.
- images/ → sample output screenshots (for docs, not in runtime).
- tools/ → precompiled standalone binaries of a simple chatbot (optional extras).
- .gradio/ → Gradio TLS certs & config.
- README.md → instructions & high‑level workflow.

a. Data Ingestion & Embedding Pipeline
- PDFs (docs/)
- create_embeddings.py (LangChain PDF loader + embedding model client)
- ChromaDB local store
b. Model Serving
- Ollama server (deepseek-r1:1.5b for generation; mxbai-embed-large for embeddings)
c. Query Layer
- CLI scripts (query01.py, query02.py)
- Gradio app (chatbot_gradio_context.py)
- LangChain Retriever & LLMChain
d. Vector Store
- ChromaDB files/directories (on disk)
e. External Dependencies
- Ollama daemon (runs locally, exposes gRPC/REST)
- Python environment & libraries (LangChain, Chromadb, Gradio, pypdf)

##### Relationships & Data Flow
- Embedding script → Ollama embedding model → embeddings
- Query script/Gradio UI → LangChain Retriever → ChromaDB (similarity search) → retrieved docs
- Retrieved docs + user query → LangChain LLMChain → Ollama generation model → answer
- UI displays answer back to user

##### Architectural Patterns & Principles
- Pipeline pattern (two distinct jobs: embed vs. query)
- Separation of concerns: storage (ChromaDB), compute (Ollama), orchestration (LangChain scripts), UI (CLI/Gradio)
- Local-first design (everything hosted on the same machine)

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Ingestion Pipeline
    subgraph "Ingestion Pipeline"
        docs["PDF Files"]:::input
        create_embeddings["create_embeddings.py"]:::script
        docs -->|"PDF pages"| create_embeddings
        create_embeddings -->|"requests embeddings"| ollama_embed["Ollama Embedding Model\n(mxbai-embed-large)"]:::service
        ollama_embed -->|"vector embeddings"| chroma["ChromaDB\n(Vector Store)"]:::storage
    end

    %% Query & Retrieval
    subgraph "Query & Retrieval"
        query01["query01.py"]:::script
        query02["query02.py"]:::script
        chroma -->|"similarity search"| query01
        chroma -->|"similarity search"| query02
        query01 -->|"retrieved docs + prompt"| ollama_gen["Ollama Generation Model\n(deepseek-r1:1.5b)"]:::service
        query02 -->|"retrieved docs + prompt"| ollama_gen
        ollama_gen -->|"answer text"| query01
        ollama_gen -->|"answer text"| query02
    end

    %% UI Layer
    subgraph "UI Layer"
        chatbot["chatbot_gradio_context.py"]:::ui
        user_cli["User (CLI)"]:::io
        user_ui["User (Browser)"]:::io
        query01 -->|"CLI output"| user_cli
        query02 -->|"CLI output"| user_cli
        chatbot -->|"prompt + embeddings"| ollama_gen
        ollama_gen -->|"answer"| chatbot
        chatbot -->|"answer"| user_ui
        chatbot -->|uses config/certs| gradio_conf[".gradio/"]:::config
    end

    %% Extras & Documentation
    subgraph "Extras & Documentation"
        tools["tools/"]:::extras
        images["images/"]:::extras
        readme["README.md"]:::docs
    end

    %% Click Events
    click docs "https://github.com/tdtheautomator/local-llm-01/tree/main/docs/"
    click create_embeddings "https://github.com/tdtheautomator/local-llm-01/blob/main/create_embeddings.py"
    click query01 "https://github.com/tdtheautomator/local-llm-01/blob/main/query01.py"
    click query02 "https://github.com/tdtheautomator/local-llm-01/blob/main/query02.py"
    click chatbot "https://github.com/tdtheautomator/local-llm-01/blob/main/chatbot_gradio_context.py"
    click gradio_conf "https://github.com/tdtheautomator/local-llm-01/tree/main/.gradio/"
    click tools "https://github.com/tdtheautomator/local-llm-01/tree/main/tools/"
    click images "https://github.com/tdtheautomator/local-llm-01/tree/main/images/"
    click readme "https://github.com/tdtheautomator/local-llm-01/blob/main/README.md"

    %% Styles
    classDef storage fill:#adebad,stroke:#2d662d,color:#000;
    classDef script fill:#bbdefb,stroke:#1e497f,color:#000;
    classDef service fill:#ffcc80,stroke:#b26a00,color:#000;
    classDef ui fill:#ce93d8,stroke:#6a1b9a,color:#000;
    classDef input fill:#e0e0e0,stroke:#424242,color:#000;
    classDef config fill:#d7ccc8,stroke:#5d4037,color:#000;
    classDef extras fill:#f0f4c3,stroke:#827717,color:#000;
    classDef docs fill:#fff9c4,stroke:#f57f17,color:#000;
    classDef io fill:#f8bbd0,stroke:#880e4f,color:#000;
```
