xberg-chunking
O que ela faz
Esta skill explica como cortar textos longos em pedaços que caibam na janela de contexto de um modelo de IA ou em um banco de busca. É para quem cria ferramentas de busca com IA ou de perguntas sobre documentos.
Quando usar
- ✓Quando você precisa alimentar um documento longo em uma ferramenta de IA que tem limite de tamanho.
- ✓Quando está criando um índice de busca ou um sistema RAG a partir de documentos.
- ✓Quando já tem o texto e quer dividi-lo em pedaços de um tamanho definido.
Link da skill
https://github.com/xberg-io/xberg/blob/main/plugin/.ai-rulez/skills/xberg-chunking/SKILL.mdCopie e cole na sua IA (Claude, ChatGPT ou Cursor) pedindo para seguir as instruções.
Como usar
O jeito mais fácil: copie a mensagem e cole na sua IA. Ela lê a skill e segue as instruções.
Mensagem pronta para colar
Para Claude Code, Codex ou Cursor: rode na pasta do projeto e a skill fica instalada.
Baixe o SKILL.md e coloque na pasta de skills do seu agente.
Exemplo do que pedir para a IA
“Divida este relatório de 80 páginas em pedaços de cerca de 1000 caracteres, com uma pequena sobreposição, para eu carregar na minha busca com IA.”
5 skills novas por semana. 1 minuto de leitura.
Como funciona
O agente ativa a divisão durante a extração ou usa o comando de divisão separado sobre um texto que você já tem. Define o tamanho do pedaço e a sobreposição, e confere se a sobreposição é menor que o tamanho do pedaço.
Conteúdo técnico (SKILL.md original)
Texto original do autor, em inglês, direto do 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
Perguntas frequentes
Para que serve a sobreposição?
Ela repete um pouco de texto entre pedaços vizinhos, então uma frase cortada na fronteira aparece inteira em um deles.
Dá para medir os pedaços em tokens?
Sim, quando um modelo tokenizador é fornecido. Caso contrário, os tamanhos são contados em caracteres.
E se a sobreposição for grande demais?
O comando rejeita uma sobreposição igual ou maior que o tamanho do pedaço.
Detalhes
Descrição original do autor
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
Popularidade
- Estrelas no GitHub
- 9,5 mil
- Posição no ranking
- #12269
- Licença
- MIT
- Atualizada em
- 02/11/2026
Comentários
- …
Mais skills deste repositório
xberg-batch-extraction
9,5 milAjuda seu agente a processar muitos documentos de uma vez com o Xberg, usando opções compartilhadas e sem parar tudo por causa de um arquivo com erro.
xberg-extracting-keywords
9,5 milAjuda seu agente a extrair as principais palavras-chave ou expressões de um documento e a detectar o idioma dele, usando as configurações de palavras-chave do Xberg.
xberg-extracting-tables
9,5 milAjuda seu agente a extrair tabelas de PDFs, planilhas e imagens, mantendo linhas e colunas íntegras em markdown ou em dados estruturados.
xberg-extracting-with-ocr
9,5 milAjuda seu agente a ler texto de PDFs digitalizados, fotos e imagens sem camada de texto, usando OCR com pacotes de idioma opcionais.
Skills parecidas
gitcrawl
394 milPermite que seu agente pesquise um arquivo salvo de issues e pull requests do GitHub, agrupe os duplicados e verifique o status atual deles no GitHub.
slacrawl
394 milPermite que seu agente pesquise e conte mensagens em um arquivo local do Slack, verifique quão atualizado ele está e o atualize quando necessário.
goplaces
394 milAjuda seu agente a buscar lugares, obter detalhes e avaliações e identificar nomes de lugares usando o Google Places, com saída em JSON para scripts.