docling 2.42.2__tar.gz → 2.43.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (135) hide show
  1. {docling-2.42.2 → docling-2.43.0}/PKG-INFO +3 -3
  2. {docling-2.42.2 → docling-2.43.0}/docling/backend/html_backend.py +1 -6
  3. {docling-2.42.2 → docling-2.43.0}/docling/backend/md_backend.py +43 -11
  4. {docling-2.42.2 → docling-2.43.0}/docling/datamodel/pipeline_options.py +15 -0
  5. {docling-2.42.2 → docling-2.43.0}/docling/datamodel/settings.py +7 -12
  6. {docling-2.42.2 → docling-2.43.0}/docling/document_converter.py +27 -17
  7. {docling-2.42.2 → docling-2.43.0}/docling/models/layout_model.py +84 -66
  8. docling-2.43.0/docling/pipeline/threaded_standard_pdf_pipeline.py +605 -0
  9. {docling-2.42.2 → docling-2.43.0}/docling.egg-info/PKG-INFO +3 -3
  10. {docling-2.42.2 → docling-2.43.0}/docling.egg-info/SOURCES.txt +3 -1
  11. {docling-2.42.2 → docling-2.43.0}/docling.egg-info/requires.txt +2 -2
  12. {docling-2.42.2 → docling-2.43.0}/pyproject.toml +3 -5
  13. {docling-2.42.2 → docling-2.43.0}/tests/test_backend_markdown.py +7 -8
  14. {docling-2.42.2 → docling-2.43.0}/tests/test_settings_load.py +1 -1
  15. docling-2.43.0/tests/test_threaded_pipeline.py +176 -0
  16. {docling-2.42.2 → docling-2.43.0}/LICENSE +0 -0
  17. {docling-2.42.2 → docling-2.43.0}/README.md +0 -0
  18. {docling-2.42.2 → docling-2.43.0}/docling/__init__.py +0 -0
  19. {docling-2.42.2 → docling-2.43.0}/docling/backend/__init__.py +0 -0
  20. {docling-2.42.2 → docling-2.43.0}/docling/backend/abstract_backend.py +0 -0
  21. {docling-2.42.2 → docling-2.43.0}/docling/backend/asciidoc_backend.py +0 -0
  22. {docling-2.42.2 → docling-2.43.0}/docling/backend/csv_backend.py +0 -0
  23. {docling-2.42.2 → docling-2.43.0}/docling/backend/docling_parse_backend.py +0 -0
  24. {docling-2.42.2 → docling-2.43.0}/docling/backend/docling_parse_v2_backend.py +0 -0
  25. {docling-2.42.2 → docling-2.43.0}/docling/backend/docling_parse_v4_backend.py +0 -0
  26. {docling-2.42.2 → docling-2.43.0}/docling/backend/docx/__init__.py +0 -0
  27. {docling-2.42.2 → docling-2.43.0}/docling/backend/docx/latex/__init__.py +0 -0
  28. {docling-2.42.2 → docling-2.43.0}/docling/backend/docx/latex/latex_dict.py +0 -0
  29. {docling-2.42.2 → docling-2.43.0}/docling/backend/docx/latex/omml.py +0 -0
  30. {docling-2.42.2 → docling-2.43.0}/docling/backend/json/__init__.py +0 -0
  31. {docling-2.42.2 → docling-2.43.0}/docling/backend/json/docling_json_backend.py +0 -0
  32. {docling-2.42.2 → docling-2.43.0}/docling/backend/msexcel_backend.py +0 -0
  33. {docling-2.42.2 → docling-2.43.0}/docling/backend/mspowerpoint_backend.py +0 -0
  34. {docling-2.42.2 → docling-2.43.0}/docling/backend/msword_backend.py +0 -0
  35. {docling-2.42.2 → docling-2.43.0}/docling/backend/noop_backend.py +0 -0
  36. {docling-2.42.2 → docling-2.43.0}/docling/backend/pdf_backend.py +0 -0
  37. {docling-2.42.2 → docling-2.43.0}/docling/backend/pypdfium2_backend.py +0 -0
  38. {docling-2.42.2 → docling-2.43.0}/docling/backend/xml/__init__.py +0 -0
  39. {docling-2.42.2 → docling-2.43.0}/docling/backend/xml/jats_backend.py +0 -0
  40. {docling-2.42.2 → docling-2.43.0}/docling/backend/xml/uspto_backend.py +0 -0
  41. {docling-2.42.2 → docling-2.43.0}/docling/chunking/__init__.py +0 -0
  42. {docling-2.42.2 → docling-2.43.0}/docling/cli/__init__.py +0 -0
  43. {docling-2.42.2 → docling-2.43.0}/docling/cli/main.py +0 -0
  44. {docling-2.42.2 → docling-2.43.0}/docling/cli/models.py +0 -0
  45. {docling-2.42.2 → docling-2.43.0}/docling/cli/tools.py +0 -0
  46. {docling-2.42.2 → docling-2.43.0}/docling/datamodel/__init__.py +0 -0
  47. {docling-2.42.2 → docling-2.43.0}/docling/datamodel/accelerator_options.py +0 -0
  48. {docling-2.42.2 → docling-2.43.0}/docling/datamodel/asr_model_specs.py +0 -0
  49. {docling-2.42.2 → docling-2.43.0}/docling/datamodel/base_models.py +0 -0
  50. {docling-2.42.2 → docling-2.43.0}/docling/datamodel/document.py +0 -0
  51. {docling-2.42.2 → docling-2.43.0}/docling/datamodel/layout_model_specs.py +0 -0
  52. {docling-2.42.2 → docling-2.43.0}/docling/datamodel/pipeline_options_asr_model.py +0 -0
  53. {docling-2.42.2 → docling-2.43.0}/docling/datamodel/pipeline_options_vlm_model.py +0 -0
  54. {docling-2.42.2 → docling-2.43.0}/docling/datamodel/vlm_model_specs.py +0 -0
  55. {docling-2.42.2 → docling-2.43.0}/docling/exceptions.py +0 -0
  56. {docling-2.42.2 → docling-2.43.0}/docling/models/__init__.py +0 -0
  57. {docling-2.42.2 → docling-2.43.0}/docling/models/api_vlm_model.py +0 -0
  58. {docling-2.42.2 → docling-2.43.0}/docling/models/base_model.py +0 -0
  59. {docling-2.42.2 → docling-2.43.0}/docling/models/base_ocr_model.py +0 -0
  60. {docling-2.42.2 → docling-2.43.0}/docling/models/code_formula_model.py +0 -0
  61. {docling-2.42.2 → docling-2.43.0}/docling/models/document_picture_classifier.py +0 -0
  62. {docling-2.42.2 → docling-2.43.0}/docling/models/easyocr_model.py +0 -0
  63. {docling-2.42.2 → docling-2.43.0}/docling/models/factories/__init__.py +0 -0
  64. {docling-2.42.2 → docling-2.43.0}/docling/models/factories/base_factory.py +0 -0
  65. {docling-2.42.2 → docling-2.43.0}/docling/models/factories/ocr_factory.py +0 -0
  66. {docling-2.42.2 → docling-2.43.0}/docling/models/factories/picture_description_factory.py +0 -0
  67. {docling-2.42.2 → docling-2.43.0}/docling/models/ocr_mac_model.py +0 -0
  68. {docling-2.42.2 → docling-2.43.0}/docling/models/page_assemble_model.py +0 -0
  69. {docling-2.42.2 → docling-2.43.0}/docling/models/page_preprocessing_model.py +0 -0
  70. {docling-2.42.2 → docling-2.43.0}/docling/models/picture_description_api_model.py +0 -0
  71. {docling-2.42.2 → docling-2.43.0}/docling/models/picture_description_base_model.py +0 -0
  72. {docling-2.42.2 → docling-2.43.0}/docling/models/picture_description_vlm_model.py +0 -0
  73. {docling-2.42.2 → docling-2.43.0}/docling/models/plugins/__init__.py +0 -0
  74. {docling-2.42.2 → docling-2.43.0}/docling/models/plugins/defaults.py +0 -0
  75. {docling-2.42.2 → docling-2.43.0}/docling/models/rapid_ocr_model.py +0 -0
  76. {docling-2.42.2 → docling-2.43.0}/docling/models/readingorder_model.py +0 -0
  77. {docling-2.42.2 → docling-2.43.0}/docling/models/table_structure_model.py +0 -0
  78. {docling-2.42.2 → docling-2.43.0}/docling/models/tesseract_ocr_cli_model.py +0 -0
  79. {docling-2.42.2 → docling-2.43.0}/docling/models/tesseract_ocr_model.py +0 -0
  80. {docling-2.42.2 → docling-2.43.0}/docling/models/utils/__init__.py +0 -0
  81. {docling-2.42.2 → docling-2.43.0}/docling/models/utils/hf_model_download.py +0 -0
  82. {docling-2.42.2 → docling-2.43.0}/docling/models/vlm_models_inline/__init__.py +0 -0
  83. {docling-2.42.2 → docling-2.43.0}/docling/models/vlm_models_inline/hf_transformers_model.py +0 -0
  84. {docling-2.42.2 → docling-2.43.0}/docling/models/vlm_models_inline/mlx_model.py +0 -0
  85. {docling-2.42.2 → docling-2.43.0}/docling/pipeline/__init__.py +0 -0
  86. {docling-2.42.2 → docling-2.43.0}/docling/pipeline/asr_pipeline.py +0 -0
  87. {docling-2.42.2 → docling-2.43.0}/docling/pipeline/base_pipeline.py +0 -0
  88. {docling-2.42.2 → docling-2.43.0}/docling/pipeline/simple_pipeline.py +0 -0
  89. {docling-2.42.2 → docling-2.43.0}/docling/pipeline/standard_pdf_pipeline.py +0 -0
  90. {docling-2.42.2 → docling-2.43.0}/docling/pipeline/vlm_pipeline.py +0 -0
  91. {docling-2.42.2 → docling-2.43.0}/docling/py.typed +0 -0
  92. {docling-2.42.2 → docling-2.43.0}/docling/utils/__init__.py +0 -0
  93. {docling-2.42.2 → docling-2.43.0}/docling/utils/accelerator_utils.py +0 -0
  94. {docling-2.42.2 → docling-2.43.0}/docling/utils/api_image_request.py +0 -0
  95. {docling-2.42.2 → docling-2.43.0}/docling/utils/export.py +0 -0
  96. {docling-2.42.2 → docling-2.43.0}/docling/utils/glm_utils.py +0 -0
  97. {docling-2.42.2 → docling-2.43.0}/docling/utils/layout_postprocessor.py +0 -0
  98. {docling-2.42.2 → docling-2.43.0}/docling/utils/locks.py +0 -0
  99. {docling-2.42.2 → docling-2.43.0}/docling/utils/model_downloader.py +0 -0
  100. {docling-2.42.2 → docling-2.43.0}/docling/utils/ocr_utils.py +0 -0
  101. {docling-2.42.2 → docling-2.43.0}/docling/utils/orientation.py +0 -0
  102. {docling-2.42.2 → docling-2.43.0}/docling/utils/profiling.py +0 -0
  103. {docling-2.42.2 → docling-2.43.0}/docling/utils/utils.py +0 -0
  104. {docling-2.42.2 → docling-2.43.0}/docling/utils/visualization.py +0 -0
  105. {docling-2.42.2 → docling-2.43.0}/docling.egg-info/dependency_links.txt +0 -0
  106. {docling-2.42.2 → docling-2.43.0}/docling.egg-info/entry_points.txt +0 -0
  107. {docling-2.42.2 → docling-2.43.0}/docling.egg-info/top_level.txt +0 -0
  108. {docling-2.42.2 → docling-2.43.0}/setup.cfg +0 -0
  109. {docling-2.42.2 → docling-2.43.0}/tests/test_asr_pipeline.py +0 -0
  110. {docling-2.42.2 → docling-2.43.0}/tests/test_backend_asciidoc.py +0 -0
  111. {docling-2.42.2 → docling-2.43.0}/tests/test_backend_csv.py +0 -0
  112. {docling-2.42.2 → docling-2.43.0}/tests/test_backend_docling_json.py +0 -0
  113. {docling-2.42.2 → docling-2.43.0}/tests/test_backend_docling_parse.py +0 -0
  114. {docling-2.42.2 → docling-2.43.0}/tests/test_backend_docling_parse_v2.py +0 -0
  115. {docling-2.42.2 → docling-2.43.0}/tests/test_backend_docling_parse_v4.py +0 -0
  116. {docling-2.42.2 → docling-2.43.0}/tests/test_backend_html.py +0 -0
  117. {docling-2.42.2 → docling-2.43.0}/tests/test_backend_jats.py +0 -0
  118. {docling-2.42.2 → docling-2.43.0}/tests/test_backend_msexcel.py +0 -0
  119. {docling-2.42.2 → docling-2.43.0}/tests/test_backend_msword.py +0 -0
  120. {docling-2.42.2 → docling-2.43.0}/tests/test_backend_patent_uspto.py +0 -0
  121. {docling-2.42.2 → docling-2.43.0}/tests/test_backend_pdfium.py +0 -0
  122. {docling-2.42.2 → docling-2.43.0}/tests/test_backend_pptx.py +0 -0
  123. {docling-2.42.2 → docling-2.43.0}/tests/test_backend_webp.py +0 -0
  124. {docling-2.42.2 → docling-2.43.0}/tests/test_cli.py +0 -0
  125. {docling-2.42.2 → docling-2.43.0}/tests/test_code_formula.py +0 -0
  126. {docling-2.42.2 → docling-2.43.0}/tests/test_data_gen_flag.py +0 -0
  127. {docling-2.42.2 → docling-2.43.0}/tests/test_document_picture_classifier.py +0 -0
  128. {docling-2.42.2 → docling-2.43.0}/tests/test_e2e_conversion.py +0 -0
  129. {docling-2.42.2 → docling-2.43.0}/tests/test_e2e_ocr_conversion.py +0 -0
  130. {docling-2.42.2 → docling-2.43.0}/tests/test_input_doc.py +0 -0
  131. {docling-2.42.2 → docling-2.43.0}/tests/test_interfaces.py +0 -0
  132. {docling-2.42.2 → docling-2.43.0}/tests/test_invalid_input.py +0 -0
  133. {docling-2.42.2 → docling-2.43.0}/tests/test_legacy_format_transform.py +0 -0
  134. {docling-2.42.2 → docling-2.43.0}/tests/test_ocr_utils.py +0 -0
  135. {docling-2.42.2 → docling-2.43.0}/tests/test_options.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: docling
3
- Version: 2.42.2
3
+ Version: 2.43.0
4
4
  Summary: SDK and CLI for parsing PDF, DOCX, HTML, and more, to a unified document representation for powering downstream workflows such as gen AI applications.
5
5
  Author-email: Christoph Auer <cau@zurich.ibm.com>, Michele Dolfi <dol@zurich.ibm.com>, Maxim Lysak <mly@zurich.ibm.com>, Nikos Livathinos <nli@zurich.ibm.com>, Ahmed Nassar <ahn@zurich.ibm.com>, Panos Vagenas <pva@zurich.ibm.com>, Peter Staar <taa@zurich.ibm.com>
6
6
  License-Expression: MIT
@@ -28,9 +28,9 @@ License-File: LICENSE
28
28
  Requires-Dist: pydantic<3.0.0,>=2.0.0
29
29
  Requires-Dist: docling-core[chunking]<3.0.0,>=2.42.0
30
30
  Requires-Dist: docling-parse<5.0.0,>=4.0.0
31
- Requires-Dist: docling-ibm-models<4,>=3.6.0
31
+ Requires-Dist: docling-ibm-models<4,>=3.9.0
32
32
  Requires-Dist: filetype<2.0.0,>=1.2.0
33
- Requires-Dist: pypdfium2<5.0.0,>=4.30.0
33
+ Requires-Dist: pypdfium2!=4.30.1,<5.0.0,>=4.30.0
34
34
  Requires-Dist: pydantic-settings<3.0.0,>=2.3.0
35
35
  Requires-Dist: huggingface_hub<1,>=0.23
36
36
  Requires-Dist: requests<3.0.0,>=2.32.2
@@ -1,6 +1,5 @@
1
1
  import logging
2
2
  import re
3
- import traceback
4
3
  from io import BytesIO
5
4
  from pathlib import Path
6
5
  from typing import Final, Optional, Union, cast
@@ -144,11 +143,7 @@ class HTMLDocumentBackend(DeclarativeDocumentBackend):
144
143
  )
145
144
  # reset context
146
145
  self.ctx = _Context()
147
-
148
- try:
149
- self._walk(content, doc)
150
- except Exception:
151
- print(traceback.format_exc())
146
+ self._walk(content, doc)
152
147
 
153
148
  return doc
154
149
 
@@ -5,7 +5,7 @@ from copy import deepcopy
5
5
  from enum import Enum
6
6
  from io import BytesIO
7
7
  from pathlib import Path
8
- from typing import List, Literal, Optional, Set, Union
8
+ from typing import Literal, Optional, Union, cast
9
9
 
10
10
  import marko
11
11
  import marko.element
@@ -14,6 +14,7 @@ from docling_core.types.doc import (
14
14
  DocItemLabel,
15
15
  DoclingDocument,
16
16
  DocumentOrigin,
17
+ ListItem,
17
18
  NodeItem,
18
19
  TableCell,
19
20
  TableData,
@@ -89,7 +90,7 @@ class MarkdownDocumentBackend(DeclarativeDocumentBackend):
89
90
  def __init__(self, in_doc: "InputDocument", path_or_stream: Union[BytesIO, Path]):
90
91
  super().__init__(in_doc, path_or_stream)
91
92
 
92
- _log.debug("MD INIT!!!")
93
+ _log.debug("Starting MarkdownDocumentBackend...")
93
94
 
94
95
  # Markdown file:
95
96
  self.path_or_stream = path_or_stream
@@ -131,7 +132,7 @@ class MarkdownDocumentBackend(DeclarativeDocumentBackend):
131
132
  for md_table_row in self.md_table_buffer:
132
133
  _log.debug(md_table_row)
133
134
  _log.debug("=== TABLE END ===")
134
- tcells: List[TableCell] = []
135
+ tcells: list[TableCell] = []
135
136
  result_table = []
136
137
  for n, md_table_row in enumerate(self.md_table_buffer):
137
138
  data = []
@@ -232,11 +233,12 @@ class MarkdownDocumentBackend(DeclarativeDocumentBackend):
232
233
  element: marko.element.Element,
233
234
  depth: int,
234
235
  doc: DoclingDocument,
235
- visited: Set[marko.element.Element],
236
+ visited: set[marko.element.Element],
236
237
  creation_stack: list[
237
238
  _CreationPayload
238
239
  ], # stack for lazy item creation triggered deep in marko's AST (on RawText)
239
240
  list_ordered_flag_by_ref: dict[str, bool],
241
+ list_last_item_by_ref: dict[str, ListItem],
240
242
  parent_item: Optional[NodeItem] = None,
241
243
  formatting: Optional[Formatting] = None,
242
244
  hyperlink: Optional[Union[AnyUrl, Path]] = None,
@@ -279,7 +281,7 @@ class MarkdownDocumentBackend(DeclarativeDocumentBackend):
279
281
 
280
282
  elif (
281
283
  isinstance(element, marko.block.ListItem)
282
- and len(element.children) == 1
284
+ and len(element.children) > 0
283
285
  and isinstance((child := element.children[0]), marko.block.Paragraph)
284
286
  and len(child.children) > 0
285
287
  ):
@@ -291,7 +293,15 @@ class MarkdownDocumentBackend(DeclarativeDocumentBackend):
291
293
  if parent_item
292
294
  else False
293
295
  )
294
- if len(child.children) > 1: # inline group will be created further down
296
+ non_list_children: list[marko.element.Element] = [
297
+ item
298
+ for item in child.children
299
+ if not isinstance(item, marko.block.ListItem)
300
+ ]
301
+ if len(non_list_children) > 1: # inline group will be created further down
302
+ parent_ref: Optional[str] = (
303
+ parent_item.self_ref if parent_item else None
304
+ )
295
305
  parent_item = self._create_list_item(
296
306
  doc=doc,
297
307
  parent_item=parent_item,
@@ -300,6 +310,8 @@ class MarkdownDocumentBackend(DeclarativeDocumentBackend):
300
310
  formatting=formatting,
301
311
  hyperlink=hyperlink,
302
312
  )
313
+ if parent_ref:
314
+ list_last_item_by_ref[parent_ref] = cast(ListItem, parent_item)
303
315
  else:
304
316
  creation_stack.append(_ListItemCreationPayload(enumerated=enumerated))
305
317
 
@@ -334,9 +346,11 @@ class MarkdownDocumentBackend(DeclarativeDocumentBackend):
334
346
  element.dest
335
347
  )
336
348
 
337
- elif isinstance(element, marko.inline.RawText):
338
- _log.debug(f" - Paragraph (raw text): {element.children}")
339
- snippet_text = element.children.strip()
349
+ elif isinstance(element, (marko.inline.RawText, marko.inline.Literal)):
350
+ _log.debug(f" - RawText/Literal: {element.children}")
351
+ snippet_text = (
352
+ element.children.strip() if isinstance(element.children, str) else ""
353
+ )
340
354
  # Detect start of the table:
341
355
  if "|" in snippet_text or self.in_table:
342
356
  # most likely part of the markdown table
@@ -359,6 +373,7 @@ class MarkdownDocumentBackend(DeclarativeDocumentBackend):
359
373
  if parent_item
360
374
  else False
361
375
  )
376
+ parent_ref = parent_item.self_ref if parent_item else None
362
377
  parent_item = self._create_list_item(
363
378
  doc=doc,
364
379
  parent_item=parent_item,
@@ -367,6 +382,11 @@ class MarkdownDocumentBackend(DeclarativeDocumentBackend):
367
382
  formatting=formatting,
368
383
  hyperlink=hyperlink,
369
384
  )
385
+ if parent_ref:
386
+ list_last_item_by_ref[parent_ref] = cast(
387
+ ListItem, parent_item
388
+ )
389
+
370
390
  elif isinstance(to_create, _HeadingCreationPayload):
371
391
  # not keeping as parent_item as logic for correctly tracking
372
392
  # that not implemented yet (section components not captured
@@ -458,6 +478,17 @@ class MarkdownDocumentBackend(DeclarativeDocumentBackend):
458
478
  element, processed_block_types
459
479
  ):
460
480
  for child in element.children:
481
+ if (
482
+ isinstance(element, marko.block.ListItem)
483
+ and isinstance(child, marko.block.List)
484
+ and parent_item
485
+ and list_last_item_by_ref.get(parent_item.self_ref, None)
486
+ ):
487
+ _log.debug(
488
+ f"walking into new List hanging from item of parent list {parent_item.self_ref}"
489
+ )
490
+ parent_item = list_last_item_by_ref[parent_item.self_ref]
491
+
461
492
  self._iterate_elements(
462
493
  element=child,
463
494
  depth=depth + 1,
@@ -465,6 +496,7 @@ class MarkdownDocumentBackend(DeclarativeDocumentBackend):
465
496
  visited=visited,
466
497
  creation_stack=creation_stack,
467
498
  list_ordered_flag_by_ref=list_ordered_flag_by_ref,
499
+ list_last_item_by_ref=list_last_item_by_ref,
468
500
  parent_item=parent_item,
469
501
  formatting=formatting,
470
502
  hyperlink=hyperlink,
@@ -483,7 +515,7 @@ class MarkdownDocumentBackend(DeclarativeDocumentBackend):
483
515
  return False
484
516
 
485
517
  @classmethod
486
- def supported_formats(cls) -> Set[InputFormat]:
518
+ def supported_formats(cls) -> set[InputFormat]:
487
519
  return {InputFormat.MD}
488
520
 
489
521
  def convert(self) -> DoclingDocument:
@@ -510,6 +542,7 @@ class MarkdownDocumentBackend(DeclarativeDocumentBackend):
510
542
  visited=set(),
511
543
  creation_stack=[],
512
544
  list_ordered_flag_by_ref={},
545
+ list_last_item_by_ref={},
513
546
  )
514
547
  self._close_table(doc=doc) # handle any last hanging table
515
548
 
@@ -534,7 +567,6 @@ class MarkdownDocumentBackend(DeclarativeDocumentBackend):
534
567
  ]:
535
568
  html_str = _restore_original_html(txt=html_str, regex=regex)
536
569
  self._html_blocks = 0
537
-
538
570
  # delegate to HTML backend
539
571
  stream = BytesIO(bytes(html_str, encoding="utf-8"))
540
572
  in_doc = InputDocument(
@@ -332,3 +332,18 @@ class ProcessingPipeline(str, Enum):
332
332
  STANDARD = "standard"
333
333
  VLM = "vlm"
334
334
  ASR = "asr"
335
+
336
+
337
+ class ThreadedPdfPipelineOptions(PdfPipelineOptions):
338
+ """Pipeline options for the threaded PDF pipeline with batching and backpressure control"""
339
+
340
+ # Batch sizes for different stages
341
+ ocr_batch_size: int = 4
342
+ layout_batch_size: int = 4
343
+ table_batch_size: int = 4
344
+
345
+ # Timing control
346
+ batch_timeout_seconds: float = 2.0
347
+
348
+ # Backpressure and queue control
349
+ queue_max_size: int = 100
@@ -26,18 +26,13 @@ class DocumentLimits(BaseModel):
26
26
 
27
27
 
28
28
  class BatchConcurrencySettings(BaseModel):
29
- doc_batch_size: int = 2
30
- doc_batch_concurrency: int = 2
31
- page_batch_size: int = 4
32
- page_batch_concurrency: int = 2
33
- elements_batch_size: int = 16
34
-
35
- # doc_batch_size: int = 1
36
- # doc_batch_concurrency: int = 1
37
- # page_batch_size: int = 1
38
- # page_batch_concurrency: int = 1
39
-
40
- # model_concurrency: int = 2
29
+ doc_batch_size: int = 1 # Number of documents processed in one batch. Should be >= doc_batch_concurrency
30
+ doc_batch_concurrency: int = 1 # Number of parallel threads processing documents. Warning: Experimental! No benefit expected without free-threaded python.
31
+ page_batch_size: int = 4 # Number of pages processed in one batch.
32
+ page_batch_concurrency: int = 1 # Currently unused.
33
+ elements_batch_size: int = (
34
+ 16 # Number of elements processed in one batch, in enrichment models.
35
+ )
41
36
 
42
37
  # To force models into single core: export OMP_NUM_THREADS=1
43
38
 
@@ -4,6 +4,7 @@ import sys
4
4
  import threading
5
5
  import time
6
6
  from collections.abc import Iterable, Iterator
7
+ from concurrent.futures import ThreadPoolExecutor
7
8
  from functools import partial
8
9
  from pathlib import Path
9
10
  from typing import Dict, List, Optional, Tuple, Type, Union
@@ -284,24 +285,33 @@ class DocumentConverter:
284
285
  settings.perf.doc_batch_size, # pass format_options
285
286
  ):
286
287
  _log.info("Going to convert document batch...")
288
+ process_func = partial(
289
+ self._process_document, raises_on_error=raises_on_error
290
+ )
287
291
 
288
- # parallel processing only within input_batch
289
- # with ThreadPoolExecutor(
290
- # max_workers=settings.perf.doc_batch_concurrency
291
- # ) as pool:
292
- # yield from pool.map(self.process_document, input_batch)
293
- # Note: PDF backends are not thread-safe, thread pool usage was disabled.
294
-
295
- for item in map(
296
- partial(self._process_document, raises_on_error=raises_on_error),
297
- input_batch,
292
+ if (
293
+ settings.perf.doc_batch_concurrency > 1
294
+ and settings.perf.doc_batch_size > 1
298
295
  ):
299
- elapsed = time.monotonic() - start_time
300
- start_time = time.monotonic()
301
- _log.info(
302
- f"Finished converting document {item.input.file.name} in {elapsed:.2f} sec."
303
- )
304
- yield item
296
+ with ThreadPoolExecutor(
297
+ max_workers=settings.perf.doc_batch_concurrency
298
+ ) as pool:
299
+ for item in pool.map(
300
+ process_func,
301
+ input_batch,
302
+ ):
303
+ yield item
304
+ else:
305
+ for item in map(
306
+ process_func,
307
+ input_batch,
308
+ ):
309
+ elapsed = time.monotonic() - start_time
310
+ start_time = time.monotonic()
311
+ _log.info(
312
+ f"Finished converting document {item.input.file.name} in {elapsed:.2f} sec."
313
+ )
314
+ yield item
305
315
 
306
316
  def _get_pipeline(self, doc_format: InputFormat) -> Optional[BasePipeline]:
307
317
  """Retrieve or initialize a pipeline, reusing instances based on class and options."""
@@ -330,7 +340,7 @@ class DocumentConverter:
330
340
  f"Reusing cached pipeline for {pipeline_class.__name__} with options hash {options_hash}"
331
341
  )
332
342
 
333
- return self.initialized_pipelines[cache_key]
343
+ return self.initialized_pipelines[cache_key]
334
344
 
335
345
  def _process_document(
336
346
  self, in_doc: InputDocument, raises_on_error: bool
@@ -3,7 +3,7 @@ import logging
3
3
  import warnings
4
4
  from collections.abc import Iterable
5
5
  from pathlib import Path
6
- from typing import Optional
6
+ from typing import List, Optional, Union
7
7
 
8
8
  import numpy as np
9
9
  from docling_core.types.doc import DocItemLabel
@@ -148,72 +148,90 @@ class LayoutModel(BasePageModel):
148
148
  def __call__(
149
149
  self, conv_res: ConversionResult, page_batch: Iterable[Page]
150
150
  ) -> Iterable[Page]:
151
- for page in page_batch:
151
+ # Convert to list to allow multiple iterations
152
+ pages = list(page_batch)
153
+
154
+ # Separate valid and invalid pages
155
+ valid_pages = []
156
+ valid_page_images: List[Union[Image.Image, np.ndarray]] = []
157
+
158
+ for page in pages:
152
159
  assert page._backend is not None
153
160
  if not page._backend.is_valid():
154
- yield page
155
- else:
156
- with TimeRecorder(conv_res, "layout"):
157
- assert page.size is not None
158
- page_image = page.get_image(scale=1.0)
159
- assert page_image is not None
160
-
161
- clusters = []
162
- for ix, pred_item in enumerate(
163
- self.layout_predictor.predict(page_image)
164
- ):
165
- label = DocItemLabel(
166
- pred_item["label"]
167
- .lower()
168
- .replace(" ", "_")
169
- .replace("-", "_")
170
- ) # Temporary, until docling-ibm-model uses docling-core types
171
- cluster = Cluster(
172
- id=ix,
173
- label=label,
174
- confidence=pred_item["confidence"],
175
- bbox=BoundingBox.model_validate(pred_item),
176
- cells=[],
177
- )
178
- clusters.append(cluster)
179
-
180
- if settings.debug.visualize_raw_layout:
181
- self.draw_clusters_and_cells_side_by_side(
182
- conv_res, page, clusters, mode_prefix="raw"
183
- )
184
-
185
- # Apply postprocessing
186
-
187
- processed_clusters, processed_cells = LayoutPostprocessor(
188
- page, clusters, self.options
189
- ).postprocess()
190
- # Note: LayoutPostprocessor updates page.cells and page.parsed_page internally
191
-
192
- with warnings.catch_warnings():
193
- warnings.filterwarnings(
194
- "ignore",
195
- "Mean of empty slice|invalid value encountered in scalar divide",
196
- RuntimeWarning,
197
- "numpy",
198
- )
199
-
200
- conv_res.confidence.pages[page.page_no].layout_score = float(
201
- np.mean([c.confidence for c in processed_clusters])
202
- )
203
-
204
- conv_res.confidence.pages[page.page_no].ocr_score = float(
205
- np.mean(
206
- [c.confidence for c in processed_cells if c.from_ocr]
207
- )
208
- )
209
-
210
- page.predictions.layout = LayoutPrediction(
211
- clusters=processed_clusters
212
- )
213
-
214
- if settings.debug.visualize_layout:
215
- self.draw_clusters_and_cells_side_by_side(
216
- conv_res, page, processed_clusters, mode_prefix="postprocessed"
217
- )
161
+ continue
218
162
 
163
+ assert page.size is not None
164
+ page_image = page.get_image(scale=1.0)
165
+ assert page_image is not None
166
+
167
+ valid_pages.append(page)
168
+ valid_page_images.append(page_image)
169
+
170
+ # Process all valid pages with batch prediction
171
+ batch_predictions = []
172
+ if valid_page_images:
173
+ with TimeRecorder(conv_res, "layout"):
174
+ batch_predictions = self.layout_predictor.predict_batch( # type: ignore[attr-defined]
175
+ valid_page_images
176
+ )
177
+
178
+ # Process each page with its predictions
179
+ valid_page_idx = 0
180
+ for page in pages:
181
+ assert page._backend is not None
182
+ if not page._backend.is_valid():
219
183
  yield page
184
+ continue
185
+
186
+ page_predictions = batch_predictions[valid_page_idx]
187
+ valid_page_idx += 1
188
+
189
+ clusters = []
190
+ for ix, pred_item in enumerate(page_predictions):
191
+ label = DocItemLabel(
192
+ pred_item["label"].lower().replace(" ", "_").replace("-", "_")
193
+ ) # Temporary, until docling-ibm-model uses docling-core types
194
+ cluster = Cluster(
195
+ id=ix,
196
+ label=label,
197
+ confidence=pred_item["confidence"],
198
+ bbox=BoundingBox.model_validate(pred_item),
199
+ cells=[],
200
+ )
201
+ clusters.append(cluster)
202
+
203
+ if settings.debug.visualize_raw_layout:
204
+ self.draw_clusters_and_cells_side_by_side(
205
+ conv_res, page, clusters, mode_prefix="raw"
206
+ )
207
+
208
+ # Apply postprocessing
209
+ processed_clusters, processed_cells = LayoutPostprocessor(
210
+ page, clusters, self.options
211
+ ).postprocess()
212
+ # Note: LayoutPostprocessor updates page.cells and page.parsed_page internally
213
+
214
+ with warnings.catch_warnings():
215
+ warnings.filterwarnings(
216
+ "ignore",
217
+ "Mean of empty slice|invalid value encountered in scalar divide",
218
+ RuntimeWarning,
219
+ "numpy",
220
+ )
221
+
222
+ conv_res.confidence.pages[page.page_no].layout_score = float(
223
+ np.mean([c.confidence for c in processed_clusters])
224
+ )
225
+
226
+ conv_res.confidence.pages[page.page_no].ocr_score = float(
227
+ np.mean([c.confidence for c in processed_cells if c.from_ocr])
228
+ )
229
+
230
+ page.predictions.layout = LayoutPrediction(clusters=processed_clusters)
231
+
232
+ if settings.debug.visualize_layout:
233
+ self.draw_clusters_and_cells_side_by_side(
234
+ conv_res, page, processed_clusters, mode_prefix="postprocessed"
235
+ )
236
+
237
+ yield page