11import importlib
2+ from copy import deepcopy
23from functools import cache
34from typing import TYPE_CHECKING , Annotated , Any , ClassVar , get_type_hints
45
6+ from docling .backend .image_backend import ImageDocumentBackend
57from docling .datamodel .backend_options import BackendOptions , BaseBackendOptions
68from docling .datamodel .base_models import (
79 BaseFormatOption ,
2022)
2123from docling .datamodel .settings import DebugSettings
2224from docling .datamodel .settings import InferenceSettings as DoclingInferenceSettings
25+ from docling .document_converter import (
26+ BoxNoteFormatOption ,
27+ CsvFormatOption ,
28+ ExcelFormatOption ,
29+ OdsFormatOption ,
30+ OdtFormatOption ,
31+ PowerpointFormatOption ,
32+ WordFormatOption ,
33+ )
2334from icij_common .pydantic_utils import (
2435 merge_configs ,
2536 safe_copy ,
3142from pydantic_core .core_schema import SerializerFunctionWrapHandler
3243
3344from .configs import BasePipelineConfig , PipelineType , ResultBufferConfig
34- from .objects import BaseModel , Device , SupportedExt
45+ from .objects import BaseModel , Device , PipelineSize , SupportedExt
3546from .utils import all_subclasses
3647
3748if TYPE_CHECKING :
@@ -233,7 +244,48 @@ def to_docling(self, device: Device) -> BaseFormatOption: # noqa: ANN201
233244 )
234245
235246
236- def _default_format_opts () -> dict [InputFormat , DoclingFormatOption ]:
247+ def default_format_opts (
248+ * , size : PipelineSize = PipelineSize .SMALL , device : Device = Device .CPU
249+ ) -> dict [InputFormat , DoclingFormatOption ]:
250+ from docling .backend .docling_parse_backend import ( # noqa: PLC0415
251+ ThreadedDoclingParseDocumentBackend ,
252+ )
253+ from docling .pipeline .threaded_standard_pdf_pipeline import ( # noqa: PLC0415
254+ ThreadedStandardPdfPipeline ,
255+ )
256+ from docling .pipeline .vlm_pipeline import VlmPipeline # noqa: PLC0415
257+
258+ default = _default_format_options ()
259+ accelerator_opts = deepcopy (default [InputFormat .PDF ].pipeline_options )[
260+ "accelerator_options"
261+ ]
262+ accelerator_opts ["device" ] = device .to_docling ()
263+ pdf_pipeline_opts = default [InputFormat .PDF ].pipeline_options
264+ pdf_pipeline_opts ["accelerator_options" ] = accelerator_opts
265+ match size :
266+ case PipelineSize .LARGE :
267+ pipeline = VlmPipeline .__name__
268+ case _:
269+ pipeline = ThreadedStandardPdfPipeline .__name__
270+ backend_opts = default [InputFormat .PDF ].backend_options
271+ pdf_fmt_opts = DoclingFormatOption (
272+ pipeline_options = pdf_pipeline_opts ,
273+ pipeline_cls = pipeline ,
274+ backend = ThreadedDoclingParseDocumentBackend .__name__ ,
275+ backend_options = backend_opts ,
276+ )
277+ default [InputFormat .PDF ] = pdf_fmt_opts
278+ image_fmt_opts = DoclingFormatOption (
279+ pipeline_options = deepcopy (pdf_pipeline_opts ),
280+ pipeline_cls = pipeline ,
281+ backend = ImageDocumentBackend .__name__ ,
282+ backend_options = deepcopy (backend_opts ),
283+ )
284+ default [InputFormat .IMAGE ] = image_fmt_opts
285+ return default
286+
287+
288+ def _default_format_options () -> dict [InputFormat , DoclingFormatOption ]:
237289 from docling .backend .json .docling_json_backend import ( # noqa: PLC0415
238290 DoclingJSONBackend ,
239291 )
@@ -242,27 +294,20 @@ def _default_format_opts() -> dict[InputFormat, DoclingFormatOption]:
242294 from docling .document_converter import ( # noqa: PLC0415 # noqa: PLC0415
243295 AsciiDocFormatOption ,
244296 AudioFormatOption ,
245- BoxNoteFormatOption ,
246- CsvFormatOption ,
247297 DclxFormatOption ,
248298 EbcdicFormatOption ,
249299 EmailFormatOption ,
250300 EpubFormatOption ,
251- ExcelFormatOption ,
252301 FormatOption ,
253302 HTMLFormatOption ,
254303 ImageFormatOption ,
255304 IWorkPagesFormatOption ,
256305 LatexFormatOption ,
257306 MarkdownFormatOption ,
258307 OdpFormatOption ,
259- OdsFormatOption ,
260- OdtFormatOption ,
261308 PatentUsptoFormatOption ,
262309 PdfFormatOption ,
263- PowerpointFormatOption ,
264310 VideoFormatOption ,
265- WordFormatOption ,
266311 XBRLFormatOption ,
267312 XMLDocLangFormatOption ,
268313 XMLJatsFormatOption ,
@@ -361,7 +406,7 @@ class DoclingPipelineConfig(BasePipelineConfig):
361406 pipeline : ClassVar [PipelineType ] = Field (frozen = True , default = PipelineType .DOCLING )
362407
363408 format_options : dict [InputFormat , DoclingFormatOption ] = Field (
364- default_factory = _default_format_opts
409+ default_factory = default_format_opts
365410 )
366411
367412 settings : DoclingSettings = Field (default_factory = DoclingSettings )
0 commit comments