{"data":{"slug":"github-xberg-io-xberg-ai-rulez-skills-extraction-pipeline-patterns-7abae98579a6","title":"Extraction Pipeline Patterns","summary":"Orchestrate document extraction with cache, fallback, and concurrency strategies.","url":"https:\/\/skillshunter.net\/skills\/github-xberg-io-xberg-ai-rulez-skills-extraction-pipeline-patterns-7abae98579a6","json_url":"https:\/\/skillshunter.net\/api\/public\/v1\/skills\/github-xberg-io-xberg-ai-rulez-skills-extraction-pipeline-patterns-7abae98579a6","markdown_url":"https:\/\/skillshunter.net\/skills\/github-xberg-io-xberg-ai-rulez-skills-extraction-pipeline-patterns-7abae98579a6.md","download_url":"https:\/\/skillshunter.net\/skills\/github-xberg-io-xberg-ai-rulez-skills-extraction-pipeline-patterns-7abae98579a6\/download","category":{"slug":"software-development","name":"Software & Development"},"editor_note":"The skill focuses on orchestrating document extraction with cache, fallback, and concurrency strategies. It includes format detection, extractor routing, and post-processing through the `FORMATS` registry. The skill supports handling password-protected PDFs, OCR fallback, and nested archives. It also includes cache and concurrency strategies based on build fingerprint and configuration.","instructions":"---\ntype: Playbook\ntitle: Extraction Pipeline Patterns\ndescription: \"Change extraction orchestration: cache, fallback, processing and concurrency.\"\npaths:\n  - \"crates\/xberg\/src\/core\/**\"\n  - \"crates\/xberg\/src\/extraction\/**\"\n  - \"crates\/xberg\/src\/extractors\/**\"\n  - \"crates\/xberg\/src\/plugins\/**\"\nx-ai-rulez:\n  kind: skill\n  id: extraction-pipeline-patterns\n  metadata:\n    priority: critical\n    name: extraction-pipeline-patterns\n---\n\n# Extraction Pipeline Patterns\n\n**Format detection \u2192 extractor routing \u2192 post-processing over the `FORMATS` registry**\n\nThe full-registry counts are verified against published claims by\n`scripts\/sync_supported_counts.py verify`. Runtime `SUPPORTED_FORMAT_COUNT` and\n`SUPPORTED_EXTENSION_COUNT` values are derived from the full static `FORMATS` registry.\n\n## Layout\n\n- `crates\/xberg\/src\/core\/pipeline\/` \u2014 orchestration (`mod.rs`, `cache.rs`, `execution.rs`,\n  `features.rs`, `format.rs`, `initialization.rs`, `page_markers.rs`)\n- `crates\/xberg\/src\/core\/mime.rs`, `core\/formats.rs` \u2014 detection and the `FORMATS` registry\n- `crates\/xberg\/src\/extractors\/` \u2014 one module per format, each implementing\n  `InternalDocumentExtractor`\n- `crates\/xberg\/src\/extraction\/` \u2014 shared parsing\/rendering helpers used by those extractors\n- `crates\/xberg\/src\/core\/config\/`, `core\/config_validation\/` \u2014 both directories, not files\n\n## Flow\n\n1. **Detect** \u2014 MIME from extension via `EXT_TO_MIME`, or from bytes via\n   `detect_mime_type_from_bytes`; validate against `SUPPORTED_MIME_TYPES`.\n2. **Route** \u2014 registry returns the highest-`priority()` extractor registered for that MIME.\n3. **Extract** \u2014 the extractor produces an `InternalDocument`.\n4. **Post-process** \u2014 `core::pipeline::run_pipeline(doc, config)` (async) or\n   `run_pipeline_sync` (WASM) runs validators, quality processing, chunking and hooks, and\n   returns `ExtractedDocument`. Every extraction path goes through it.\n\n## Extractor modules\n\n- Office: DOCX, PPTX, PPT, DOC, XLSX\/XLS, ODT, ODP, iWork, HWP\/HWPX, and WordPerfect under\n  `extractors\/{docx,pptx,ppt,doc,excel,odt,odp,hwp,hwpx,wordperfect}.rs` and `extractors\/iwork\/`.\n- Markup: Markdown, text, RST, Org, RTF, AsciiDoc, Typst, and Djot under\n  `extractors\/{markdown,text,rst,orgmode,asciidoc,typst}.rs` and `extractors\/{rtf,djot_format}\/`.\n- Academic: LaTeX, BibTeX, JATS, Jupyter, DocBook, EPUB, and FictionBook under\n  `extractors\/{bibtex,jupyter,docbook,fictionbook}.rs` and `extractors\/{latex,jats,epub}\/`.\n- PDF: text, encrypted-document, and OCR-fallback handling under `extractors\/pdf\/`.\n- Images: PNG, JPEG, TIFF, WebP, HEIC, SVG, and QR under `extractors\/` and `extraction\/`.\n- Web: HTML, XHTML, XML, and MDX under `extractors\/` and `extraction\/html\/`.\n- Email: EML, MSG, and PST under `extractors\/` and `extraction\/email\/`.\n- Archives: ZIP, TAR, GZIP, and 7z under `extractors\/archive.rs` and `extraction\/archive\/`.\n- Structured: JSON, GeoJSON, YAML, TOML, CSV, DBF, SQLite, and GeoPackage under `extractors\/`.\n\n## Fallback strategies\n\n- **Password-protected PDFs** \u2014 try the configured password, then the secondary list; on\n  failure report `is_encrypted` in metadata rather than erroring out.\n- **OCR fallback** \u2014 a PDF page with no extractable text routes to the OCR pipeline;\n  `config.force_ocr` and `config.force_ocr_pages` force it.\n- **Nested archives** \u2014 recursive with a depth limit from `SecurityLimits`.\n- **Corrupted input** \u2014 emit what parsed and attach the error location; never panic.\n\nThe cross-extractor fallback chain runs only for `UnsupportedFormat` and `Plugin` errors as\ndefined by `is_extractor_fallback_eligible`. Parsing, IO, OCR, and validation errors abort the\nchain. A successful fallback records an `extractor-fallback` processing warning.\n\n## Cache and concurrency\n\n- Extraction keys are `<cache_version_tag>-<content_hash>-<config_hash>`, never path-based.\n  The tag hashes `CARGO_PKG_VERSION`, `CACHE_SCHEMA_VERSION`, `env!(\"XBERG_BUILD_ID\")` and the\n  debug\/release bit (`cache\/version.rs`); `XBERG_BUILD_ID` is the commit SHA plus a hash of any\n  uncommitted diff (`build.rs`), so it IS a build fingerprint.\n- Two builds from different commits therefore get different entries with no schema bump needed.\n  The exception is a build that cannot reach git metadata and gets `XBERG_BUILD_ID = \"\"` -- a\n  crates.io\/docs.rs tarball (safe: immutable source per version) or a Docker build (`.dockerignore`\n  excludes `**\/.git\/`, and nothing passes the `--build-arg` escape hatch). Bump\n  `CACHE_SCHEMA_VERSION` when behavior can change and those builds must not collide. For A\/B or\n  revert checks, disable the cache or export distinct `XBERG_BUILD_ID` values per arm, so the\n  experiment cannot replay the control.\n- Configuration that affects output belongs in the config hash. Check the cache before\n  extraction so a hit skips processing.\n- Default batch concurrency uses host CPU count capped by any detected Linux cgroup quota via\n  `core\/config\/concurrency.rs::resolve_thread_budget`.\n- `core\/io.rs::read_file_async` currently reads the whole file with `tokio::fs::read`; there\n  is no `AsyncRead` extraction surface. Treat streaming as an open gap.\n- Cache hit and miss OTel counters exist, but no hit-rate target is computed or enforced.\n\n## Plugin integration\n\n`crates\/xberg\/src\/plugins\/`. Registry selection is by **`priority()`, highest wins** \u2014 not by\nregistration order. Register above 50 to override a built-in. See\n`plugin-architecture-patterns`.\n\n## Features\n\nAll features live in `crates\/xberg\/Cargo.toml`; there is no `FEATURE_MATRIX.md`.\n\n| Group | Features |\n| --- | --- |\n| OCR | `ocr`, `ocr-wasm`, `paddle-ocr`, `paddle-ocr-tract`, `sceptre-ocr`, `candle-vlm-ocr` |\n| Formats | `pdf`, `office`, `excel`, `html`, `xml`, `email`, `archives`, and format-specific flags |\n| AI\/ML | `embeddings`, `static-embeddings`, layout, keywords, language detection, and NER flags |\n| Server | `api` (Axum), `mcp`, `otel`, `prometheus`, `tokio-runtime` |\n| Aggregates | `formats`, `analysis`, `services`, `full`, and platform target groups |\n\nBindings are separate crates, not features of `crates\/xberg`. The one mutually-exclusive pair\nis `ort-bundled` \/ `ort-dynamic`. WASM excludes ORT-backed `embeddings`, but **does** carry\n`ocr-wasm`, `keywords` and `static-embeddings`. Full detail in `feature-flag-conventions`.\n\n## Critical Rules\n\n- **Detect before routing** \u2014 never dispatch on a caller-supplied extension alone.\n- **Apply `SecurityLimits` to user content** \u2014 archive size, compression ratio, file count, nesting depth.\n\n## Verification\n\nTest the changed format categories and both success and failure paths. No coverage percentage\nis an enforced contract. The format headline test is the enforced count; update its constants\nand listed copy together with `FORMATS`. Use `benchmark-workflow` for performance or quality\nclaims and `test-corpus` for bucket-backed fixtures.\n\n## Related Skills\n\n- **mime-detection-routing** \u2014 the `FORMATS` registry and how to add a format\n- **plugin-architecture-patterns** \u2014 which trait an extractor actually implements\n- **format-specific-extraction** \u2014 per-format workflows and helpers\n- **chunking-embeddings** \u2014 post-extraction text splitting\n","use_cases":["Extract content from a DOCX file with OCR fallback","Process multiple documents concurrently using cache","Handle password-protected PDFs with configured password"],"limitations":["OCR fallback requires configured force_ocr settings","Cache keys are version-dependent and may change with build updates","Nested archives are limited by SecurityLimits depth"],"compatibility":[],"setup_tip":null,"sample_input":null,"sample_output":null,"source_url":"https:\/\/github.com\/xberg-io\/xberg\/blob\/95bf61a74390a3ecccaf6356ae874d0a8b26aa9a\/.ai-rulez\/skills\/extraction-pipeline-patterns\/SKILL.md","source_commit":"95bf61a74390a3ecccaf6356ae874d0a8b26aa9a","license":null,"version":null,"listing_approved_at":"2026-11-15","created_at":"2026-11-14T14:02:39.000000Z","updated_at":"2026-11-15T16:39:17.000000Z","seo_title":"Extraction Pipeline Patterns for Document Processing","seo_description":"Optimize document extraction with cache, fallback, and concurrency strategies for efficient processing.","seo_keywords":["document extraction pipeline","cache and concurrency strategies","extractor routing and fallback","format detection and registry","OCR and encrypted document handling"]}}