跳到主要内容
知仓学习社ZHICANG

chunking

Use when splitting extracted text into chunks for LLM context windows or RAG ingestion. Covers chunk size, overlap, markdown/yaml/semantic chunkers,…

不碰外部(只输出文字)无严重或高危命中hashgraph-online/awesome-codex-plugins

它会碰到什么

扫了多少1 个文本文件,6 KB
它会碰到什么不碰外部(只输出文字)
命中总数0 处
命中统计严重 0 · 高 0 · 中 0 · 低 0

这一栏是扫描器报的事实,不是结论。命中多不等于有毒(安全工具、规则库、示例脚本本来就会包含危险写法),命中少也不等于干净。它和你手上的凭据、文件、网络有什么关系,需要你自己看。

技能内容

Chunking

Use this when feeding documents into an LLM context window or a vector

store. Kreuzberg chunks two ways: inline during extraction (chunks land on

result.chunks), 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)
kreuzberg extract report.pdf --chunk --format json | jq '.chunks | length'

# Explicit size + overlap
kreuzberg 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
kreuzberg chunk --text "long document text ..." --chunk-size 800 --chunk-overlap 100

# From stdin (pipe extracted content straight in)
kreuzberg extract notes.md | kreuzberg 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):

| Type | Behavior |

| ---------- | ------------------------------------------------------------------- |

| text | Default. Plain character-window splitting with overlap. |

| markdown | Markdown-aware — splits on structure (headings, blocks) where possible. |

| yaml | YAML-aware splitting for structured config/data documents. |

| semantic | Topic-boundary splitting driven by --topic-threshold (0.0–1.0, default 0.75). |

# Markdown-aware chunking keeps headings and blocks intact
kreuzberg chunk --text "$(cat README.md)" --chunker-type markdown

# Semantic chunking — lower threshold = more, smaller topic chunks
kreuzberg 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
kreuzberg extract report.pdf --chunking-tokenizer Xenova/gpt-4o --format json

# Or on the standalone command
kreuzberg 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"
kreuzberg extract report.pdf --config kreuzberg.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 result.chunks:

from kreuzberg import extract_file_sync, ExtractionConfig, ChunkingConfig

config = ExtractionConfig(
    chunking=ChunkingConfig(max_chars=1000, max_overlap=200),
)
result = extract_file_sync("report.pdf", config=config)
for chunk in result.chunks:
    print(len(chunk))

> Python ChunkingConfig uses max_chars / max_overlap. Rust uses

> max_characters / overlap. See references/python-api.md and

> references/rust-api.md in the sibling kreuzberg 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.

想直接用这个技能?

本站把开放许可(MIT / Apache 等)的技能按仓库打包整理到网盘,点一下转存到你自己的网盘,不用一个个从 GitHub 拉。许可未声明的技能只给原始仓库链接,不打包。

它属于哪个仓库

星标★ 1,027
本站分层T1
该仓技能数1910
原文件路径plugins/kreuzberg-dev/plugins/plugins/kreuzberg/skills/chunking/SKILL.md

同一个仓库里的其他技能

看这个仓库的全部 1910 个技能

同名技能的其他版本

有 2 个不同仓库或目录里都有叫 chunking 的技能。它们内容并不相同,别混用: