docling-java icon indicating copy to clipboard operation
docling-java copied to clipboard

[Improvement] Support convert-side chunking (chunking_preset / chunking_options)

Open edeandrea opened this issue 1 day ago • 0 comments

Description

ConvertDocumentsOptions exposes chunking_preset and chunking_options, letting the convert endpoints chunk a document in the same pass that converts it, instead of converting and then sending the result back to /chunk. docling-java maps neither.

These were listed in #819 and deliberately deferred, because mapping the two request properties on their own would produce inert setters. Making the feature usable needs three changes together.

What the server actually does

The two options are only the chunker configuration. The trigger is "chunks" in to_formats — from docling_jobkit/convert/results_processor.py:

#   a) "chunks" is listed in to_formats, OR
#   b) at least one processor declares it requires chunk records
self._chunks_in_formats: bool = (to_formats is not None and "chunks" in to_formats)
self._chunk_active: bool = self._chunks_in_formats or any(
    _processor_requires_chunks(p) for p in target_processors
)

Chunks are written to chunks/{name}.chunks.jsonl, and the result comes back as a ChunkedDocumentResult, which is a member of the ResultType union that a convert task carries:

ResultType = Annotated[
    ExportResult | ZipArchiveResult | RemoteTargetResult
    | ChunkedDocumentResult | PresignedArtifactResult,
    Field(discriminator="kind"),
]

So convert-side chunking is reachable in-body, as kind: "ChunkedDocumentResponse" with chunks + documents, as well as via a presigned target's chunks artifact.

Note that on a chunk request the server clears these fields from the nested convert options, so they only ever apply to the convert path:

@field_validator("convert_options", mode="after")
def sync_convert_chunking_options(cls, value: ConvertDocumentsOptions):
    value.chunking_options = None
    value.chunking_preset = None

Work needed

  1. chunkingPreset (String) and chunkingOptions (the existing ChunkerOptions, whose chunker discriminator already matches the server's oneOf) on ConvertDocumentOptions, mutually exclusive.
  2. OutputFormat.CHUNKS — without it a Java caller cannot trigger chunking at all. Tracked more broadly in the OutputFormat gap issue.
  3. A response type for the chunked convert shape, plus dispatch for it in Jackson2ConvertDocumentResponseDeserializer / Jackson3ConvertDocumentResponseDeserializer. The current dispatch tests documents first:
if (node.has("documents")) {
  return mapper.treeToValue(node, PreSignedUrlConvertResponse.class);

A ChunkedDocumentResponse also has documents, but as ExportResult rather than DocumentArtifactItem, so it would route to the wrong subtype and drop chunks. (Read from the code; not yet confirmed against a running server.)

Verified against

docling-serve v1.35.0–v1.41.0 (ConvertDocumentsOptions is identical across that range), docling 2.155.0, docling-jobkit main.

edeandrea avatar Dec 01 '26 15:12 edeandrea