RAG/app/ — Document Chunking (14 Types)

Transform raw documents into semantically coherent chunks

14 document-type handlers: naive splitter, paper, book, manual, presentation, QA, table, resume, picture (OCR), audio (transcription), email, tag, one, laws.

N
Classes
N
Files
~N k
Lines
N
Key Metric

❓ What is this & why?

The app module contains 14 specialized document-type chunkers. Different document formats have different semantic boundaries: tables need structure preservation, academic papers need section hierarchy, books need chapter breaks, code needs logical units. This module exists to transform raw documents into semantically coherent chunks that can be retrieved and reasoned about as first-class units.

💡 Real-world analogy

Think of a newspaper archive. Articles (papers) need to be cut at section boundaries to preserve meaning. Tables need their grid structure intact. Books need chapters separated, not random paragraphs. A generic 'split by word count' chunker would destroy all this structure. Instead, each document type gets a specialized cutter that understands its layout.

🤔 Why Is It Designed This Way?

{{DESIGN_RATIONALE}} — 150+ words explaining the design choices: what pattern does this follow and why? What constraints shaped the implementation? What trade-offs were made and what was sacrificed?

Design ChoiceWhat Was ChosenWhat Was RejectedWhy
Example: data layoutArray of structsStruct of arraysRandom access pattern dominates; cache locality for single items matters more than SIMD sweeps

Contents

Architecture

flowchart LR
    subgraph Input["Input Documents"]
        I1["PDF"]
        I2["Markdown"]
        I3["Table"]
        I4["Code"]
        I5["Other..."]
    end
    subgraph Detect["Type Detection"]
        D["Detect Format"]
    end
    subgraph Chunkers["14 Chunker Types"]
        C1["Naive Split"]
        C2["Paper"]
        C3["Book"]
        C4["Table"]
        C5["Others..."]
    end
    subgraph Output["Chunks + Metadata"]
        O["Semantic Chunks"]
    end
    Input --> D
    D -->|Strategy| Chunkers
    Chunkers --> O

Key Classes

Class / FunctionFilePurpose
ClassNamefile.hBrief description

Data Structures

TypeNameDescription
enumEnumNameBrief description

Interactions

DirectionPartnerInterfaceDescription
→Other ModulemethodName()Brief description

Configuration

Knob / ParameterDefaultDescription
param_namevalueWhat it controls

Directory Map

Source tree for app
submod_name/
├── file_a.ext                 ← Role: brief annotation
├── file_b.ext                 ← Role: brief annotation
├── file_c.ext                 ← Role: brief annotation
└── index.ext                  ← Role: entry point

📑 Annotated Code Walkthrough

The most important code in this sub-module, annotated with WHY each piece exists:

{{KEY_FUNCTION_NAME}}

// Replace with actual code from the source
void key_function() {
    // ← WHY: Explain the purpose of this line
    // ← WHY: What constraint or requirement drives this?
}

Line-by-line:

  • Line N: What this does and WHY — what would break if removed
  • Line M: The design choice here — why this approach over the obvious alternative

⚠️ Edge Cases & Boundaries

Edge CaseWhat HappensWhere in CodeRisk Level
Empty inputHow it's handledfunction_name:line🟢 Low
Concurrent accessHow it's handledfunction_name:line🔴 High

Processing Workflow

sequenceDiagram
    participant User as User/API
    participant Detector as Type Detector
    participant Chunker as Specialized Chunker
    participant Metadata as Metadata Handler
    User->>Detector: Document submitted
    Detector->>Detector: Analyze format
    Detector->>Chunker: Route to handler
    Chunker->>Chunker: Parse content
    Chunker->>Metadata: Extract structure
    Metadata->>User: Return chunks + metadata

Code Examples

Example: Typical Usage

// Replace with actual code example
void example() {
    // ...
}