diff --git a/docling-serve/docling-serve-api/src/main/java/ai/docling/serve/api/convert/request/options/ConvertDocumentOptions.java b/docling-serve/docling-serve-api/src/main/java/ai/docling/serve/api/convert/request/options/ConvertDocumentOptions.java index c245cc6a..781502f6 100644 --- a/docling-serve/docling-serve-api/src/main/java/ai/docling/serve/api/convert/request/options/ConvertDocumentOptions.java +++ b/docling-serve/docling-serve-api/src/main/java/ai/docling/serve/api/convert/request/options/ConvertDocumentOptions.java @@ -3,6 +3,7 @@ import java.time.Duration; import java.time.temporal.ChronoUnit; import java.util.List; +import java.util.Map; import org.jspecify.annotations.Nullable; @@ -66,8 +67,14 @@ public class ConvertDocumentOptions { /** * The OCR engine to use. String. Allowed values: auto, easyocr, ocrmac, rapidocr, tesserocr, tesseract. Optional, defaults to easyocr. + * + *

Docling Serve marks {@code ocr_engine} as deprecated and synchronizes it onto {@code ocr_preset} when + * {@code ocr_preset} is not set. + * + * @deprecated Docling Serve deprecated {@code ocr_engine}. Use {@link #getOcrPreset()} instead. */ @JsonProperty("ocr_engine") + @Deprecated(since = "0.7.3") @Nullable private OcrEngine ocrEngine; @@ -79,6 +86,23 @@ public class ConvertDocumentOptions { @lombok.Singular("ocrLang") private List ocrLang; + /** + * Preset id for the OCR engine, for example {@code auto}, {@code easyocr} or {@code tesseract}. Optional, defaults to {@code auto} on the server. Mutually exclusive with + * {@link #getOcrCustomConfig()}. The set of available presets is controlled by the Docling Serve deployment. + */ + @JsonProperty("ocr_preset") + @Nullable + private String ocrPreset; + + /** + * Custom configuration for the OCR engine, used to specify engine-specific options beyond {@link #getOcrLang()}. The {@code kind} entry selects the engine implementation, for + * example {@code easyocr} or {@code tesseract}, and each engine kind has its own configuration schema. Mutually exclusive with {@link #getOcrPreset()}. + */ + @JsonProperty("ocr_custom_config") + @JsonSetter(nulls = Nulls.AS_EMPTY) + @lombok.Singular("ocrCustomConfigEntry") + private Map ocrCustomConfig; + /** * The PDF backend to use. String. Allowed values: pypdfium2, dlparse_v1, dlparse_v2, dlparse_v4. Optional, defaults to dlparse_v4. */ @@ -101,6 +125,44 @@ public class ConvertDocumentOptions { @Nullable private Boolean tableCellMatching; + /** + * Preset id for table structure detection. {@code default} selects the deployment-controlled default; the server schema also lists {@code tableformer_v1_accurate}, + * {@code tableformer_v1_fast} and {@code tableformer_v2} as examples, but those are not registered in every Docling Serve build. Mutually + * exclusive with {@link #getTableStructureCustomConfig()}. The set of available presets is controlled by the Docling Serve deployment. + */ + @JsonProperty("table_structure_preset") + @Nullable + private String tableStructurePreset; + + /** + * Custom configuration for the table structure model. The {@code kind} entry selects the table structure implementation, for example {@code docling_tableformer}, and the + * remaining entries are that implementation's options. When unset, the default kind with its preset configuration is used. Mutually exclusive with + * {@link #getTableStructurePreset()}. + */ + @JsonProperty("table_structure_custom_config") + @JsonSetter(nulls = Nulls.AS_EMPTY) + @lombok.Singular("tableStructureCustomConfigEntry") + private Map tableStructureCustomConfig; + + /** + * Preset id for layout detection. {@code default} selects the deployment-controlled default; the server schema also lists {@code docling_layout_default} as an example, but it + * is not registered in every Docling Serve build. Mutually exclusive with {@link #getLayoutCustomConfig()}. The set of available presets is controlled by the Docling Serve + * deployment. + */ + @JsonProperty("layout_preset") + @Nullable + private String layoutPreset; + + /** + * Custom configuration for the layout model. The {@code kind} entry selects the layout implementation, for example {@code docling_layout_default} or + * {@code layout_object_detection}, and the remaining entries are that implementation's options. When unset, the default kind with its preset configuration is used. Mutually + * exclusive with {@link #getLayoutPreset()}. + */ + @JsonProperty("layout_custom_config") + @JsonSetter(nulls = Nulls.AS_EMPTY) + @lombok.Singular("layoutCustomConfigEntry") + private Map layoutCustomConfig; + /** * Choose the pipeline to process PDF or image files. */ @@ -141,12 +203,20 @@ public class ConvertDocumentOptions { private Boolean doTableStructure; /** - * If enabled, images will be extracted from the document. Boolean. Optional, defaults to true. + * If enabled, picture element images are generated and included in the output. Boolean. Optional, defaults to true. */ @JsonProperty("include_images") @Nullable private Boolean includeImages; + /** + * If enabled, full-page images are generated and included in the output. This is independent of {@link #getIncludeImages()}, which covers picture elements only. Boolean. + * Optional, defaults to false. + */ + @JsonProperty("include_page_images") + @Nullable + private Boolean includePageImages; + /** * Scale factor for images. Float. Optional, defaults to 2.0. */ @@ -161,6 +231,14 @@ public class ConvertDocumentOptions { @Nullable private String mdPageBreakPlaceholder; + /** + * Whether to use a compact table format without column padding in the markdown output. When false (the default), tables use padded columns for better visual formatting. When + * true, tables use minimal whitespace, which is better for large tables and downstream processing. Boolean. Optional, defaults to false. + */ + @JsonProperty("md_compact_tables") + @Nullable + private Boolean mdCompactTables; + /** * If enabled, perform OCR code enrichment. Boolean. Optional, defaults to false. */ @@ -175,6 +253,22 @@ public class ConvertDocumentOptions { @Nullable private Boolean doFormulaEnrichment; + /** + * Preset id for code and formula extraction, for example {@code default}. Mutually exclusive with {@link #getCodeFormulaCustomConfig()}. The set of available presets is + * controlled by the Docling Serve deployment. Applies to {@link #getDoCodeEnrichment()} and {@link #getDoFormulaEnrichment()}. + */ + @JsonProperty("code_formula_preset") + @Nullable + private String codeFormulaPreset; + + /** + * Custom code and formula extraction configuration, including the model spec and engine options. Mutually exclusive with {@link #getCodeFormulaPreset()}. + */ + @JsonProperty("code_formula_custom_config") + @JsonSetter(nulls = Nulls.AS_EMPTY) + @lombok.Singular("codeFormulaCustomConfigEntry") + private Map codeFormulaCustomConfig; + /** * If enabled, classify pictures in documents. Boolean. Optional, defaults to false. */ @@ -182,6 +276,48 @@ public class ConvertDocumentOptions { @Nullable private Boolean doPictureClassification; + /** + * Preset id for picture classification, for example {@code default} or {@code document_figure_classifier_v2}. Mutually exclusive with + * {@link #getPictureClassificationCustomConfig()}. The set of available presets is controlled by the Docling Serve deployment. + */ + @JsonProperty("picture_classification_preset") + @Nullable + private String pictureClassificationPreset; + + /** + * Custom configuration for picture classification. The {@code kind} entry selects the classifier implementation, for example {@code document_picture_classifier}. Mutually + * exclusive with {@link #getPictureClassificationPreset()}. + */ + @JsonProperty("picture_classification_custom_config") + @JsonSetter(nulls = Nulls.AS_EMPTY) + @lombok.Singular("pictureClassificationCustomConfigEntry") + private Map pictureClassificationCustomConfig; + + /** + * If enabled, extract numeric data from charts. Boolean. Optional, defaults to false. + */ + @JsonProperty("do_chart_extraction") + @Nullable + private Boolean doChartExtraction; + + /** + * Preset id for chart extraction. Use {@code default} for the deployment-controlled default, or a specific preset such as {@code granite_vision_v4} or {@code granite_vision}. + * Mutually exclusive with {@link #getChartExtractionCustomConfig()}. + */ + @JsonProperty("chart_extraction_preset") + @Nullable + private String chartExtractionPreset; + + /** + * Custom chart extraction configuration, including the model spec and engine options. Entries are {@code model_spec}, {@code engine_options} and the optional output flags + * {@code chart2csv}, {@code chart2summary} and {@code chart2code}. Only available if the Docling Serve deployment allows custom configurations. Mutually exclusive with + * {@link #getChartExtractionPreset()}. + */ + @JsonProperty("chart_extraction_custom_config") + @JsonSetter(nulls = Nulls.AS_EMPTY) + @lombok.Singular("chartExtractionCustomConfigEntry") + private Map chartExtractionCustomConfig; + /** * If enabled, describe pictures in documents. Boolean. Optional, defaults to false. */ @@ -199,41 +335,100 @@ public class ConvertDocumentOptions { /** * Options for running a local vision-language model in the picture description. The parameters refer to a model hosted on Hugging Face. This parameter is mutually exclusive with * picture_description_api. + * + *

Docling Serve marks {@code picture_description_local} as deprecated. The replacements cannot be combined with this option. + * + * @deprecated Docling Serve deprecated {@code picture_description_local}. Use {@link #getPictureDescriptionPreset()} or {@link #getPictureDescriptionCustomConfig()} instead. */ @JsonProperty("picture_description_local") + @Deprecated(since = "0.7.3") @Nullable private PictureDescriptionLocal pictureDescriptionLocal; /** * API details for using a vision-language model in the picture description. This parameter is mutually exclusive with picture_description_local. + * + *

Docling Serve marks {@code picture_description_api} as deprecated. The replacements cannot be combined with this option. + * + * @deprecated Docling Serve deprecated {@code picture_description_api}. Use {@link #getPictureDescriptionPreset()} or {@link #getPictureDescriptionCustomConfig()} instead. */ @JsonProperty("picture_description_api") + @Deprecated(since = "0.7.3") @Nullable private PictureDescriptionApi pictureDescriptionApi; + /** + * Preset id for picture description, for example {@code default}, {@code smolvlm} or {@code granite_vision}. Mutually exclusive with + * {@link #getPictureDescriptionCustomConfig()}, and cannot be combined with the deprecated {@link #getPictureDescriptionLocal()} or {@link #getPictureDescriptionApi()}. + */ + @JsonProperty("picture_description_preset") + @Nullable + private String pictureDescriptionPreset; + + /** + * Custom picture description configuration, including the model spec and engine options. Mutually exclusive with {@link #getPictureDescriptionPreset()}, and cannot be combined + * with the deprecated {@link #getPictureDescriptionLocal()} or {@link #getPictureDescriptionApi()}. + */ + @JsonProperty("picture_description_custom_config") + @JsonSetter(nulls = Nulls.AS_EMPTY) + @lombok.Singular("pictureDescriptionCustomConfigEntry") + private Map pictureDescriptionCustomConfig; + /** * Preset of local and API models for the vlm pipeline. This parameter is mutually exclusive with vlm_pipeline_model_local and vlm_pipeline_model_api. Use the other options for * more parameters. + * + *

Docling Serve marks {@code vlm_pipeline_model} as deprecated. The replacements cannot be combined with this option. + * + * @deprecated Docling Serve deprecated {@code vlm_pipeline_model}. Use {@link #getVlmPipelinePreset()} or {@link #getVlmPipelineCustomConfig()} instead. */ @JsonProperty("vlm_pipeline_model") + @Deprecated(since = "0.7.3") @Nullable private VlmModelType vlmPipelineModel; /** * Options for running a local vision-language model for the vlm pipeline. The parameters refer to a model hosted on Hugging Face. This parameter is mutually exclusive with * vlm_pipeline_model_api and vlm_pipeline_model. + * + *

Docling Serve marks {@code vlm_pipeline_model_local} as deprecated. The replacements cannot be combined with this option. + * + * @deprecated Docling Serve deprecated {@code vlm_pipeline_model_local}. Use {@link #getVlmPipelinePreset()} or {@link #getVlmPipelineCustomConfig()} instead. */ @JsonProperty("vlm_pipeline_model_local") + @Deprecated(since = "0.7.3") @Nullable private String vlmPipelineModelLocal; /** * API details for using a vision-language model for the vlm pipeline. This parameter is mutually exclusive with vlm_pipeline_model_local and vlm_pipeline_model. + * + *

Docling Serve marks {@code vlm_pipeline_model_api} as deprecated. The replacements cannot be combined with this option. + * + * @deprecated Docling Serve deprecated {@code vlm_pipeline_model_api}. Use {@link #getVlmPipelinePreset()} or {@link #getVlmPipelineCustomConfig()} instead. */ @JsonProperty("vlm_pipeline_model_api") + @Deprecated(since = "0.7.3") @Nullable private String vlmPipelineModelApi; + /** + * Preset id for the VLM pipeline, for example {@code default} or {@code granite_docling}. Use {@code default} for the stable, deployment-controlled configuration. Mutually + * exclusive with {@link #getVlmPipelineCustomConfig()}, and cannot be combined with the deprecated {@code vlmPipelineModel*} options. + */ + @JsonProperty("vlm_pipeline_preset") + @Nullable + private String vlmPipelinePreset; + + /** + * Custom VLM pipeline configuration. Must include the {@code model_spec} and {@code engine_options} entries. Only available if the Docling Serve deployment allows custom + * configurations. Mutually exclusive with {@link #getVlmPipelinePreset()}, and cannot be combined with the deprecated {@code vlmPipelineModel*} options. + */ + @JsonProperty("vlm_pipeline_custom_config") + @JsonSetter(nulls = Nulls.AS_EMPTY) + @lombok.Singular("vlmPipelineCustomConfigEntry") + private Map vlmPipelineCustomConfig; + /** * Whether heading hierarchy inference is enabled. Derived from {@link #getHeadingHierarchyOptions()} * — {@code true} when options are present, {@code false} otherwise. diff --git a/docling-serve/docling-serve-api/src/main/java/ai/docling/serve/api/convert/request/options/HeadingHierarchyOptions.java b/docling-serve/docling-serve-api/src/main/java/ai/docling/serve/api/convert/request/options/HeadingHierarchyOptions.java index 436964ea..7daee68f 100644 --- a/docling-serve/docling-serve-api/src/main/java/ai/docling/serve/api/convert/request/options/HeadingHierarchyOptions.java +++ b/docling-serve/docling-serve-api/src/main/java/ai/docling/serve/api/convert/request/options/HeadingHierarchyOptions.java @@ -45,8 +45,7 @@ public class HeadingHierarchyOptions { /** * Fall back to the heading's visual style (font size, weight, slant, letter case) when - * neither bookmarks nor numbering provide a level. Requires {@code generate_parsed_pages=True} - * in the pipeline options. + * neither bookmarks nor numbering provide a level. * * @param useStyle true to use visual style, or null for the default (true) * @return the use-style flag diff --git a/docling-serve/docling-serve-api/src/main/java/ai/docling/serve/api/convert/request/options/OcrEngine.java b/docling-serve/docling-serve-api/src/main/java/ai/docling/serve/api/convert/request/options/OcrEngine.java index 79235f24..38311b38 100644 --- a/docling-serve/docling-serve-api/src/main/java/ai/docling/serve/api/convert/request/options/OcrEngine.java +++ b/docling-serve/docling-serve-api/src/main/java/ai/docling/serve/api/convert/request/options/OcrEngine.java @@ -4,14 +4,24 @@ /** * OCR engines supported by Docling. + * + * @deprecated Only used by the deprecated {@code ConvertDocumentOptions.ocrEngine} option. Select the OCR engine with + * {@code ConvertDocumentOptions.ocrPreset} instead, which takes a preset id registered by the Docling Serve deployment. */ +@Deprecated(since = "0.7.3") public enum OcrEngine { - @JsonProperty("auto") AUTO, - @JsonProperty("easyocr") EASYOCR, - @JsonProperty("ocrmac") OCRMAC, - @JsonProperty("rapidocr") RAPIDOCR, - @JsonProperty("tesserocr") TESSEROCR, - @JsonProperty("tesseract") TESSERACT + @JsonProperty("auto") + AUTO, + @JsonProperty("easyocr") + EASYOCR, + @JsonProperty("ocrmac") + OCRMAC, + @JsonProperty("rapidocr") + RAPIDOCR, + @JsonProperty("tesserocr") + TESSEROCR, + @JsonProperty("tesseract") + TESSERACT } diff --git a/docling-serve/docling-serve-api/src/main/java/ai/docling/serve/api/convert/request/options/PictureDescriptionApi.java b/docling-serve/docling-serve-api/src/main/java/ai/docling/serve/api/convert/request/options/PictureDescriptionApi.java index 2fe493ef..f57a5212 100644 --- a/docling-serve/docling-serve-api/src/main/java/ai/docling/serve/api/convert/request/options/PictureDescriptionApi.java +++ b/docling-serve/docling-serve-api/src/main/java/ai/docling/serve/api/convert/request/options/PictureDescriptionApi.java @@ -21,7 +21,11 @@ * Configuration options for picture description API integration. * This class encapsulates settings for making API calls to describe pictures, * including URL, headers, parameters, timeout, concurrency, and custom prompts. + * + * @deprecated Only used by the deprecated {@code ConvertDocumentOptions.pictureDescriptionApi} option. Use + * {@code ConvertDocumentOptions.pictureDescriptionPreset} or {@code ConvertDocumentOptions.pictureDescriptionCustomConfig} instead. */ +@Deprecated(since = "0.7.3") @JsonInclude(JsonInclude.Include.NON_EMPTY) @lombok.extern.jackson.Jacksonized @lombok.Builder(toBuilder = true) diff --git a/docling-serve/docling-serve-api/src/main/java/ai/docling/serve/api/convert/request/options/PictureDescriptionLocal.java b/docling-serve/docling-serve-api/src/main/java/ai/docling/serve/api/convert/request/options/PictureDescriptionLocal.java index a2053b5a..40f588d2 100644 --- a/docling-serve/docling-serve-api/src/main/java/ai/docling/serve/api/convert/request/options/PictureDescriptionLocal.java +++ b/docling-serve/docling-serve-api/src/main/java/ai/docling/serve/api/convert/request/options/PictureDescriptionLocal.java @@ -12,7 +12,11 @@ /** * Configuration for local picture description generation. * This class contains settings for generating descriptions of pictures using a local model. + * + * @deprecated Only used by the deprecated {@code ConvertDocumentOptions.pictureDescriptionLocal} option. Use + * {@code ConvertDocumentOptions.pictureDescriptionPreset} or {@code ConvertDocumentOptions.pictureDescriptionCustomConfig} instead. */ +@Deprecated(since = "0.7.3") @JsonInclude(JsonInclude.Include.NON_EMPTY) @lombok.extern.jackson.Jacksonized @lombok.Builder(toBuilder = true) diff --git a/docling-serve/docling-serve-api/src/main/java/ai/docling/serve/api/convert/request/options/VlmModelType.java b/docling-serve/docling-serve-api/src/main/java/ai/docling/serve/api/convert/request/options/VlmModelType.java index 1726edaf..9f7a3d91 100644 --- a/docling-serve/docling-serve-api/src/main/java/ai/docling/serve/api/convert/request/options/VlmModelType.java +++ b/docling-serve/docling-serve-api/src/main/java/ai/docling/serve/api/convert/request/options/VlmModelType.java @@ -4,14 +4,24 @@ /** * Local and API models for the VLM pipeline. + * + * @deprecated Only used by the deprecated {@code ConvertDocumentOptions.vlmPipelineModel} option. Use + * {@code ConvertDocumentOptions.vlmPipelinePreset} or {@code ConvertDocumentOptions.vlmPipelineCustomConfig} instead. */ +@Deprecated(since = "0.7.3") public enum VlmModelType { - @JsonProperty("smoldocling") SMOLDOCLING, - @JsonProperty("smoldocling_vllm") SMOLDOCLING_VLLM, - @JsonProperty("granite_vision") GRANITE_VISION, - @JsonProperty("granite_vision_vllm") GRANITE_VISION_VLLM, - @JsonProperty("granite_vision_ollama") GRANITE_VISION_OLLAMA, - @JsonProperty("got_ocr_2") GOT_OCR_2 + @JsonProperty("smoldocling") + SMOLDOCLING, + @JsonProperty("smoldocling_vllm") + SMOLDOCLING_VLLM, + @JsonProperty("granite_vision") + GRANITE_VISION, + @JsonProperty("granite_vision_vllm") + GRANITE_VISION_VLLM, + @JsonProperty("granite_vision_ollama") + GRANITE_VISION_OLLAMA, + @JsonProperty("got_ocr_2") + GOT_OCR_2 } diff --git a/docling-serve/docling-serve-api/src/test/java/ai/docling/serve/api/convert/request/options/ConvertDocumentOptionsTests.java b/docling-serve/docling-serve-api/src/test/java/ai/docling/serve/api/convert/request/options/ConvertDocumentOptionsTests.java index a942db48..1db3cc2a 100644 --- a/docling-serve/docling-serve-api/src/test/java/ai/docling/serve/api/convert/request/options/ConvertDocumentOptionsTests.java +++ b/docling-serve/docling-serve-api/src/test/java/ai/docling/serve/api/convert/request/options/ConvertDocumentOptionsTests.java @@ -1,9 +1,12 @@ package ai.docling.serve.api.convert.request.options; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; import org.junit.jupiter.api.Test; @@ -68,6 +71,119 @@ void convertDocumentOptionsWithoutHeadingHierarchy() { .satisfies(o -> assertThat(o.getHeadingHierarchyOptions()).isNull()); } + @Test + void convertDocumentOptionsWithStagePresets() { + var options = ConvertDocumentOptions.builder() + .layoutPreset("docling_layout_default") + .ocrPreset("tesseract") + .tableStructurePreset("tableformer_v2") + .pictureDescriptionPreset("granite_vision") + .pictureClassificationPreset("document_figure_classifier_v2") + .codeFormulaPreset("default") + .chartExtractionPreset("granite_vision_v4") + .vlmPipelinePreset("granite_docling") + .build(); + + assertThat(options) + .extracting( + ConvertDocumentOptions::getLayoutPreset, ConvertDocumentOptions::getOcrPreset, ConvertDocumentOptions::getTableStructurePreset, ConvertDocumentOptions::getPictureDescriptionPreset, ConvertDocumentOptions::getPictureClassificationPreset, ConvertDocumentOptions::getCodeFormulaPreset, ConvertDocumentOptions::getChartExtractionPreset, ConvertDocumentOptions::getVlmPipelinePreset) + .containsExactly( + "docling_layout_default", "tesseract", "tableformer_v2", "granite_vision", "document_figure_classifier_v2", "default", "granite_vision_v4", "granite_docling"); + } + + @Test + void convertDocumentOptionsPresetsDefaultToNull() { + var options = ConvertDocumentOptions.builder().build(); + + assertThat(options) + .extracting( + ConvertDocumentOptions::getLayoutPreset, ConvertDocumentOptions::getOcrPreset, ConvertDocumentOptions::getTableStructurePreset, ConvertDocumentOptions::getPictureDescriptionPreset, ConvertDocumentOptions::getPictureClassificationPreset, ConvertDocumentOptions::getCodeFormulaPreset, ConvertDocumentOptions::getChartExtractionPreset, ConvertDocumentOptions::getVlmPipelinePreset) + .containsOnlyNulls(); + } + + @Test + void convertDocumentOptionsWithCustomConfigs() { + var options = ConvertDocumentOptions.builder() + .ocrCustomConfig(Map.of("kind", "tesseract", "lang", List.of("eng", "deu"))) + .layoutCustomConfigEntry("kind", "docling_layout_default") + .layoutCustomConfigEntry("keep_empty_clusters", false) + .tableStructureCustomConfig(Map.of("kind", "docling_tableformer", "mode", "fast")) + .chartExtractionCustomConfig(Map.of("chart2csv", true)) + .build(); + + assertThat(options.getOcrCustomConfig()) + .containsEntry("kind", "tesseract") + .containsEntry("lang", List.of("eng", "deu")); + assertThat(options.getLayoutCustomConfig()) + .hasSize(2) + .containsEntry("kind", "docling_layout_default") + .containsEntry("keep_empty_clusters", false); + assertThat(options.getTableStructureCustomConfig()) + .containsEntry("kind", "docling_tableformer") + .containsEntry("mode", "fast"); + assertThat(options.getChartExtractionCustomConfig()) + .containsEntry("chart2csv", true); + } + + @Test + void convertDocumentOptionsCustomConfigsAreImmutable() { + Map ocrConfig = new HashMap<>(Map.of("kind", "easyocr")); + + var options = ConvertDocumentOptions.builder() + .ocrCustomConfig(ocrConfig) + .build(); + + ocrConfig.put("use_gpu", true); + + assertThat(options.getOcrCustomConfig()) + .hasSize(1) + .containsOnlyKeys("kind"); + assertThatThrownBy(() -> options.getOcrCustomConfig().put("use_gpu", true)) + .isInstanceOf(UnsupportedOperationException.class); + } + + @Test + void convertDocumentOptionsWithStandaloneFlags() { + var options = ConvertDocumentOptions.builder() + .doChartExtraction(true) + .includePageImages(true) + .mdCompactTables(true) + .build(); + + assertThat(options) + .extracting( + ConvertDocumentOptions::getDoChartExtraction, ConvertDocumentOptions::getIncludePageImages, ConvertDocumentOptions::getMdCompactTables) + .containsExactly(true, true, true); + } + + @Test + void convertDocumentOptionsStandaloneFlagsDefaultToNull() { + var options = ConvertDocumentOptions.builder().build(); + + assertThat(options) + .extracting( + ConvertDocumentOptions::getDoChartExtraction, ConvertDocumentOptions::getIncludePageImages, ConvertDocumentOptions::getMdCompactTables) + .containsOnlyNulls(); + } + + @Test + void convertDocumentOptionsToBuilderKeepsPresetsAndCustomConfigs() { + var original = ConvertDocumentOptions.builder() + .ocrPreset("easyocr") + .layoutCustomConfigEntry("kind", "docling_layout_default") + .doChartExtraction(true) + .includePageImages(true) + .mdCompactTables(true) + .build(); + + var rebuilt = original.toBuilder().build(); + + assertThat(rebuilt) + .extracting( + ConvertDocumentOptions::getOcrPreset, ConvertDocumentOptions::getLayoutCustomConfig, ConvertDocumentOptions::getDoChartExtraction, ConvertDocumentOptions::getIncludePageImages, ConvertDocumentOptions::getMdCompactTables) + .containsExactly("easyocr", Map.of("kind", "docling_layout_default"), true, true, true); + } + @Test void convertDocumentOptionsToBuilderWithHeadingHierarchy() { var hierarchyOptions = HeadingHierarchyOptions.builder() diff --git a/docling-serve/docling-serve-client/src/test/java/ai/docling/serve/client/AbstractDoclingServeClientTests.java b/docling-serve/docling-serve-client/src/test/java/ai/docling/serve/client/AbstractDoclingServeClientTests.java index d383526c..96b483c7 100644 --- a/docling-serve/docling-serve-client/src/test/java/ai/docling/serve/client/AbstractDoclingServeClientTests.java +++ b/docling-serve/docling-serve-client/src/test/java/ai/docling/serve/client/AbstractDoclingServeClientTests.java @@ -1502,6 +1502,134 @@ void shouldInferHeadingHierarchyFromPdfNumbering() { .anyMatch(h -> "3.1 PDFbackends".equals(h.getText()) && (h.getLevel() >= 2)); } + @Test + void shouldConvertWithStagePresets() { + // "default" resolves to the deployment-controlled preset for each stage. Other ids from the + // server's schema examples (docling_layout_default, tableformer_v2, ...) are not registered + // in every Docling Serve build, so they would make this test depend on the image. + var convOptions = ConvertDocumentOptions.builder() + .toFormat(OutputFormat.MARKDOWN) + .layoutPreset("default") + .ocrPreset("easyocr") + .tableStructurePreset("default") + .pictureClassificationPreset("default") + .pageRange(List.of(1, 1)) + .build(); + + var request = ConvertDocumentRequest.builder() + .options(convOptions) + .build(); + + var response = getDoclingClient().convertFiles(request, Path.of("src", "test", "resources", "2408.09869.pdf")); + + assertThat(response) + .isNotNull() + .extracting(ConvertDocumentResponse::getResponseType) + .isEqualTo(ResponseType.IN_BODY); + + var inBodyResponse = (InBodyConvertDocumentResponse) response; + + assertThat(inBodyResponse.getStatus()).isNotEmpty(); + assertThat(inBodyResponse.getDocument().getMarkdownContent()).isNotEmpty(); + } + + @Test + void shouldIncludePageImagesWhenRequested() { + var convOptions = ConvertDocumentOptions.builder() + .toFormat(OutputFormat.JSON) + .imageExportMode(ImageRefMode.EMBEDDED) + .includePageImages(true) + .pageRange(List.of(1, 1)) + .build(); + + var request = ConvertDocumentRequest.builder() + .options(convOptions) + .build(); + + var response = getDoclingClient().convertFiles(request, Path.of("src", "test", "resources", "2408.09869.pdf")); + + var doc = ((InBodyConvertDocumentResponse) response).getDocument().getJsonContent(); + + assertThat(doc).isNotNull(); + assertThat(doc.getPages()) + .as("The converted document should expose at least one page") + .isNotEmpty(); + assertThat(doc.getPages().values()) + .as("include_page_images should attach a full-page image to every page") + .isNotEmpty() + .allSatisfy(page -> assertThat(page.getImage()).isNotNull()); + } + + @Test + void shouldNotIncludePageImagesByDefault() { + var convOptions = ConvertDocumentOptions.builder() + .toFormat(OutputFormat.JSON) + .imageExportMode(ImageRefMode.EMBEDDED) + .pageRange(List.of(1, 1)) + .build(); + + var request = ConvertDocumentRequest.builder() + .options(convOptions) + .build(); + + var response = getDoclingClient().convertFiles(request, Path.of("src", "test", "resources", "2408.09869.pdf")); + + var doc = ((InBodyConvertDocumentResponse) response).getDocument().getJsonContent(); + + assertThat(doc).isNotNull(); + assertThat(doc.getPages()) + .as("The converted document should expose at least one page") + .isNotEmpty(); + assertThat(doc.getPages().values()) + .as("Page images should be absent when include_page_images is not set") + .allSatisfy(page -> assertThat(page.getImage()).isNull()); + } + + @Test + void shouldEmitCompactMarkdownTablesWhenRequested() { + var padded = convertTableToMarkdown(null); + var compact = convertTableToMarkdown(true); + + assertThat(padded) + .as("The fixture should convert to a markdown table") + .contains("|"); + assertThat(compact).contains("|"); + + // A padded table widens every cell to a common column width, which shows up most reliably in + // the header separator row: "|-----------|" when padded, "| - |" when compact. Asserting on + // the padding of the cells themselves is not safe, because it depends on the column + // alignment the table happens to use. + assertThat(padded) + .as("The default markdown table format pads the header separator with runs of dashes") + .containsPattern("-{3,}"); + assertThat(compact) + .as("md_compact_tables should collapse the header separator to single dashes") + .doesNotContainPattern("-{3,}"); + assertThat(compact.length()) + .as("A compact table should be shorter than the padded one") + .isLessThan(padded.length()); + } + + private String convertTableToMarkdown(@Nullable Boolean compactTables) { + var convOptions = ConvertDocumentOptions.builder() + .toFormat(OutputFormat.MARKDOWN) + .mdCompactTables(compactTables) + .build(); + + var request = ConvertDocumentRequest.builder() + .options(convOptions) + .build(); + + // 2408.09869.pdf is a two-page excerpt with no tables, so this uses the page of the same + // paper that carries the CPU benchmark table. + var response = getDoclingClient().convertFiles(request, Path.of("src", "test", "resources", "2408.09869-table.pdf")); + var markdown = ((InBodyConvertDocumentResponse) response).getDocument().getMarkdownContent(); + + assertThat(markdown).isNotEmpty(); + + return markdown; + } + @Test void shouldHandleResponseWithDoclingDocument() { ConvertDocumentOptions options = ConvertDocumentOptions.builder() diff --git a/docling-serve/docling-serve-client/src/test/resources/2408.09869-table.pdf b/docling-serve/docling-serve-client/src/test/resources/2408.09869-table.pdf new file mode 100644 index 00000000..1b4f536b Binary files /dev/null and b/docling-serve/docling-serve-client/src/test/resources/2408.09869-table.pdf differ diff --git a/docs/src/doc/docs/docling-serve/serve-api.md b/docs/src/doc/docs/docling-serve/serve-api.md index e7779a1b..0213512d 100644 --- a/docs/src/doc/docs/docling-serve/serve-api.md +++ b/docs/src/doc/docs/docling-serve/serve-api.md @@ -181,8 +181,84 @@ Options (`ai.docling.serve.api.convert.request.options.ConvertDocumentOptions`) - Pipelines and page ranges (e.g., `pipeline`, `pageRange`) - Timeouts and error behavior (e.g., `documentTimeout`, `abortOnError`) - Enrichments (code/formula/picture), image handling, scaling, page break placeholder +- Chart extraction (e.g., `doChartExtraction`) +- Full-page images and compact markdown tables (e.g., `includePageImages`, `mdCompactTables`) +- Per-stage presets and custom configurations (see below) - VLM pipeline hints +#### Per-stage presets and custom configurations + +Each pipeline stage can be tuned either by naming a server-side *preset* or by supplying a *custom +configuration*. The two are mutually exclusive per stage — setting both makes Docling Serve reject +the request. + +| Stage | Preset | Custom configuration | +|---|---|---| +| Layout | `layoutPreset` | `layoutCustomConfig` | +| OCR | `ocrPreset` | `ocrCustomConfig` | +| Table structure | `tableStructurePreset` | `tableStructureCustomConfig` | +| Picture description | `pictureDescriptionPreset` | `pictureDescriptionCustomConfig` | +| Picture classification | `pictureClassificationPreset` | `pictureClassificationCustomConfig` | +| Code & formula | `codeFormulaPreset` | `codeFormulaCustomConfig` | +| Chart extraction | `chartExtractionPreset` | `chartExtractionCustomConfig` | +| VLM pipeline | `vlmPipelinePreset` | `vlmPipelineCustomConfig` | + +Presets are plain strings, because the available ids are determined by the Docling Serve deployment +rather than by this library. `"default"` selects the deployment-controlled default for a stage, +where the deployment registers one, and is usually the safest choice; `ocrPreset` additionally +accepts engine ids such as `"easyocr"`. + +!!! warning + Not every id in the server's OpenAPI `examples` is registered in every Docling Serve build, and + that includes `"default"` — it is not guaranteed for every stage. On `v1.35.0`, for instance, + `layoutPreset("docling_layout_default")`, `tableStructurePreset("tableformer_v2")` and + `codeFormulaPreset("default")` are rejected with `Unknown ... preset`, and + `ocrPreset("tesseract")` fails unless Tesseract is installed in the image. Check what your + deployment registers before relying on any particular id. + +A custom configuration is a `Map` and is an alternative to the stage's preset, not a +modifier applied on top of one. Its schema is stage-specific, and the eight stages split into two +groups: + +| Group | Stages | Shape | +|---|---|---| +| Kind-selected | Layout, OCR, table structure, picture classification | A `kind` entry selects the implementation, and the remaining entries are that implementation's own settings | +| VLM-backed | Picture description, code & formula, chart extraction, VLM pipeline | `model_spec` and `engine_options` entries, plus any stage-specific flags — no `kind` | + +Builders accept either the whole map or one entry at a time: + +```java +ConvertDocumentOptions options = ConvertDocumentOptions.builder() + .ocrPreset("easyocr") + .layoutCustomConfigEntry("kind", "docling_layout_default") + .layoutCustomConfigEntry("keep_empty_clusters", false) + .tableStructureCustomConfig(Map.of("kind", "docling_tableformer", "mode", "fast")) + .build(); +``` + +A VLM-backed stage takes the model and the engine instead: + +```java +ConvertDocumentOptions options = ConvertDocumentOptions.builder() + .doChartExtraction(true) + .chartExtractionCustomConfigEntry("model_spec", Map.of( + "name", "Granite-Vision-4.1-4B", + "default_repo_id", "ibm-granite/granite-vision-4.1-4b", + "prompt", "", + "response_format", "plain text")) + .chartExtractionCustomConfigEntry("engine_options", Map.of("engine_type", "api_lmstudio")) + .chartExtractionCustomConfigEntry("chart2csv", true) + .build(); +``` + +!!! note + The preset and custom-config options supersede `ocrEngine`, `pictureDescriptionLocal`, + `pictureDescriptionApi` and the `vlmPipelineModel*` options, which Docling Serve marks as + deprecated. These are annotated `@Deprecated` in `docling-java` too, so using one produces a + compiler warning. They are not marked for removal: when they go depends on Docling Serve, not + on this library. A deprecated option cannot be combined with the preset or custom config for + the same stage. + Explore the `options` package for the full list of knobs you can turn. ### Responses: `InBodyConvertDocumentResponse`, `PreSignedUrlConvertDocumentResponse`, `PreSignedUrlConvertResponse`, `ZipArchiveConvertDocumentResponse`, and `DocumentResponse` diff --git a/docs/src/doc/docs/whats-new.md b/docs/src/doc/docs/whats-new.md index dea3be4e..96392b1e 100644 --- a/docs/src/doc/docs/whats-new.md +++ b/docs/src/doc/docs/whats-new.md @@ -26,6 +26,9 @@ Docling Java {{ gradle.project_version }} includes important breaking changes, a ### {{ gradle.project_version }} +* **Per-stage presets and custom configurations on `ConvertDocumentOptions`** — Eight pipeline stages (layout, OCR, table structure, picture description, picture classification, code & formula, chart extraction and the VLM pipeline) can now be tuned from Java, each through a `Preset` string or a `CustomConfig` map, for example `ocrPreset("easyocr")` or `layoutCustomConfigEntry("kind", "docling_layout_default")`. Presets are plain strings because the available ids are set by the Docling Serve deployment, so not even `"default"` is registered for every stage on every image. A custom config is a `Map` with a stage-specific schema, in one of two shapes: the kind-selected stages (layout, OCR, table structure, picture classification) pick an implementation through a `kind` entry, while the VLM-backed stages (picture description, code & formula, chart extraction, VLM pipeline) take `model_spec` and `engine_options` entries instead. The preset and the custom config are mutually exclusive per stage — a custom config replaces the preset rather than overriding it. These supersede `ocrEngine`, `pictureDescriptionLocal`, `pictureDescriptionApi` and the `vlmPipelineModel*` options, which Docling Serve marks as deprecated. +* **The options Docling Serve deprecates are now `@Deprecated` in Java** — `ocrEngine`, `pictureDescriptionLocal`, `pictureDescriptionApi`, `vlmPipelineModel`, `vlmPipelineModelLocal` and `vlmPipelineModelApi` carry `@Deprecated(since = "0.7.3")`, which Lombok copies onto both the getter and the builder setter, so setting one produces a compiler warning pointing at the preset or custom-config replacement. They are deliberately **not** marked `forRemoval`: these options still work, and when they are removed is Docling Serve's decision rather than this library's. The four types that are only reachable through those options — `OcrEngine`, `VlmModelType`, `PictureDescriptionLocal` and `PictureDescriptionApi` — are marked `@Deprecated` as well, so the warning also appears at `PictureDescriptionApi.builder()` rather than only at the setter. +* **New `doChartExtraction`, `includePageImages` and `mdCompactTables` options** — `doChartExtraction` extracts numeric data from charts, which had no workaround before. `includePageImages` generates full-page images, independently of `includeImages`, which covers picture elements only. `mdCompactTables` emits markdown tables without column padding, which is better for large tables and downstream processing. All three default to `false` on the server. * **New `bearerToken` option** — `DoclingServeApi.builder().bearerToken(token)` sends `Authorization: Bearer ` on every request, for a `docling-serve` behind a proxy that authenticates on bearer tokens, such as the [`oauth-proxy` deployment](https://github.com/docling-project/docling-serve/blob/main/docs/deployment.md#secure-deployment-with-oauth-proxy). It is independent of `apiKey` (sent as `X-Api-Key`), so both can be set. The token is masked when request logging is enabled. Legacy `DoclingServeApiBuilderFactory` implementations don't support it and fail if it is set. * **A failed async task reports the reason given by Docling Serve** — When an async conversion or chunking task failed, the exception only showed the task metadata, which holds document counts, so the cause of the failure was lost. `TaskStatusPollResponse` now has an `errorMessage` field, mapped from the `error_message` that Docling Serve returns, and the exception message includes it when it is present. How much detail that message carries depends on the server's error-sanitization setting: by default Docling Serve reports a generic `Internal processing error.` for most infrastructure failures, and the underlying exception text only when it is started with `DOCLING_SERVE_DEBUG_ERROR_DETAILS=true`. * **New `HeadingHierarchyOptions` and `headingHierarchyOptions` on `ConvertDocumentOptions`** — When set, `headingHierarchyOptions` enables PDF section-header level inference from bookmarks, outline numbering and visual style. The helper getter `doPdfHeadingHierarchy()` is derived from the presence of these options (returns `true` when non-null, `false` otherwise), so callers only need to pass the options to enable hierarchy inference. The options class covers all docling-serve fields (`useBookmarks`, `useNumbering`, `useStyle`, `useFontStyle`, `styleSizeTolerance`, `numberingSchemes`, `maxLevel`, `bookmarkMatchThreshold`).