RUNLOCALAIv38
->Will it run?Best GPUCompareTroubleshootStartLearnPulseModelsHardwareToolsBench
Run check
RUNLOCALAI

Independently operated catalog for local-AI hardware and software. Hand-written verdicts. Source-cited claims. Reproducible commands when we have them.

OP·Eruo Fredoline
DIR
  • Models
  • Hardware
  • Tools
  • Benchmarks
TOOLS
  • Will it run?
  • Compare hardware
  • Cost vs cloud
  • Choose my GPU
  • Prompting kits
  • Quick answers
REF
  • All buyer guides
  • Learn local AI
  • Methodology
  • Glossary
  • Errors KB
  • Trust
EDITOR
  • About
  • Author
  • How we make money
  • Editorial policy
  • Contact
LEGAL
  • Privacy
  • Terms
  • Sitemap
MAIL · MONTHLY DIGEST
Get monthly local AI changes
Monthly recap. No spam.
DISCLOSURE

Some links on this site are affiliate links (Amazon Associates and other first-class retailers). When you buy through them, we earn a small commission at no extra cost to you. Affiliate links do not influence our verdicts — there are cards we rate highly that we don't have affiliate relationships with, and cards that sell well that we refuse to recommend. Read more →

© 2026 runlocalai.coIndependently operated
RUNLOCALAI · v38
  1. >
  2. Home
  3. /Learn
  4. /Courses
  5. /Advanced RAG — Chunking, Retrieval, Re-ranking
  6. /Ch. 3
Advanced RAG — Chunking, Retrieval, Re-ranking

03. Fixed-Size vs Semantic Tradeoffs

Chapter 3 of 24 · 15 min
KEY INSIGHT

The optimal strategy depends on document structure complexity; simple documents benefit little from semantic chunking overhead.

Both chunking strategies have distinct performance profiles that suit different use cases.

Fixed-size chunking offers predictable memory usage, uniform embedding computation, and simplicity. Implementation requires only character/word counting and slice operations. However, this approach frequently splits sentences mid-thought and separates related concepts across chunk boundaries.

Semantic chunking preserves document structure but introduces complexity in boundary detection and variable chunk sizes. The overhead becomes significant when processing millions of documents.

Factor Fixed-Size Semantic
Implementation complexity Low Medium-High
Chunk size variance Low High
Context preservation Poor Good
Index size predictability High Medium
Retrieval on fragmented docs Degraded Stable

Hybrid approaches offer a middle path. First, identify semantic boundaries (headings, paragraph breaks). Then apply fixed-size chunking within sections. This preserves section context while maintaining reasonable size uniformity.

def hybrid_chunk(document: str, target_size: int = 400) -> List[str]:
    """Chunk by sections first, then apply size limits within sections."""
    
    # Split by headings (lines starting with # or ALL CAPS followed by :)
    section_pattern = r'(?=\n#{1,6}\s|\n[A-Z][A-Z\s]+:\n)'
    sections = re.split(section_pattern, document)
    
    chunks = []
    for section in sections:
        if len(section) <= target_size:
            if section.strip():
                chunks.append(section.strip())
        else:
            # Apply fixed-size within long sections
            words = section.split()
            for i in range(0, len(words), target_size // 5):
                chunk = ' '.join(words[i:i + target_size // 5])
                if chunk.strip():
                    chunks.append(chunk)
    
    return chunks

Local verification checkpoint

Run the smallest example from this chapter in a local workspace and record the package version, runtime, data path, and observed output. If the result depends on model size, vector count, CPU/GPU backend, or available memory, note that constraint beside the exercise so the lesson remains reproducible.

EXERCISE

Calculate chunk size distribution statistics (mean, std, min, max) for both strategies on a sample of 20 documents using NumPy. Visualize with a histogram.

← Chapter 2
Semantic Chunking at Scale
Chapter 4 →
Multi-Strategy Retrieval