Skip to content

fix: Docling parser extracts mathematical formulas - #16645

Merged
wangq8 merged 4 commits into
infiniflow:mainfrom
Sohaib9920:fix/docling-formula-extraction
Jul 6, 2026
Merged

wangq8 merged 4 commits into
infiniflow:mainfrom
Sohaib9920:fix/docling-formula-extraction

Conversation

@Sohaib9920

Copy link
Copy Markdown
Contributor

Before:

Screenshot from 2026-07-05 07-24-48

After:

Screenshot from 2026-07-05 08-24-56

After (DOCLING_FORMULA_ENRICHMENT="1"):

Screenshot from 2026-07-05 08-50-02

Fixes #16644

@dosubot dosubot Bot added size:S This PR changes 10-29 lines, ignoring generated files. 🐞 bug Something isn't working, pull request that fix bug. labels Jul 5, 2026
@coderabbitai

coderabbitai Bot commented Jul 5, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: c8bc1941-4afd-4fe0-8a9a-971c2a7340ba

📥 Commits

Reviewing files that changed from the base of the PR and between 91cbbe2 and 1f1a057.

📒 Files selected for processing (1)
  • deepdoc/parser/docling_parser.py
🚧 Files skipped from review as they are similar to previous changes (1)
  • deepdoc/parser/docling_parser.py

📝 Walkthrough

Walkthrough

Docling parser now conditionally imports pipeline-related classes, extracts formulas inline during document iteration, skips empty equation payloads, and enables optional LaTeX formula enrichment for local conversion via a new environment variable, documented in the PDF parser guide.

Changes

Docling formula handling

Layer / File(s) Summary
Defensive Docling imports
deepdoc/parser/docling_parser.py
PdfFormatOption, InputFormat, and PdfPipelineOptions are imported alongside DocumentConverter, defaulting to None if import fails.
Inline formula extraction and payload guard
deepdoc/parser/docling_parser.py
Formula items are yielded inline during the main doc.texts iteration, and empty equation payloads are now skipped like empty text payloads.
Formula enrichment pipeline and docs
deepdoc/parser/docling_parser.py, docs/guides/dataset/select_pdf_parser.md
Local PDF conversion builds PdfPipelineOptions with do_formula_enrichment controlled by DOCLING_FORMULA_ENRICHMENT, wiring DocumentConverter via format_options; docs describe the new environment variable and its 0/1 behavior.

Estimated code review effort: 2 (Simple) | ~15 minutes

Sequence Diagram(s)

sequenceDiagram
    participant ParsePdf as parse_pdf
    participant PipelineOptions as PdfPipelineOptions
    participant Converter as DocumentConverter
    participant DocItems as _iter_doc_items
    participant Sections as _transfer_to_sections

    ParsePdf->>PipelineOptions: set do_formula_enrichment from env var
    ParsePdf->>Converter: create with format_options(InputFormat.PDF, pipeline_options)
    Converter-->>ParsePdf: conv_res (parsed document)
    ParsePdf->>DocItems: iterate doc.texts
    DocItems->>DocItems: yield equation when label == "formula"
    DocItems-->>Sections: sections including equations
    Sections->>Sections: skip empty equation payloads
    Sections-->>ParsePdf: final sections
Loading

Poem

A formula hopped, once lost in the weeds,
Now caught inline where the parser reads.
Flip the switch, LaTeX takes flight,
Or keep it plain — either way, it's right.
Hop hop hooray, the equations are free! 🐇✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The PR description is on-topic but misses the required Summary section and background explanation from the template. Add a brief Summary section explaining the problem, the change, and any relevant context; screenshots alone are not enough.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly states the main change: Docling parser now extracts mathematical formulas.
Linked Issues check ✅ Passed The changes match issue #16644 by preserving formulas, supporting LaTeX enrichment, and falling back to original formula text.
Out of Scope Changes check ✅ Passed The documented code and docs changes stay focused on formula extraction and the new Docling enrichment setting.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@deepdoc/parser/docling_parser.py`:
- Around line 566-568: The new PDF pipeline setup in docling_parser should not
parse DOCLING_FORMULA_ENRICHMENT with int() because non-numeric values can crash
parsing; update the PdfPipelineOptions setup to use safe boolean/env parsing in
the same flow that builds DocumentConverter. Also add a self.logger message
around the pipeline_options / do_formula_enrichment decision so this new
conversion path is logged consistently with the rest of the parser.
- Around line 225-231: The formula handling in docling_parser’s label ==
"formula" branch is using plain text first, but the enriched LaTeX is available
in the enrichment payload. Update the logic in the formula extraction path to
read enriched_data["latex"] or "tex" before falling back to orig or text, while
keeping the existing bbox extraction and DoclingContentType.EQUATION yield
behavior unchanged.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: f34e9a80-8b57-46be-bca0-b1030381e252

📥 Commits

Reviewing files that changed from the base of the PR and between 0fcfb38 and 91cbbe2.

📒 Files selected for processing (2)
  • deepdoc/parser/docling_parser.py
  • docs/guides/dataset/select_pdf_parser.md

Comment thread deepdoc/parser/docling_parser.py Resolved
Comment thread deepdoc/parser/docling_parser.py Resolved
@dosubot dosubot Bot added size:M This PR changes 30-99 lines, ignoring generated files. and removed size:S This PR changes 10-29 lines, ignoring generated files. labels Jul 5, 2026
@wangq8 wangq8 added the ci Continue Integration label Jul 6, 2026
@codecov

codecov Bot commented Jul 6, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.16%. Comparing base (09eb9db) to head (5b83d2e).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #16645   +/-   ##
=======================================
  Coverage   93.16%   93.16%           
=======================================
  Files          10       10           
  Lines         717      717           
  Branches      118      118           
=======================================
  Hits          668      668           
  Misses         29       29           
  Partials       20       20           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@wangq8
wangq8 merged commit 534a3a7 into infiniflow:main Jul 6, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🐞 bug Something isn't working, pull request that fix bug. ci Continue Integration size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Docling PDF Parser Fails to Parse Mathematical Formulas

2 participants