# alucek/quickb architecture

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

- Interactive diagram: https://gitdiagram.com/alucek/quickb
- Repository: https://github.com/alucek/quickb

## Overview

##### Project Type and Purpose
- QuicKB is an open-source, end-to-end machine learning pipeline tool for optimizing document retrieval by:
- Chunking source documents into coherent segments
- Generating synthetic QA pairs
- Fine-tuning embedding models
- It is invoked via a single CLI entrypoint (`src/main.py`) and driven by `config.yaml`.

##### File Structure Analysis
- Top-level files:
- `config.yaml`: central pipeline configuration
- `requirements.txt`, `setup.py`: packaging & dependencies
- `README.md`: detailed overview & usage
- `src/`: core implementation, broken into submodules:
- `chunking/`: various chunker implementations & registry
- `synth_dataset/`: synthetic question generator, deduplicator, rate limiter
- `training/`: model training orchestration
- `hub_upload/`: push datasets/models to Hugging Face Hub
- `prompts/`: prompt templates for LLM-based generation
- `main.py`: orchestrates stages based on `pipeline.from_stage` and `to_stage`

##### Key Insights from README
- Pipeline stages: CHUNK → GENERATE → TRAIN
- Each stage reads/writes JSON artifacts (`knowledgebase.json`, `train_data.json`, model outputs)
- External integrations:
- LiteLLM (any LLM/embedding provider) for chunking & QA generation
- Hugging Face Hub for dataset/model storage and retrieval

1. Config Manager (reads `config.yaml`)
2. Orchestrator (`src/main.py`)
3. Document Ingestion (filesystem or Hub)
4. Chunking Module (registry → chosen chunker)
5. Knowledgebase Output (`knowledgebase.json`)
6. Synthetic QA Generator (LLM + deduplicator + rate limiter)
7. Training Data Output (`train_data.json`)
8. Model Trainer (SentenceTransformers pipeline)
9. Model Output (trained embedding model directory)
10. External Services:
- LiteLLM API (LLM calls, embeddings)
- Hugging Face Hub (dataset/model push & pull)
- Config Manager → Orchestrator (inject settings)
- Orchestrator → Document Ingestion → Chunking Module
- Chunking Module → Knowledgebase Output
- Knowledgebase Output → Synthetic QA Generator
- Synthetic QA Generator → Training Data Output
- Training Data Output + Knowledgebase Output → Model Trainer
- Model Trainer → Model Output
- At each artifact step, optional Hub Upload/Download interactions
- Chunking & QA modules ↔ LiteLLM API
- Upload modules ↔ Hugging Face Hub
c. Architectural Patterns & Principles:
- Modular pipeline stages, pluggable strategies (Strategy Pattern for chunkers)
- Separation of concerns: data preparation vs. model training vs. I/O
- Config-driven behavior for maximum flexibility
- Parallelism in QA generation (rate-limiting & worker pool)
d. Key Technologies & Frameworks:
- Python packaging (`setup.py`)
- Sentence-Transformers, PyTorch (model training)
- LiteLLM (LLM/embedding abstraction)
- Hugging Face Hub SDK
- Standard CLI entrypoint with `argparse` or equivalent in `main.py`

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% I/O Layer
    subgraph "I/O Layer"
        Config["Config Manager"]:::io
        Orchestrator["Orchestrator\n(src/main.py)"]:::io
        Ingestion["Document Ingestion"]:::io
    end

    %% Core Pipeline
    subgraph "Core Pipeline"
        subgraph "Chunking Module"
            reg["Registry"]:::core
            base["BaseChunker"]:::core
            fixed["FixedTokenChunker"]:::core
            rec["RecursiveTokenChunker"]:::core
            cluster["ClusterSemanticChunker"]:::core
            llmChunk["LLMSemanticChunker"]:::core
            kam["KamradtModifiedChunker"]:::core
            utils["Utilities"]:::core
        end
        chunkOut["Knowledgebase Output\n(knowledgebase.json)"]:::io

        subgraph "Synthetic QA Generator"
            qgen["QuestionGenerator"]:::core
            dedup["Deduplicator"]:::core
            rate["RateLimiter\n(MaxWorkers=150)"]:::core
        end
        qaOut["Training Data Output\n(train_data.json)"]:::io

        subgraph "Model Trainer"
            trainer["Train.py"]:::core
        end
        modelOut["Model Output\n(Embedding Model Dir)"]:::io
    end

    %% Hub Upload Module
    subgraph "Hub Upload Module"
        dsPush["DatasetPusher"]:::core
        cardGen["CardGenerator"]:::core
        template["UploadTemplate.md"]:::io
    end

    %% External Services
    subgraph "External Services"
        llm["LiteLLM API"]:::external
        hub["Hugging Face Hub"]:::external
    end

    %% Connections
    Config -->|inject settings| Orchestrator
    Orchestrator --> Ingestion
    Ingestion --> reg
    reg --> base
    reg --> fixed
    reg --> rec
    reg --> cluster
    reg --> llmChunk
    reg --> kam
    reg --> utils
    llmChunk <--> llm
    base --> chunkOut
    fixed --> chunkOut
    rec --> chunkOut
    cluster --> chunkOut
    kam --> chunkOut
    utils --> chunkOut

    chunkOut --> qgen
    qgen <--> llm
    qgen --> dedup
    dedup --> rate
    rate --> qaOut

    qaOut --> trainer
    chunkOut --> trainer
    trainer <--> llm
    trainer --> modelOut

    chunkOut --> dsPush
    qaOut --> dsPush
    modelOut --> cardGen
    dsPush --> hub
    cardGen --> hub

    %% Click Events
    click Config "https://github.com/alucek/quickb/blob/main/config.yaml"
    click Orchestrator "https://github.com/alucek/quickb/blob/main/src/main.py"
    click reg "https://github.com/alucek/quickb/blob/main/src/chunking/registry.py"
    click base "https://github.com/alucek/quickb/blob/main/src/chunking/base_chunker.py"
    click fixed "https://github.com/alucek/quickb/blob/main/src/chunking/fixed_token_chunker.py"
    click rec "https://github.com/alucek/quickb/blob/main/src/chunking/recursive_token_chunker.py"
    click cluster "https://github.com/alucek/quickb/blob/main/src/chunking/cluster_semantic_chunker.py"
    click llmChunk "https://github.com/alucek/quickb/blob/main/src/chunking/llm_semantic_chunker.py"
    click kam "https://github.com/alucek/quickb/blob/main/src/chunking/kamradt_modified_chunker.py"
    click utils "https://github.com/alucek/quickb/blob/main/src/chunking/utils.py"
    click qgen "https://github.com/alucek/quickb/blob/main/src/synth_dataset/question_generator.py"
    click dedup "https://github.com/alucek/quickb/blob/main/src/synth_dataset/deduplicator.py"
    click rate "https://github.com/alucek/quickb/blob/main/src/synth_dataset/rate_limiter.py"
    click trainer "https://github.com/alucek/quickb/blob/main/src/training/train.py"
    click dsPush "https://github.com/alucek/quickb/blob/main/src/hub_upload/dataset_pusher.py"
    click cardGen "https://github.com/alucek/quickb/blob/main/src/hub_upload/card_generator.py"
    click template "https://github.com/alucek/quickb/blob/main/src/hub_upload/template.md"

    %% Styles
    classDef core fill:#ADD8E6,stroke:#333,stroke-width:1px
    classDef io fill:#90EE90,stroke:#333,stroke-width:1px
    classDef external fill:#FFA500,stroke:#333,stroke-width:1px
```
