xberg-batch-extraction
它能做什么
这项技能说明如何在一次操作中对一个文件夹或文件列表进行文档内容提取。适合有大量文档、希望得到一份结果、并把每个文件的错误单独列出的人。
适用场景
- ✓当你有一个包含 PDF 或 Word 文件的文件夹,需要一起处理时。
- ✓当你希望对每个文件应用同一组提取选项时。
- ✓当部分文件可能失败,但你仍希望获得其余文件的结果时。
技能链接
https://github.com/xberg-io/xberg/blob/main/plugin/.ai-rulez/skills/xberg-batch-extraction/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“请在一次运行中提取我报告文件夹中每个 PDF 的文字,并告诉我哪些文件失败了。”
每周 5 个新技能,1 分钟读完。
工作原理
智能体会对你的文件列表运行批处理命令,应用共用设置,每次只处理有限数量的文件,然后返回成功的结果以及所有错误。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
Batch extraction
Use this when processing a directory or glob of documents in one pass.
xberg batch shares one extraction config across every file, runs
extractions concurrently, and returns a JSON envelope — failures on
individual files do not abort the run.
Basic usage
# Glob expands to many paths; results come back in a JSON envelope (default)
xberg batch *.pdf
# Mixed formats, markdown content for LLM ingestion
xberg batch docs/*.docx --content-format markdown
# Recurse with the shell, then extract
xberg batch $(find ./corpus -name '*.pdf')
batch defaults to --format json (vs --format text for single
extract). The envelope contains results, total_ms, per_file_ms and, when failures
occur, errors. Each results entry is a full extracted document. One input may produce
multiple documents, so do not pair results with inputs by position. per_file_ms is
aligned with inputs; inspect errors for per-input failures.
xberg batch reports/*.pdf \
| jq '.results[] | {chars: (.content | length), mime: .mime_type}'
Parallelism
--max-concurrent caps how many files extract at once. When omitted, the scheduler derives document concurrency from the total thread budget. Lower it on memory-constrained hosts or when OCR/ML
models are active, since each in-flight extraction holds its own buffers.
Layout-heavy batches are further limited (1 concurrent extraction for
all-PDF-layout batches, 2 for mixed layout):
# Cap at 4 concurrent extractions
xberg batch scans/*.pdf --ocr true --max-concurrent 4
--max-threads additionally caps total internal threads (Rayon, ONNX
intra-op, the batch semaphore) for tightly constrained environments:
xberg batch *.pdf --max-concurrent 2 --max-threads 4
Per-file config overrides
A single shared config does not always fit. --file-configs points at a
JSON file mapping each path to its own override object, merged on top of
the shared config for that file only:
{
"scan.pdf": { "force_ocr": true },
"report.pdf": { "output_format": "markdown" },
"data.xlsx": { "output_format": "json" }
}
xberg batch scan.pdf report.pdf data.xlsx --file-configs overrides.json
Keys are file paths (matching the paths passed on the command line); values are per-file extraction config objects in snake_case, the same shape as a config file.
Output layout
For text/toon output with image extraction, --output-dir controls where
referenced image files (e.g. image_0.png) are written; the directory
must already exist. JSON output embeds image bytes inline and ignores
--output-dir.
mkdir -p out/images
xberg batch slides/*.pptx --extract-images true --output-dir out/images --format text
Error recovery
Batch extraction is fault-tolerant per file: one unreadable or corrupt
document does not stop the rest. Inspect results for partial content and
surfaced errors rather than relying on the process exit code alone. Pair
with --max-concurrent to avoid exhausting memory when a few large files
sit in a big batch.
Shared config
Every extract flag also applies to batch (OCR, chunking, layout,
content format, etc.) and is shared across all files unless a
--file-configs entry overrides it:
xberg batch invoices/*.pdf \
--layout --layout-table-model slanet_wireless \
--content-format markdown --max-concurrent 8
A config file works too and auto-discovers from the cwd upward:
output_format = "markdown"
[ocr]
backend = "tesseract"
language = "eng"
xberg batch corpus/*.pdf --config xberg.toml
Programmatic access
From Python, extract_batch takes a list of ExtractInputs and returns one
envelope whose results array holds a document per input:
from xberg import ExtractInput, extract_batch, ExtractionConfig
config = ExtractionConfig(output_format="markdown")
inputs = [ExtractInput(uri=p) for p in ["a.pdf", "b.docx", "c.xlsx"]]
output = await extract_batch(inputs, config)
for doc in output.results:
print(len(doc.content))
Per-input overrides go on ExtractInput.config (a FileExtractionConfig).
Node.js mirrors this with extractBatch; Rust uses extract_batch(inputs, &config).
See ../../references/python-api.md, ../../references/nodejs-api.md, and
../../references/rust-api.md.
MCP
When the xberg MCP server is registered, prefer the
extract_batch tool over shelling out — it takes an array of inpu
常见问题
一个有问题的文件会中断整个任务吗?
不会。单个文件的失败不会影响批处理中的其他文件。
我如何控制负载?
有一项设置可以限制同时处理的文件数量,这在内存较少的电脑上很有帮助。
不同的文件可以使用不同的设置吗?
可以。这项技能提到了 file-configs 选项,用于为单个文件设置覆盖配置。
详情
作者的原始描述
Use when extracting from many files at once with shared config, bounded parallelism, per-file overrides, and error recovery. Covers the `batch` command, `--file-configs`, `--max-concurrent`, and output layout.
repo: xberg-io/xberg
热度
- GitHub 星标
- 9.5k
- 排名
- #12268
- 许可证
- MIT
- 更新时间
- 2026/11/2
评论
- …
同一仓库的更多技能
xberg-chunking
9.5k帮你的智能体把长文档文字切分为较小的片段,用于 AI 提示或搜索索引,可设置大小并可选择重叠部分。
xberg-extracting-keywords
9.5k帮你的智能体使用 Xberg 的关键词设置,从文档中提取主要关键词或关键短语,并检测文档语言。
xberg-extracting-tables
9.5k帮你的智能体从 PDF、电子表格和图片中提取表格,并以 Markdown 或结构化数据的形式保持行和列的完整。
xberg-extracting-with-ocr
9.5k帮你的智能体使用 OCR 从没有文字层的扫描 PDF、照片和图片中读取文字,并可选择语言包。