xberg-chunking
できること
このスキルは、長いテキストをAIモデルの文脈の窓や検索データベースに収まるよう、塊に分ける方法を説明します。AI検索や文書の質問ツールを作る人向けです。
使う場面
- ✓サイズ上限のあるAIツールに、長い文書を入れる必要があるとき。
- ✓文書から検索インデックスやRAGのシステムを作っているとき。
- ✓すでに手元にあるテキストを、一定の大きさの塊に分けたいとき。
スキルのリンク
https://github.com/xberg-io/xberg/blob/main/plugin/.ai-rulez/skills/xberg-chunking/SKILL.mdコピーしてAI(Claude、ChatGPT、Cursor)に貼り付け、指示に従うよう頼んでください。
使い方
いちばん簡単な方法:メッセージをコピーしてAIに貼り付けるだけ。AIがスキルを読んで指示に従います。
貼り付け用メッセージ
Claude Code、Codex、Cursorの場合:プロジェクトのフォルダで実行するとスキルがインストールされます。
SKILL.mdをダウンロードして、エージェントのスキル用フォルダに入れてください。
AIへの頼み方の例
“この80ページのレポートを、約1000文字ずつ少し重なるように分割し、AI検索に読み込めるようにしてください。”
毎週5つの新しいスキル。1分で読めます。
仕組み
エージェントは、抽出の際にチャンク化を有効にするか、手元のテキストに対して別のチャンクコマンドを使います。塊の大きさと重なりを設定し、重なりが塊の大きさより小さいことを確認します。
技術的な内容(元のSKILL.md)
作者による元のテキスト(英語)をGitHubからそのまま表示しています。
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 '.result.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_typeis rendered capitalized ("Text","Markdown","Yaml","Semantic") because it is emitted via Rust's Debug formatting, whereas the--chunker-typeinput 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
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-size→max_charactersand--chunk-overlap→overlap. 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 kwargsmax_characters/overlap; the Rust core struct fields are alsomax_characters/overlap. TOML/JSON conf
よくある質問
重なりは何のためにありますか?
隣り合う塊の間で少しの文章を重ねることで、区切りの位置で途切れた文が、どちらかの塊に完全な形で残るようにするためです。
トークン数で塊の大きさを決められますか?
はい。トークナイザーのモデルが指定されていれば可能です。指定がなければ、文字数で数えます。
重なりが大きすぎるとどうなりますか?
塊の大きさと等しいか、それより大きい重なりは、コマンドが拒否します。
詳細
作者による元の説明
Use when splitting extracted text into chunks for LLM context windows or RAG ingestion. Covers chunk size, overlap, markdown/yaml/semantic chunkers, tokenizer-based sizing, and the standalone `chunk` command.
repo: xberg-io/xberg
人気
- GitHubのスター
- 9.5k
- ランキング
- #12269
- ライセンス
- MIT
- 更新日
- 2026/11/2
コメント
- …
このリポジトリの他のスキル
xberg-batch-extraction
9.5kエージェントがXbergで多数の文書を一括処理できるよう支援します。共通の設定を使い、同時処理数を制限し、失敗したファイルで全体が止まらないようにします。
xberg-extracting-keywords
9.5kエージェントが、Xbergのキーワード設定を使って、文書の主なキーワードやキーフレーズを抽出し、言語を判定できるよう支援します。
xberg-extracting-tables
9.5kエージェントが、PDF、表計算ファイル、画像から表を抽出できるよう支援します。行と列を崩さず、MarkdownまたはJSON形式の構造化データとして取り出します。
xberg-extracting-with-ocr
9.5kエージェントが、テキストレイヤーのないスキャンPDF、写真、画像からOCRで文字を読み取れるよう支援します。言語パックを指定することもできます。
似ているスキル
gitcrawl
394k保存されたGitHubのイシューとプルリクエストのアーカイブを検索し、重複をまとめ、GitHub上の現在の状態を確認するようエージェントを支援します。
slacrawl
394kローカルのSlackアーカイブ内のメッセージを検索して件数を数え、アーカイブの新しさを確認し、必要に応じて更新するようエージェントを支援します。
goplaces
394kGoogle Placesを使って、場所を検索し、詳細や口コミを取得し、場所の名前を解決するようエージェントを支援します。スクリプト用にJSON出力もできます。