本文へスキップ
Skillpedia
分析とスプレッドシート9.5k · #12269

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がスキルを読んで指示に従います。

貼り付け用メッセージ

このスキルを使って手伝ってください:https://github.com/xberg-io/xberg/blob/main/plugin/.ai-rulez/skills/xberg-chunking/SKILL.md このリンクのSKILL.mdファイルを読んで、私の作業でその指示に従ってください。
こういうスキルを、AIが自分で見つけてくれたら?無料のSkillpedia MCPをインストール。1行で、作業の前に15,000+のスキルから探してくれます。1分でインストール →

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_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
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_characters and --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 kwargs max_characters / overlap; the Rust core struct fields are also max_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

このスキルは役に立ちますか?

0

ログイン して投票しましょう。

コメント

  • …

このリポジトリの他のスキル

似ているスキル