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

image_export_mode=referenced returns image paths, but image files are missing

Open madhukargunda opened this issue 11 months ago • 9 comments

1).When using:

"image_export_mode": "referenced", "do_picture_description": true

the response correctly includes the image references/paths, but the actual exported image files are not present in the output. This makes it impossible to retrieve or post-process the images afterward.

Could you clarify whether the images are supposed to be included in the response payload, or if there is an endpoint/mechanism to fetch the extracted images separately? If not, please consider adding support for exporting or retrieving the referenced images.

Syntax :(e.g., ![Image](path/to/image.png))

Image
  1. .I’ve noticed that when enabling picture descriptions, the extracted image descriptions (generated via OpenAI on my side) are not being inserted or replaced in the final document output. The API returns the descriptions correctly, but the processed Markdown/PDF does not contain them.

In most cases the image nodes remain unchanged, and the description is never amended. This also leads to unnecessary token usage on the LLM side, as the generated descriptions are never reflected in the final result.

Could you clarify how the picture description insertion is handled, and whether any additional configuration is required to ensure the descriptions are merged into the response?

requesting you include some java samples covering this scenario or share same knowledge here i will prepare some examples for community use.

below is the sample prepared (extracted my java code)

{
  "options": {
    "to_formats": ["md"],
    "do_picture_description": true,
    "image_export_mode": "referenced",
    "include_images": "true",
    "picture_description_api": {
      "url": "https://api.openai.com/v1/chat/completions",
      "headers": {"Authorization": "Bearer {{OPEN_AI_KEY}}"},
      "params": {"model": "gpt-5", "max_completion_tokens": 1000},
      "prompt": "Provide a comprehensive and detailed description of the image, including all visible objects, text, layout, context, and any relevant visual details.",
      "timeout": "90"
    },
    "picture_description_area_threshold": 0.0
  }, 
  "sources": [{"kind": "http", "url": "https://arxiv.org/pdf/2408.09869"}]
}

madhukargunda avatar Dec 12 '25 17:12 madhukargunda

@ThomasVitale are you able to take a look at this?

edeandrea avatar Dec 13 '25 14:12 edeandrea

@edeandrea yes, I'll have a look

ThomasVitale avatar Dec 13 '25 15:12 ThomasVitale

@edeandrea Can I take up this issue ?

ArpanKrChakraborty avatar Mar 01 '26 18:03 ArpanKrChakraborty

@ArpanKrChakraborty its all yours!

edeandrea avatar Mar 02 '26 13:03 edeandrea

@ArpanKrChakraborty if there isn't a test case which would catch this issue (most likely there isn't), please add a test case for it as well.

edeandrea avatar Mar 02 '26 13:03 edeandrea

Issue: Missing Exported Images in docling-java Convert API Response Note: I am targeting the first bug mentioned in the issue description for now. Problem Statement When invoking DoclingServeConvertApi.convertSource() with image export enabled (image_export_mode: "referenced"), the response correctly includes image references in the markdown output, but the actual exported image files are missing. Request Configuration:

{
  "options": {
    "to_formats": ["md"],
    "do_picture_description": true,
    "image_export_mode": "referenced",
    "include_images": "true",
    "picture_description_api": { ... },
    "picture_description_area_threshold": 0.0
  }, 
  "sources": [{"kind": "http", "url": "https://arxiv.org/pdf/2408.09869"}]
}

Root Cause Analysis The issue stems from how docling-serve handles different target types:

  • Default behavior: When ConvertDocumentRequest.target is null, docling-serve defaults to an in-body target, which returns only the converted content without exported image files.
  • Required behavior: To retrieve exported images, ConvertDocumentRequest.target must be set to ZipTarget, which returns a Response with MIME type application/zip containing the images in an artifacts/ folder.

Current Bug: docling-java does not handle the application/zip MIME type response from docling-serve.

Proposed Solution - docling-serve's convert APIs can return three distinct response types:

  1. ConvertDocumentResponse - Single document processed with in-body target
  2. application/zip Response - Multiple documents processed OR zip target
  3. PreSignedUrlConvertDocumentResponse - PutTarget or S3Target used as target

Proposed Type Hierarchy:

Refactor ConvertDocumentResponse as a base type with three concrete implementations:

  • InBodyConvertDocumentResponse (handles type 1) - new
  • ZipArchiveConvertDocumentResponse (handles type 2) - new
  • PreSignedUrlConvertDocumentResponse (handles type 3) - new

Breaking Change Consideration This solution introduces a breaking change requiring client code modifications: Current Code:

// Assumes in-body target response
ConvertDocumentResponse response = client.convertSource(convertDocumentRequest);

Updated Code:

ConvertDocumentResponse genericResponse = client.convertSource(convertDocumentRequest);
if (genericResponse instanceof InBodyTargetConvertDocumentResponse response) {
    // Existing logic continues here
} else if (genericResponse instanceof ZipArchiveConvertDocumentResponse zipResponse) {
    // Handle zip archive with exported images
} else if (genericResponse instanceof PreSignedUrlConvertDocumentResponse urlResponse) {
    // Handle pre-signed URL response
}

Questions for Discussion

  1. Is this breaking change acceptable for the project, or should we explore backward-compatible alternatives?
  2. An alternative backward-compatible approach would be to extend ConvertDocumentResponse with additional fields, such as an InputStream field to capture the ZIP stream for application/zip responses from docling-serve.

@edeandrea @ThomasVitale - I would greatly appreciate your input and guidance on the preferred approach before proceeding with implementation. I'm also happy to connect on Discord/Slack for further discussion if that would be helpful.

ArpanKrChakraborty avatar Mar 04 '26 13:03 ArpanKrChakraborty

Hi @ArpanKrChakraborty sorry for the delay in getting back to you. I've been out of the office.

Thank you for the detailed analysis. Indeed you are correct - there are 3 potential return types

Image Image

I think your proposed solution with the breaking change is the best solution. I think we're still at an infancy stage (i.e. before a 1.0 release) where we can make breaking changes.

I'd also add a getResponseType() method to ConvertDocumentResponse with an enumeration for the various types. That way consumers could switch on the enumeration rather than doing instanceof checks, which aren't as performant.

@ThomasVitale what do you think?

edeandrea avatar Mar 06 '26 02:03 edeandrea

@edeandrea Added an implementation of the changes discussed above.

ArpanKrChakraborty avatar Mar 08 '26 21:03 ArpanKrChakraborty

🎉 This issue has been resolved in v0.5.0 (Release Notes)

docling-java-ops[bot] avatar Mar 19 '26 20:03 docling-java-ops[bot]