Threaded docling-parse default (2.123.0, #3764) drops most of a scanned PDF's embedded OCR text layer
Bug
Since 2.123.0 made ThreadedDoclingParseDocumentBackend the default (#3764), converting a scanned PDF that carries an embedded OCR text layer can lose almost all of that layer. The serial DoclingParseDocumentBackend reads the same file correctly. Nothing warns or errors: the conversion succeeds, and the output is just a few percent of the document's words.
With all defaults except the backend, on the first 12 pages of two public Internet Archive scans (ABBYY OCR text layers):
| words in the text layer (PyMuPDF) | default (threaded) | DoclingParseDocumentBackend |
|
|---|---|---|---|
alcoholotherdrug00delg |
3153 | 179 | 3680 |
legalissuesforal00broo |
3580 | 309 | 3707 |
(The counts are words in export_to_markdown(). The serial column exceeds the text layer slightly because markdown adds table and heading tokens.)
How often, and how it bisects, from a larger run:
- In a sweep of 29 Internet Archive scans with OCR text layers, the threaded backend lost most of the text on 5, and serial on 1. The other 23 either agreed or differed only in segmentation.
- On a 1980s typewriter scan with a legacy OCR text layer, prose similarity to a hand-made ground truth drops from 0.896 (serial) to 0.648 (threaded). Whole clauses are replaced by noise, e.g.
from Chomsky grammars [28] because they require parallel rewriting of all the symbols in→from n hs t b lit exl s [ ei s. - The bisect puts it on docling core. Holding docling-core, docling-parse, docling-ibm-models and rapidocr constant and moving only
docling/docling-slim, the score steps exactly at 2.123.0. Passingbackend=DoclingParseDocumentBackendon 2.126.0 restores the pre-2.123 result. - Thread count is not the cause. Setting
parser_threads=1on the threaded backend still loses the text, so the problem is in the threaded code path itself.
This looks related to #4139 (OCR on rasterised regions degrades under the threaded backend) and may share a root cause. The symptom here is larger, though: the embedded text layer itself is lost, not just OCR characters. #4139 is waiting on a PDF; both files above are public.
Steps to reproduce
curl -L -o a.pdf https://archive.org/download/alcoholotherdrug00delg/alcoholotherdrug00delg.pdf
curl -L -o b.pdf https://archive.org/download/legalissuesforal00broo/legalissuesforal00broo.pdf
python repro.py a.pdf b.pdf# repro.py
import sys, fitz # PyMuPDF, only to count the words in the embedded text layer
from docling.backend.docling_parse_backend import DoclingParseDocumentBackend
from docling.datamodel.base_models import InputFormat
from docling.document_converter import DocumentConverter, PdfFormatOption
PAGES = (1, 12)
def words(backend, pdf):
opt = PdfFormatOption() if backend is None else PdfFormatOption(backend=backend)
doc = DocumentConverter(format_options={InputFormat.PDF: opt}).convert(
pdf, page_range=PAGES).document
return len(doc.export_to_markdown().split())
for pdf in sys.argv[1:]:
f = fitz.open(pdf)
layer = sum(len(f[i].get_text().split()) for i in range(PAGES[0] - 1, PAGES[1]))
print(pdf, "| text layer", layer,
"| default (threaded)", words(None, pdf),
"| DoclingParseDocumentBackend", words(DoclingParseDocumentBackend, pdf))Output:
a.pdf | text layer 3153 | default (threaded) 179 | DoclingParseDocumentBackend 3680
b.pdf | text layer 3580 | default (threaded) 309 | DoclingParseDocumentBackend 3707Workaround: pass backend=DoclingParseDocumentBackend explicitly.
Docling version
docling 2.126.0 (docling-slim 2.126.0, docling-core 2.95.0, docling-parse 7.18.0, docling-ibm-models 4.0.2, rapidocr 3.9.2)
Python version
Python 3.12.13, macOS arm64 (Darwin 25.5.0), CPU
Source: docling-project/docling