{"data":{"slug":"github-xberg-io-xberg-plugin-ai-rulez-skills-xberg-batch-extraction-b7dc2e851254","title":"Batch Extraction for Multi-File Processing","summary":"Process multiple files in one go with shared config, parallelism, and error recovery.","url":"https:\/\/skillshunter.net\/skills\/github-xberg-io-xberg-plugin-ai-rulez-skills-xberg-batch-extraction-b7dc2e851254","json_url":"https:\/\/skillshunter.net\/api\/public\/v1\/skills\/github-xberg-io-xberg-plugin-ai-rulez-skills-xberg-batch-extraction-b7dc2e851254","markdown_url":"https:\/\/skillshunter.net\/skills\/github-xberg-io-xberg-plugin-ai-rulez-skills-xberg-batch-extraction-b7dc2e851254.md","download_url":"https:\/\/skillshunter.net\/skills\/github-xberg-io-xberg-plugin-ai-rulez-skills-xberg-batch-extraction-b7dc2e851254\/download","category":{"slug":"software-development","name":"Software & Development"},"editor_note":"The batch extraction command requires a valid input directory or glob pattern. Ensure the output directory exists if using `--output-dir` for image extraction.","instructions":"---\ntype: Playbook\ntitle: Batch Extraction\ndescription: 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.\nx-ai-rulez:\n  kind: skill\n  id: xberg-batch-extraction\n  metadata:\n    name: xberg-batch-extraction\n---\n\n# Batch extraction\n\nUse this when processing a directory or glob of documents in one pass.\n`xberg batch` shares one extraction config across every file, runs\nextractions concurrently, and returns a JSON envelope \u2014 failures on\nindividual files do not abort the run.\n\n## Basic usage\n\n```bash\n# Glob expands to many paths; results come back in a JSON envelope (default)\nxberg batch *.pdf\n\n# Mixed formats, markdown content for LLM ingestion\nxberg batch docs\/*.docx --content-format markdown\n\n# Recurse with the shell, then extract\nxberg batch $(find .\/corpus -name '*.pdf')\n```\n\n`batch` defaults to `--format json` (vs `--format text` for single\n`extract`). The envelope contains `results`, `total_ms`, `per_file_ms` and, when failures\noccur, `errors`. Each `results` entry is a full extracted document. One input may produce\nmultiple documents, so do not pair results with inputs by position. `per_file_ms` is\naligned with inputs; inspect `errors` for per-input failures.\n\n```bash\nxberg batch reports\/*.pdf \\\n  | jq '.results[] | {chars: (.content | length), mime: .mime_type}'\n```\n\n## Parallelism\n\n`--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\nmodels are active, since each in-flight extraction holds its own buffers.\nLayout-heavy batches are further limited (1 concurrent extraction for\nall-PDF-layout batches, 2 for mixed layout):\n\n```bash\n# Cap at 4 concurrent extractions\nxberg batch scans\/*.pdf --ocr true --max-concurrent 4\n```\n\n`--max-threads` additionally caps *total* internal threads (Rayon, ONNX\nintra-op, the batch semaphore) for tightly constrained environments:\n\n```bash\nxberg batch *.pdf --max-concurrent 2 --max-threads 4\n```\n\n## Per-file config overrides\n\nA single shared config does not always fit. `--file-configs` points at a\nJSON file mapping each path to its own override object, merged on top of\nthe shared config for that file only:\n\n```json\n{\n  \"scan.pdf\": { \"force_ocr\": true },\n  \"report.pdf\": { \"output_format\": \"markdown\" },\n  \"data.xlsx\": { \"output_format\": \"json\" }\n}\n```\n\n```bash\nxberg batch scan.pdf report.pdf data.xlsx --file-configs overrides.json\n```\n\nKeys are file paths (matching the paths passed on the command line);\nvalues are per-file extraction config objects in snake_case, the same\nshape as a config file.\n\n## Output layout\n\nFor text\/toon output with image extraction, `--output-dir` controls where\nreferenced image files (e.g. `image_0.png`) are written; the directory\nmust already exist. JSON output embeds image bytes inline and ignores\n`--output-dir`.\n\n```bash\nmkdir -p out\/images\nxberg batch slides\/*.pptx --extract-images true --output-dir out\/images --format text\n```\n\n## Error recovery\n\nBatch extraction is fault-tolerant per file: one unreadable or corrupt\ndocument does not stop the rest. Inspect results for partial content and\nsurfaced errors rather than relying on the process exit code alone. Pair\nwith `--max-concurrent` to avoid exhausting memory when a few large files\nsit in a big batch.\n\n## Shared config\n\nEvery `extract` flag also applies to `batch` (OCR, chunking, layout,\ncontent format, etc.) and is shared across all files unless a\n`--file-configs` entry overrides it:\n\n```bash\nxberg batch invoices\/*.pdf \\\n  --layout --layout-table-model slanet_wireless \\\n  --content-format markdown --max-concurrent 8\n```\n\nA config file works too and auto-discovers from the cwd upward:\n\n```toml\noutput_format = \"markdown\"\n\n[ocr]\nbackend = \"tesseract\"\nlanguage = \"eng\"\n```\n\n```bash\nxberg batch corpus\/*.pdf --config xberg.toml\n```\n\n## Programmatic access\n\nFrom Python, `extract_batch` takes a list of `ExtractInput`s and returns one\nenvelope whose `results` array holds a document per input:\n\n```python\nfrom xberg import ExtractInput, extract_batch, ExtractionConfig\n\nconfig = ExtractionConfig(output_format=\"markdown\")\n\ninputs = [ExtractInput(uri=p) for p in [\"a.pdf\", \"b.docx\", \"c.xlsx\"]]\noutput = await extract_batch(inputs, config)\n\nfor doc in output.results:\n    print(len(doc.content))\n```\n\nPer-input overrides go on `ExtractInput.config` (a `FileExtractionConfig`).\nNode.js mirrors this with `extractBatch`; Rust uses `extract_batch(inputs, &config)`.\nSee `..\/..\/references\/python-api.md`, `..\/..\/references\/nodejs-api.md`, and\n`..\/..\/references\/rust-api.md`.\n\n## MCP\n\nWhen the `xberg` MCP server is registered, prefer the\n`extract_batch` tool over shelling out \u2014 it takes an array of input objects\nand a config object and returns structured results directly.\n\n## Common pitfalls\n\n- **Default format differs** \u2014 `batch` defaults to `--format json`,\n  `extract` to `--format text`. Set `--format` explicitly if a script\n  depends on one shape.\n- **`--output-dir` must exist** \u2014 the CLI does not create it.\n- **Memory blowups** \u2014 large batches with OCR\/layout active may need an explicit\n  `--max-concurrent` ceiling.\n- **`--file-configs` path keys** \u2014 must match the paths as passed on the\n  command line, not absolute-resolved variants.\n\nSee `..\/..\/references\/cli-reference.md` for the full `batch` flag set.\n","use_cases":["Extracting content from a directory of PDFs","Processing mixed document formats with custom output formats","Recovering from partial failures in large batches"],"limitations":[],"compatibility":[],"setup_tip":null,"sample_input":null,"sample_output":null,"source_url":"https:\/\/github.com\/xberg-io\/xberg\/blob\/ffbf7971796a126fc52f6bb8fb40418772071f61\/plugin\/.ai-rulez\/skills\/xberg-batch-extraction\/SKILL.md","source_commit":"ffbf7971796a126fc52f6bb8fb40418772071f61","license":null,"version":null,"listing_approved_at":"2026-11-16","created_at":"2026-11-15T13:56:14.000000Z","updated_at":"2026-11-16T05:16:54.000000Z","seo_title":"Batch Extraction for Multi-File Processing","seo_description":"Efficiently extract content from multiple files with shared configuration, parallel processing, and error handling.","seo_keywords":["batch extraction","multi-file processing","parallel document extraction","error recovery in batch","shared configuration extraction"]}}