Skip to content

rlm-chunking

Select and configure the optimal chunking strategy for documents processed through the RLM workflow. Different content types require different approaches to maintain semantic coherence while respecting context limits.

Split content at exact byte boundaries with optional overlap.

Best for:

  • Unstructured text (logs, raw output)
  • Content without clear section markers
  • Maximum control over chunk sizes

Configuration:

Terminal window
rlm-rs load <file> --chunker fixed --chunk-size 6000 --overlap 1000

Parameters:

  • --chunk-size: Characters per chunk (default: 6000, max: 50000)
  • --overlap: Characters shared between adjacent chunks (default: 0)

Trade-offs:

  • Pro: Predictable chunk sizes, simple to reason about
  • Con: May split mid-sentence or mid-concept

Split at natural boundaries (headings, paragraph breaks, code blocks).

Best for:

  • Markdown documents
  • Source code files
  • Structured data (JSON, XML, YAML)
  • Documentation with clear sections

Configuration:

Terminal window
rlm-rs load <file> --chunker semantic --chunk-size 6000

Behavior:

  • Respects heading hierarchy (h1 > h2 > h3)
  • Keeps code blocks together when possible
  • Preserves paragraph boundaries
  • Falls back to sentence boundaries for dense text

Trade-offs:

  • Pro: Maintains semantic coherence
  • Con: Chunk sizes may vary significantly

Multi-threaded chunking for very large files.

Best for:

  • Files > 10MB
  • When processing time is critical
  • Bulk loading multiple files

Configuration:

Terminal window
rlm-rs load <file> --chunker parallel --chunk-size 100000

Trade-offs:

  • Pro: 2-4x faster for large files
  • Con: Same limitations as fixed chunking
Content TypeStrategyChunk SizeOverlap
Markdown docssemantic60000
Source codesemantic60000
JSON/XMLsemantic60000
Plain textfixed6000500
Log filesfixed60001000
Mixed contentsemantic60000
Very large filesparallel60000

The default chunk size of 6000 characters (~1500 tokens) is optimized for semantic search quality. Larger chunks (up to 50000 max) can be specified for fewer total chunks:

  • Default: 6000 chars (~1500 tokens) - best for semantic search
  • Maximum: 50000 chars (~12,500 tokens) - for fewer chunks

Increase chunk size (up to 50000) when:

  • Content has many small sections
  • Need fewer total chunks
  • Sections are tightly interrelated

Decrease chunk size when:

  • Sub-LLM responses are getting truncated
  • Need more granular analysis
  • Content is dense with important details

Overlap ensures context continuity between chunks.

When to use overlap:

  • Content has flowing narrative
  • Important context may span boundaries
  • Searching for patterns that cross chunk boundaries

Typical values:

  • 0: Structured content with clear boundaries
  • 500-1000: Narrative text, logs
  • 2000+: Dense technical content where context matters

After loading, verify chunking results:

Terminal window
# Show buffer details including chunk count
rlm-rs show <buffer_name> --chunks
# View chunk boundaries
rlm-rs chunk-indices <buffer_name>
# Preview first chunk content
rlm-rs peek <buffer_name> --start 0 --end 3000
Terminal window
rlm-rs load server.log --name logs --chunker fixed --chunk-size 6000 --overlap 500
Terminal window
rlm-rs load docs.md --name docs --chunker semantic
Terminal window
# Concatenate multiple files first, then load
cat src/*.rs > combined.rs
rlm-rs load combined.rs --name code --chunker semantic --chunk-size 6000
Terminal window
rlm-rs load dataset.jsonl --name data --chunker parallel --chunk-size 6000

Chunking strategy affects search quality:

  • Semantic chunking works best with semantic search because chunks align with conceptual boundaries
  • Fixed chunking with overlap helps ensure search queries match content that might span chunk boundaries
  • Embeddings are generated automatically on first search - no manual step required

Chunks too small: Increase --chunk-size or switch to semantic chunking.

Important content split: Add overlap or switch to semantic chunking.

Processing too slow: Use parallel chunking for files > 5MB.

Sub-LLM truncating responses: Decrease chunk size to allow more output space.

Search missing relevant content: Try increasing overlap or switching to semantic chunking.