xberg-chunking
Skill này làm gì
Skill này giải thích cách cắt văn bản dài thành các đoạn vừa với cửa sổ ngữ cảnh của một model AI hoặc cơ sở dữ liệu tìm kiếm. Nó dành cho người xây dựng công cụ tìm kiếm AI hoặc công cụ hỏi đáp tài liệu.
Khi nào nên dùng
- ✓Khi bạn cần đưa một tài liệu dài vào một công cụ AI có giới hạn kích thước.
- ✓Khi bạn đang xây một chỉ mục tìm kiếm hoặc hệ thống RAG từ tài liệu.
- ✓Khi bạn đã có văn bản và muốn chia nó thành các đoạn có kích thước đặt sẵn.
Liên kết skill
https://github.com/xberg-io/xberg/blob/main/plugin/.ai-rulez/skills/xberg-chunking/SKILL.mdSao chép rồi dán vào AI của bạn (Claude, ChatGPT hoặc Cursor) và nhờ nó làm theo hướng dẫn.
Cách dùng
Cách dễ nhất: sao chép tin nhắn và dán vào AI của bạn. AI sẽ đọc skill và làm theo hướng dẫn.
Tin nhắn có sẵn để dán
Dành cho Claude Code, Codex hoặc Cursor: chạy lệnh trong thư mục dự án của bạn và skill sẽ được cài đặt.
Tải tệp SKILL.md về và thả vào thư mục skill của agent.
Ví dụ cách nhờ AI
“Chia báo cáo 80 trang này thành các đoạn khoảng 1000 ký tự, có một chút chồng lấp, để tôi nạp vào công cụ tìm kiếm AI của mình.”
5 skill mới mỗi tuần. Đọc chỉ 1 phút.
Cách hoạt động
Agent hoặc bật chia đoạn trong lúc trích xuất, hoặc dùng lệnh chunk riêng trên văn bản bạn đã có. Nó đặt kích thước đoạn và phần chồng lấp, rồi kiểm tra phần chồng lấp nhỏ hơn kích thước đoạn.
Nội dung kỹ thuật (SKILL.md gốc)
Lấy nguyên văn từ GitHub, do tác giả viết bằng tiếng Anh.
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
Câu hỏi thường gặp
Phần chồng lấp dùng để làm gì?
Phần chồng lấp lặp lại một ít văn bản giữa các đoạn liền kề, để một câu bị cắt ở ranh giới vẫn xuất hiện nguyên vẹn trong một trong các đoạn.
Có thể đo đoạn theo token không?
Có, khi có cung cấp một model tokenizer. Nếu không, kích thước được đếm theo ký tự.
Nếu phần chồng lấp quá lớn thì sao?
Lệnh sẽ từ chối phần chồng lấp bằng hoặc lớn hơn kích thước đoạn.
Chi tiết
Mô tả gốc của tác giả
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
Độ phổ biến
- Sao GitHub
- 9.5k
- Vị trí xếp hạng
- #12269
- Giấy phép
- MIT
- Cập nhật
- 2/11/2026
Bình luận
- …
Thêm skill từ kho mã này
xberg-batch-extraction
9.5kGiúp agent của bạn xử lý nhiều tài liệu một lượt với Xberg, dùng chung tùy chọn, giới hạn việc song song và không để một file lỗi làm dừng cả lượt.
xberg-extracting-keywords
9.5kGiúp agent của bạn lấy các từ khóa chính hoặc cụm từ khóa từ tài liệu và nhận diện ngôn ngữ của tài liệu, bằng các cài đặt từ khóa của Xberg.
xberg-extracting-tables
9.5kGiúp agent của bạn lấy bảng từ PDF, bảng tính và hình ảnh, giữ nguyên hàng và cột dưới dạng markdown hoặc dữ liệu có cấu trúc.
xberg-extracting-with-ocr
9.5kGiúp agent của bạn đọc văn bản từ PDF quét, ảnh chụp và hình ảnh không có lớp văn bản, bằng OCR với các gói ngôn ngữ tùy chọn.
Skill tương tự
gitcrawl
394kCho phép agent của bạn tìm trong kho lưu trữ issue và pull request GitHub, gom các mục trùng lặp và kiểm tra trạng thái hiện tại trên GitHub.
slacrawl
394kCho phép agent của bạn tìm và đếm tin nhắn trong kho lưu trữ Slack cục bộ, kiểm tra kho đó mới đến mức nào và làm mới khi cần.
goplaces
394kGiúp agent của bạn tìm địa điểm, lấy chi tiết và đánh giá, và xác định tên địa điểm bằng Google Places, với đầu ra JSON cho script.