Hybrid PDF extraction: add DoclingTableRefiner (closes #16)#19
Merged
Conversation
Introduces a hybrid PDF-extraction path: in-tree (PyMuPDF + pdfplumber) parses by default, and DoclingTableRefiner refines table sections via TableFormer when a source URL is on an allowlist (CDC MMWR, two WHO sitrep paths) or when a heuristic flags an in-tree table as broken (sparse cells or over-segmented rows). Docling and its transitive deps are lazy-imported, so the feature flag (ExtractionConfig.enable_docling_refiner) gates all runtime cost — when off, no Docling import ever happens. The refiner is a per-process singleton; the converter loads on first use (~10-30s, ~1.5 GB RAM). Merge strategy: page-match Docling tables against in-tree table sections first; for unmatched Docling tables, insert at the right page position; for unmatched in-tree sections flagged broken by the heuristic, drop them. This handles cases like CDC MMWR where PyMuPDF hallucinates a 6x13 empty table on page 4 while Docling finds the real 17x2 table on page 3. Provenance: SectionContent and DocumentChunk now carry an `extractor` field set to 'pymupdf', 'pdfplumber', or 'docling'. Includes the docling_eval test suite (5 PDFs + 2 HTML sources, FINDINGS write-up, eval scripts for in-tree / Docling / hybrid runs and OCR cost analysis). Per-run output artifacts are gitignored. Validated end-to-end against all 5 PDFs: - WHO mpox sitrep: no refinement (trigger=NONE, 11x4 in-tree) - WHO cholera epi: Docling 21x8 replaces in-tree 23x20 (allowlist) - CDC MMWR measles: Docling 17x2 replaces in-tree 6x13 empties (allowlist + heuristic-confirmed broken in-tree section dropped) - Africa CDC weekly: refiner short-circuits on requires_ocr - ECDC CDTR: no refinement (tables present as charts, both stacks miss) Tests: 25 new unit tests cover trigger logic, heuristics, merge behaviour (replace / drop / insert), and the disabled-flag fast path. Full suite: 203 passing.
4 tasks
rapsoj
reviewed
May 18, 2026
Collaborator
rapsoj
left a comment
There was a problem hiding this comment.
Resolved conflict in config.py keeping both changes from branch and impersonate setting from main.
rapsoj
approved these changes
May 18, 2026
Collaborator
rapsoj
left a comment
There was a problem hiding this comment.
Resolved conflict in config.py keeping both changes from branch and impersonate setting from main.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
DoclingTableRefiner, a Docling-based post-pass that refines PDF table sections after in-tree parsing, with two triggers: a source-URL allowlist (CDC MMWR, two WHO sitrep paths) and a heuristic that flags sparse / over-segmented in-tree tables.ExtractionConfig.enable_docling_refiner) gate all Docling cost — when off, no Docling import ever happens. Per-process singleton in the pipeline; converter loads on first use (~10–30 s, ~1.5 GB RAM).SectionContentandDocumentChunkcarry anextractorfield (pymupdf/pdfplumber/docling).FINDINGS.md, eval scripts for in-tree / Docling / hybrid runs + OCR cost analysis). Per-run output artifacts are gitignored.Test plan
scripts/eval_hybrid_pdf.py) against the 5 PDFs indata/docling_eval/sources/:requires_ocrenable_docling_refiner=False,import bioscancast.extractiondoes not load Docling (verifieddoclingabsent fromsys.modules)Closes #16