Skip to content

fix: Refactor RapidOcrModel to support all PP-OCR languages via version/backbone resolution - #3863

Open
nikos-livathinos wants to merge 9 commits into
mainfrom
nli/fix_ocr_defects
Open

fix: Refactor RapidOcrModel to support all PP-OCR languages via version/backbone resolution#3863
nikos-livathinos wants to merge 9 commits into
mainfrom
nli/fix_ocr_defects

Conversation

@nikos-livathinos

@nikos-livathinos nikos-livathinos commented Jul 24, 2026

Copy link
Copy Markdown
Member

Reworks how RapidOcrModel maps a user's requested language and backend onto concrete PP-OCR checkpoints, so Docling can serve every language RapidOCR supports instead of just chinese/english.

Previously the model shipped hand-maintained per-language, per-backend model-path tables that were hard to extend and effectively capped support at a couple of languages. This PR replaces them with a resolver that picks the right PP-OCR version and recognizer for a given (lang, backend) pair and fetches assets on demand.

Resolution procedure:

  1. Get the user's input for the language and the rapidocr backend (or the default values).
  2. Use RapidOCR/python/rapidocr/utils/model_resolver.py to check if the language is supported in PPOCRv6:
    a. First pass the input language through the COMMON_LANG_ALIASES.get(input_lang, input_lang)
    b. Check if the output of a exists in PP_OCRV6_LANGS
    • If yes download the PPOCR-v6 checkpoints. Return.
  3. Else if the backend is torch:
    a. If the input language is in: arabic, cyrillic, devanagari, ka, korean, latin, ta, te
    download the PPOCR-v4 checkpoints. Return.
    b. Else raise exception that the asked language is not supported by that backbone
  4. Else:
    a. If the language input is any of: arabic, ch, cyrillic, devanagari, el, en, eslav, korean, latin, ta, te, th
    download the PPOCR-v5 checkpoints. Return.
    b. Else raise exception that the asked language is not supported by that backbone

RapidOCR model artifacts download:

  1. If the user has NOT provided artifacts_path the downloading is fully delegated to RapidOCR lib:
    • This allows to use the artifacts bundled in the python package.
  2. Otherwise RapidOcrModel implementation downloads the artifacts:
    • The actual URL is still provided by RapidOCR.InferSession
    • Docling's code decides the saving path and filename.

In case the user has provided custom paths for each individual model (det/rec/cls), they are used instead.

Checklist:

  • Documentation has been updated, if necessary.
  • Examples have been added, if necessary.
  • Tests have been added, if necessary.

…te OCR models

Signed-off-by: Nikos Livathinos <nli@zurich.ibm.com>
@nikos-livathinos nikos-livathinos self-assigned this Jul 24, 2026
@nikos-livathinos
nikos-livathinos marked this pull request as draft July 24, 2026 08:38
@github-actions

Copy link
Copy Markdown
Contributor

DCO Check Passed

Thanks @nikos-livathinos, all your commits are properly signed off. 🎉

@nikos-livathinos
nikos-livathinos requested a review from cau-git July 24, 2026 08:38
@mergify

mergify Bot commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

Merge Protections

🟢 Merge protection satisfied — ready to merge.

Show 1 satisfied protection

🟢 Enforce conventional commit

Make sure that we follow https://www.conventionalcommits.org/en/v1.0.0/

  • title ~= ^(fix|feat|docs|style|refactor|perf|test|build|ci|chore|revert)(?:\(.+\))?(!)?:

@codecov

codecov Bot commented Jul 24, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 98.24561% with 2 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
docling/models/stages/ocr/rapid_ocr_model.py 98.21% 2 Missing ⚠️

📢 Thoughts on this report? Let us know!

Comment thread docling/models/stages/ocr/auto_ocr_model.py Outdated
…the model supports. This changes

the way how the user's input for the language/backbone resolves to which PPOCR checkpoints should be used.
Improve the tests

Signed-off-by: Nikos Livathinos <nli@zurich.ibm.com>
Signed-off-by: Nikos Livathinos <nli@zurich.ibm.com>
@nikos-livathinos nikos-livathinos changed the title fix: Correct defects in the OCR models fix: Correct defects in RapidOCR Jul 27, 2026
@nikos-livathinos nikos-livathinos changed the title fix: Correct defects in RapidOCR fix: Refactor RapidOcrModel to support all PP-OCR languages via version/backbone resolution Jul 27, 2026
…nly when the artifacts_path is

set. Otherwise delegate the downloading and local caching to the RapidOCR library.
This way the package bundled model artifacts can be also used.

Signed-off-by: Nikos Livathinos <nli@zurich.ibm.com>
Signed-off-by: Nikos Livathinos <nli@zurich.ibm.com>
@nikos-livathinos
nikos-livathinos marked this pull request as ready for review July 27, 2026 14:55
@nikos-livathinos
nikos-livathinos marked this pull request as draft July 27, 2026 14:55
Signed-off-by: Nikos Livathinos <nli@zurich.ibm.com>
Signed-off-by: Nikos Livathinos <nli@zurich.ibm.com>
@nikos-livathinos
nikos-livathinos marked this pull request as ready for review July 28, 2026 15:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants