Commit 4af4d0a
feat(docling): add do_ocr option (#6006)
# What does this PR do?
Adds `do_ocr` configuration option to the inline docling file processor,
allowing users to disable OCR for digital
PDFs with embedded text.
By default, docling runs OCR on all PDFs (including digital PDFs that
already have embedded text). This PR exposes
docling's `do_ocr` parameter to allow users to skip OCR on digital PDFs,
improving processing speed with no quality
loss.
Implementation changes:
- Add `do_ocr` field to `DoclingFileProcessorConfig` (default=`True`,
backward compatible)
- Pass config to docling's `PdfPipelineOptions`
- Create `DocumentConverter` once in `__init__` to reuse loaded models
<!-- If resolving an issue, uncomment and update the line below -->
<!-- Closes #[issue-number] -->
## Test Plan
Manual testing with 4 PDFs from the FileProcessor API pdf test set (2-32
pages):
**Digital PDFs (3 tested):**
- Advantag Savings (2 pages): 2.83s baseline to 1.54s with
`do_ocr=false` (1.85x speedup, 821 words extracted)
- syllabus_soc24_spring2018 (11 pages): 4.33s to 3.81s (1.14x speedup,
3348 words extracted)
- Best-Movies-in-Every-Genre (32 pages): 9.34s to 8.65s (1.08x speedup,
5942 words extracted)
- Quality: 100% text extraction maintained (same word count as baseline)
**Scanned PDF (1 tested):**
- Park at Beverly Hills (3 pages): 34.15s to 1.51s (22.6x speedup, but
only 18 words vs 479 words extracted)
- Confirms `do_ocr=true` required for scanned documents
**Validation script:**
```python
from ogx.providers.inline.file_processor.docling.config import
DoclingFileProcessorConfig
from ogx.providers.inline.file_processor.docling.docling import
DoclingFileProcessor
# Test default behavior
config_default = DoclingFileProcessorConfig()
assert config_default.do_ocr == True
print("Default config has do_ocr=True")
# Test with OCR disabled
config_optimized = DoclingFileProcessorConfig(do_ocr=False)
assert config_optimized.do_ocr == False
print("Config with do_ocr=False works")
# Verify processor initializes
processor = DoclingFileProcessor(config=config_optimized)
assert processor.converter is not None
print("DoclingFileProcessor initialized successfully")
Output:
Default config has do_ocr=True
Config with do_ocr=False works
DoclingFileProcessor initialized successfully
---------
Signed-off-by: Sahana Sreeram <sahanasreeram01@gmail.com>
Co-authored-by: devin-ai-integration[bot] <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-authored-by: Francisco Javier Arceo <arceofrancisco@gmail.com>1 parent 4d881a8 commit 4af4d0a
3 files changed
Lines changed: 24 additions & 3 deletions
File tree
- docs/docs/providers/file_processors
- src/ogx/providers/inline/file_processor/docling
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
97 | 97 | | |
98 | 98 | | |
99 | 99 | | |
| 100 | + | |
100 | 101 | | |
101 | 102 | | |
102 | 103 | | |
103 | 104 | | |
104 | 105 | | |
105 | 106 | | |
| 107 | + | |
106 | 108 | | |
Lines changed: 10 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
30 | 39 | | |
31 | 40 | | |
32 | 41 | | |
33 | 42 | | |
34 | 43 | | |
| 44 | + | |
35 | 45 | | |
Lines changed: 12 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
14 | | - | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
15 | 17 | | |
16 | 18 | | |
17 | 19 | | |
| |||
40 | 42 | | |
41 | 43 | | |
42 | 44 | | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
43 | 53 | | |
44 | 54 | | |
45 | 55 | | |
| |||
76 | 86 | | |
77 | 87 | | |
78 | 88 | | |
79 | | - | |
80 | | - | |
| 89 | + | |
81 | 90 | | |
82 | 91 | | |
83 | 92 | | |
| |||
0 commit comments