New to Claude Skills? Learn how to install them →

Cxberg-io on GitHub

Chunking

Free

Efficiently split text for LLMs and RAG ingestion.

Get this skill

Free · Opens the source repo

What Chunking does

Chunking is a specialized tool designed for developers and data scientists who need to prepare text documents for use with large language models (LLMs) and retrieval-augmented generation (RAG) systems. It allows users to split extracted text into manageable chunks, which can be crucial for optimizing context windows and ensuring efficient data ingestion. The skill supports various chunking strategies, including character-based and token-based sizing, making it versatile for different use cases.

The tool operates in two primary modes: inline during document extraction and as a standalone command. When using the inline mode, simply enable chunking with the --chunk flag, and the extracted text will automatically be divided into chunks based on specified sizes and overlaps. This is particularly useful when processing large documents, as it streamlines the workflow and integrates seamlessly into the extraction process.

For users who already have text content, the standalone chunk command provides flexibility to chunk existing text. You can specify chunk sizes and overlaps, and choose from different chunker types, such as text, markdown, yaml, or semantic. This allows for tailored chunking strategies that can preserve document structure or focus on topic boundaries, enhancing the relevance of the chunks for downstream tasks.

Additionally, the skill supports token-based chunk sizing, which is essential for ensuring that the chunks fit within the constraints of specific LLMs. Users can easily switch between character and token sizing based on their needs, making it a powerful tool for both document processing and LLM integration.

When to use it

Use this skill when you need to prepare documents for LLMs or RAG systems, especially when dealing with large volumes of text that require efficient chunking.

When not to use it

This skill may not be suitable for simple text processing tasks that do not require chunking or when working with very small text inputs that do not benefit from segmentation.

What you can build with it

Preparing documents for LLM ingestion

Use the Chunking skill to efficiently split large documents into manageable chunks that fit within the context window of LLMs.

Optimizing RAG systems

Chunk text for RAG ingestion, ensuring that the chunks maintain relevance and structure for better retrieval.

Processing existing text data

Utilize the standalone `chunk` command to segment already available text, applying different chunking strategies as needed.

How to install Chunking

View source

1. Install with the skills CLI

npx skills add xberg-io/xberg/chunking --agent claude-code

2. Or install it manually

Download the skill folder and drop it into ~/.claude/skills/ for all projects, or .claude/skills/ to scope it to one repo. Restart Claude Code so it picks up the new skill.

Anthropic's agentic coding CLI, and the reference implementation of Agent Skills. Drop a skill folder into ~/.claude/skills and Claude Code loads it automatically whenever a task matches the skill's description. Claude Code docs

Inside SKILL.md

Written by xberg-io
<!-- AI-RULEZ :: GENERATED FILE — DO NOT EDIT Content-Hash: blake3:0b5cd4bec9d2a8f3452e07139ef56d6b87f9f7990714d15483a03435e751af59 Source-Hash: blake3:5907a9cc29a5d72bbd3eaf5b820cac5133c8724895664c64fa8eafc2227716af Schema-Version: v1 -->

Chunking

Use this when feeding documents into an LLM context window or a vector store. Xberg chunks two ways: inline during extraction (chunks land on each document's chunks field), or standalone via the chunk command for text you already have. Sizing is character-based by default, or token-based when a tokenizer model is supplied.

Inline during extraction

Turn on chunking with --chunk and the chunks appear on the structured result under chunks:

# 1000-char chunks, 200-char overlap (defaults when --chunk is on)
xberg extract report.pdf --chunk --format json | jq '.chunks | length'

# Explicit size + overlap
xberg extract report.pdf --chunk --chunk-size 1500 --chunk-overlap 300 --format json

Overlap must be smaller than chunk size — the CLI rejects --chunk-overlap >= --chunk-size. When you set only --chunk-overlap against an existing config, an overlap that exceeds the size is clamped to chunk_size / 4.

Standalone chunk command

Chunk text you already have, from --text or stdin. Output defaults to JSON:

# From a flag
xberg chunk --text "long document text ..." --chunk-size 800 --chunk-overlap 100

# From stdin (pipe extracted content straight in)
xberg extract notes.md | xberg chunk --chunk-size 500 --format json

JSON output carries chunks (array of strings), chunk_count, the resolved config (max_characters, overlap, chunker_type), and input_size_bytes. Use --format text for a human-readable dump with --- chunk N --- separators.

Note: in the JSON output, chunker_type is rendered capitalized ("Text", "Markdown", "Yaml", "Semantic") because it is emitted via Rust's Debug formatting, whereas the --chunker-type input flag is lowercase (text, markdown, yaml, semantic). Lowercase the value before comparing if you parse it back.

Chunker types

--chunker-type selects the splitting strategy (standalone chunk command):

TypeBehavior
textDefault. Plain character-window splitting with overlap.
markdownMarkdown-aware — splits on structure (headings, blocks) where possible.
yamlYAML-aware splitting for structured config/data documents.
semanticTopic-boundary splitting driven by --topic-threshold (0.0–1.0, default 0.75).
# Markdown-aware chunking keeps headings and blocks intact
xberg chunk --text "$(cat README.md)" --chunker-type markdown

# Semantic chunking — lower threshold = more, smaller topic chunks
xberg chunk --text "$(cat transcript.txt)" --chunker-type semantic --topic-threshold 0.6

Token-based sizing

By default --chunk-size counts characters. To size chunks by tokens for a specific model, pass --chunking-tokenizer with a HuggingFace tokenizer id. On the extract command this implicitly enables chunking. Requires the chunking-tokenizers feature (present in the default CLI build).

# Size chunks by GPT-4o tokens during extraction
xberg extract report.pdf --chunking-tokenizer Xenova/gpt-4o --format json

# Or on the standalone command
xberg chunk --text "$(cat doc.txt)" --chunking-tokenizer Xenova/gpt-4o --chunk-size 512

With a tokenizer set, --chunk-size is interpreted in tokens, not characters.

Config file alternative

Field names in config files are snake_case under [chunking]:

[chunking]
max_characters = 1000
overlap = 200
chunker_type = "markdown"
xberg extract report.pdf --config xberg.toml --format json

CLI flags map to config fields as --chunk-sizemax_characters and --chunk-overlapoverlap. In config files use the snake_case names.

Programmatic access

From Python, enable chunking on the config and read the chunks off the document in the result envelope (result.results[0].chunks):

from xberg import ExtractInput, extract, ExtractionConfig, ChunkingConfig

config = ExtractionConfig(
    chunking=ChunkingConfig(max_characters=1000, overlap=200),
)
result = await extract(ExtractInput(uri="report.pdf"), config)
for chunk in result.results[0].chunks or []:
    print(len(chunk.content))

The public Python ChunkingConfig (a dataclass) uses constructor kwargs max_characters / overlap; the Rust core struct fields are also max_characters / overlap. TOML/JSON config keys are max_chars / max_overlap (with max_characters / overlap accepted as serde aliases), and dict-form config passed to ExtractionConfig likewise accepts the max_chars / max_overlap aliases; Node's ChunkingConfig interface uses maxCharacters / overlap. See references/python-api.md and references/rust-api.md in the sibling xberg skill.

Picking parameters

  • RAG / vector store — 500–1000 chars (or 256–512 tokens) with 10–20% overlap. Use markdown chunking for docs to keep sections whole.
  • LLM summarization — larger chunks (1500–4000 chars) with small overlap; size by tokens to stay under the model window.
  • Topic segmentationsemantic chunker; tune --topic-threshold down for finer splits, up for coarser ones.

Common pitfalls

  • Overlap ≥ size — rejected on extract; clamped to size / 4 when only overlap is changed against an existing config.
  • Tokenizer without the feature--chunking-tokenizer errors if the CLI was built without chunking-tokenizers. The default build includes it.
  • Empty input — the standalone chunk command bails on empty text; provide --text or pipe non-empty stdin.

See references/configuration.md for the full [chunking] schema and references/cli-reference.md for every chunk flag.

Frequently asked questions about Chunking

Similar skills