xberg-chunking
Qué hace
Esta habilidad explica cómo trocear textos largos en fragmentos que caben en la ventana de contexto de un modelo de IA o en una base de datos de búsqueda. Está pensada para personas que construyen herramientas de búsqueda con IA o de preguntas sobre documentos.
Cuándo usarla
- ✓Cuando necesitas pasar un documento largo a una herramienta de IA que tiene un límite de tamaño.
- ✓Cuando estás creando un índice de búsqueda o un sistema RAG a partir de documentos.
- ✓Cuando ya tienes el texto y quieres dividirlo en fragmentos de un tamaño fijado.
Link de la skill
https://github.com/xberg-io/xberg/blob/main/plugin/.ai-rulez/skills/xberg-chunking/SKILL.mdCópialo y pégalo en tu IA (Claude, ChatGPT o Cursor) pidiéndole que siga las instrucciones.
Cómo usar
La forma más fácil: copia el mensaje y pégalo en tu IA. Ella lee la skill y sigue las instrucciones.
Mensaje listo para pegar
Para Claude Code, Codex o Cursor: ejecútalo en la carpeta del proyecto y la skill queda instalada.
Descarga el SKILL.md y ponlo en la carpeta de skills de tu agente.
Ejemplo de qué pedirle a la IA
“Divide este informe de 80 páginas en fragmentos de unos 1000 caracteres con un poco de solapamiento para cargarlo en mi buscador de IA.”
5 skills nuevas por semana. 1 minuto de lectura.
Cómo funciona
El agente activa el troceado durante la extracción o usa el comando de troceado independiente sobre un texto que ya tienes. Fija el tamaño del fragmento y el solapamiento, y comprueba que el solapamiento sea menor que el tamaño del fragmento.
Contenido técnico (SKILL.md original)
Texto original del autor, en inglés, directo de 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
Preguntas frecuentes
¿Para qué sirve el solapamiento?
Repite un poco de texto entre fragmentos vecinos, para que una frase cortada en el límite aparezca completa en uno de ellos.
¿Se pueden medir los fragmentos en tokens?
Sí, cuando se proporciona un modelo tokenizador. Si no, los tamaños se cuentan en caracteres.
¿Y si el solapamiento es demasiado grande?
El comando rechaza un solapamiento igual o mayor que el tamaño del fragmento.
Detalles
Descripción original del 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
Popularidad
- Estrellas en GitHub
- 9,5 mil
- Posición en el ranking
- #12269
- Licencia
- MIT
- Actualizada
- 2/11/2026
Comentarios
- …
Más skills de este repositorio
xberg-batch-extraction
9,5 milAyuda a tu agente a procesar muchos documentos a la vez con Xberg, compartiendo un único conjunto de opciones, limitando el trabajo en paralelo y evitando que los archivos con error detengan la ejecución.
xberg-extracting-keywords
9,5 milAyuda a tu agente a extraer las palabras clave o frases clave principales de un documento y a detectar su idioma, usando los ajustes de palabras clave de Xberg.
xberg-extracting-tables
9,5 milAyuda a tu agente a extraer tablas de PDF, hojas de cálculo e imágenes, manteniendo intactas las filas y columnas como Markdown o datos estructurados.
xberg-extracting-with-ocr
9,5 milAyuda a tu agente a leer texto de PDF escaneados, fotos e imágenes que no tienen capa de texto, usando OCR con paquetes de idiomas opcionales.
Skills parecidas
gitcrawl
394 milPermite que tu agente busque en un archivo guardado de incidencias y pull requests de GitHub, agrupe duplicados y revise su estado actual en GitHub.
slacrawl
394 milPermite que tu agente busque y cuente mensajes en un archivo local de Slack, revise qué tan reciente es y lo actualice cuando haga falta.
goplaces
394 milAyuda a tu agente a buscar lugares, obtener sus detalles y reseñas, y resolver nombres de lugares usando Google Places, con salida JSON para scripts.