# brandonstarxel/chunking_evaluation architecture

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

- Interactive diagram: https://gitdiagram.com/brandonstarxel/chunking_evaluation
- Repository: https://github.com/brandonstarxel/chunking_evaluation

## Overview

##### Project type and purpose
- This is an open-source Python library (“chunking_evaluation”) designed to:
- Provide multiple text chunking strategies (e.g., fixed token, semantic, LLM-based)
- Offer an evaluation framework (GeneralEvaluation, SyntheticEvaluation) that compares chunkers using embedding functions and retrieval metrics
- Enable users to plug in custom chunkers and embedding functions and to generate synthetic evaluation datasets

##### File structure
- Top-level files: setup.py (packaging/install), README.md, license, .gitignore
- Package “chunking_evaluation”:
- subpackage “chunking”: BaseChunker & concrete implementations (FixedToken, RecursiveToken, ClusterSemantic, LLM semantic, Kamradt-modified)
- subpackage “evaluation_framework”:
– base_evaluation classes (GeneralEvaluation, SyntheticEvaluation)
– data folders (general_evaluation_data/corpora and questions_db)
– prompts for LLM-based query/excerpt generation
- utils.py for shared utilities
- External dependencies appear in code (chromadb for embedding storage, openai/anthropic for API calls)

##### README for additional insights
- Core workflows:
- “Evaluate a chunker” → instantiate BaseChunker, pick an embedding function, run GeneralEvaluation
- “Evaluate custom embedding function” → plug your own EmbeddingFunction into the same pipeline
- “Synthetic dataset pipeline” → Corpus → generate queries/excerpts via LLM → filter → run SyntheticEvaluation

##### Final advice
- Both batch evaluation (GeneralEvaluation) and synthetic pipeline (SyntheticEvaluation) as parallel flows
- Both input data (corpora, prompt files) and outputs (metrics, CSV results)
- Explicitly show the extension points where users can drop in their own chunkers or embedding functions

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Input Layer
    subgraph "Input Layer"
        CorpusFiles["Corpus Files"]:::datastore
        click CorpusFiles "https://github.com/brandonstarxel/chunking_evaluation/tree/main/chunking_evaluation/evaluation_framework/general_evaluation_data/corpora/"
        QuestionDB["Question DB"]:::datastore
        click QuestionDB "https://github.com/brandonstarxel/chunking_evaluation/tree/main/chunking_evaluation/evaluation_framework/general_evaluation_data/questions_db/"
    end

    %% Chunking Layer
    subgraph "Chunking Layer"
        BaseChunker["BaseChunker"]:::interface
        click BaseChunker "https://github.com/brandonstarxel/chunking_evaluation/blob/main/chunking_evaluation/chunking/base_chunker.py"
        FixedTokenChunker["FixedTokenChunker"]:::module
        click FixedTokenChunker "https://github.com/brandonstarxel/chunking_evaluation/blob/main/chunking_evaluation/chunking/fixed_token_chunker.py"
        RecursiveTokenChunker["RecursiveTokenChunker"]:::module
        click RecursiveTokenChunker "https://github.com/brandonstarxel/chunking_evaluation/blob/main/chunking_evaluation/chunking/recursive_token_chunker.py"
        ClusterSemanticChunker["ClusterSemanticChunker"]:::module
        click ClusterSemanticChunker "https://github.com/brandonstarxel/chunking_evaluation/blob/main/chunking_evaluation/chunking/cluster_semantic_chunker.py"
        LLMSemanticChunker["LLMSemanticChunker"]:::module
        click LLMSemanticChunker "https://github.com/brandonstarxel/chunking_evaluation/blob/main/chunking_evaluation/chunking/llm_semantic_chunker.py"
        KamradtModified["Kamradt-Modified Chunker"]:::module
        click KamradtModified "https://github.com/brandonstarxel/chunking_evaluation/blob/main/chunking_evaluation/chunking/kamradt_modified_chunker.py"
        CustomChunker["CustomChunker"]:::module
    end

    %% Embedding Layer
    subgraph "Embedding Layer"
        EmbeddingFunction["EmbeddingFunction"]:::interface
        OpenAIEmbFn["OpenAIEmbeddingFunction"]:::external
        AnthropicEmbFn["AnthropicEmbeddingFunction"]:::external
        CustomEmbFn["Custom EmbeddingFunction"]:::module
        ChromaDB["ChromaDB (SQLite)"]:::datastore
    end

    %% Evaluation Layer
    subgraph "Evaluation Layer"
        BaseEvaluation["BaseEvaluation"]:::module
        click BaseEvaluation "https://github.com/brandonstarxel/chunking_evaluation/blob/main/chunking_evaluation/evaluation_framework/base_evaluation.py"
        GeneralEvaluation["GeneralEvaluation"]:::module
        click GeneralEvaluation "https://github.com/brandonstarxel/chunking_evaluation/blob/main/chunking_evaluation/evaluation_framework/general_evaluation.py"
        SyntheticEvaluation["SyntheticEvaluation"]:::module
        click SyntheticEvaluation "https://github.com/brandonstarxel/chunking_evaluation/blob/main/chunking_evaluation/evaluation_framework/synthetic_evaluation.py"
    end

    %% Synthetic Pipeline
    subgraph "Synthetic Pipeline"
        Prompts["LLM Prompt Templates"]:::datastore
        click Prompts "https://github.com/brandonstarxel/chunking_evaluation/tree/main/chunking_evaluation/evaluation_framework/prompts/"
        LLMAPI["LLM API (OpenAI/Anthropic)"]:::external
        SyntheticQueries["Synthetic Queries/Excerpts"]:::datastore
        CSVOutput["CSV Results"]:::datastore
    end

    %% Utils and Config
    Utils["Utils"]:::module
    click Utils "https://github.com/brandonstarxel/chunking_evaluation/blob/main/chunking_evaluation/utils.py"
    Setup["setup.py"]:::module
    click Setup "https://github.com/brandonstarxel/chunking_evaluation/blob/main/setup.py"
    Readme["README.md"]:::module
    click Readme "https://github.com/brandonstarxel/chunking_evaluation/blob/main/README.md"

    %% Data Flow
    CorpusFiles -->|raw text| BaseChunker
    BaseChunker -->|chunks| EmbeddingFunction
    FixedTokenChunker -.-> BaseChunker
    RecursiveTokenChunker -.-> BaseChunker
    ClusterSemanticChunker -.-> BaseChunker
    LLMSemanticChunker -.-> BaseChunker
    KamradtModified -.-> BaseChunker
    CustomChunker -.-> BaseChunker

    EmbeddingFunction -->|embeddings| ChromaDB
    OpenAIEmbFn -.-> EmbeddingFunction
    AnthropicEmbFn -.-> EmbeddingFunction
    CustomEmbFn -.-> EmbeddingFunction

    QuestionDB -->|ground-truth| GeneralEvaluation
    ChromaDB -->|retrieval| GeneralEvaluation
    GeneralEvaluation -->|metrics| CSVOutput

    %% Synthetic Flow
    Prompts -->|templates| SyntheticEvaluation
    LLMAPI -->|generate queries| SyntheticEvaluation
    SyntheticEvaluation -->|synthetic data| SyntheticQueries
    SyntheticQueries -->|chunk & embed| BaseChunker
    SyntheticQueries -->|chunk & embed| EmbeddingFunction
    SyntheticEvaluation -->|evaluate| GeneralEvaluation

    %% Utils usage
    Utils -.-> BaseChunker
    Utils -.-> EmbeddingFunction
    Utils -.-> BaseEvaluation

    %% Styles
    classDef module fill:#A0E7E5,stroke:#333,stroke-width:1px;
    classDef interface fill:#B4F8C8,stroke:#333,stroke-width:1px;
    classDef datastore fill:#FFAEBC,stroke:#333,stroke-width:1px,stroke-dasharray: 5 5;
    classDef external fill:#CDB4DB,stroke:#333,stroke-width:1px,stroke-dasharray: 2 2;
```
