Claus Ibsen created CAMEL-27202:
-----------------------------------

             Summary: camel-docling - ocrLanguage ignored with docling-serve 
unless doOcr is set
                 Key: CAMEL-27202
                 URL: https://issues.apache.org/jira/browse/CAMEL-27202
             Project: Camel
          Issue Type: Bug
          Components: camel-docling
            Reporter: Claus Ibsen


When converting through docling-serve, the endpoint option {{ocrLanguage}} is 
only sent when {{doOcr}} is set to true. With the default ({{doOcr}} unset, 
{{enableOCR=true}}) the server does OCR with its own default languages and the 
configured {{ocrLanguage}} is silently dropped. The per-message header 
{{CamelDoclingOCRLanguage}} behaves differently: it turns {{doOcr}} on when it 
is unset ("asking for a language is asking for OCR"), so the header works and 
the endpoint option does not.

h3. How to reproduce
{noformat}
docling:convert?operation=CONVERT_TO_MARKDOWN&useDoclingServe=true&doclingServeUrl=http://localhost:5001&ocrLanguage=xx
{noformat}
The conversion succeeds; {{ocr_lang}} is not in the request (an unknown 
language would fail on the server). With {{doOcr=true&ocrLanguage=xx}} the 
server fails, as expected, because there is no model for {{xx}}. Tested against 
docling-serve v1.38.2.

h3. Where
{{components/camel-ai/camel-docling/src/main/java/org/apache/camel/component/docling/DoclingProducer.java}}:
* {{resolveOcrSettings(Exchange)}}: {{doOcr}} stays {{null}} for the endpoint 
{{ocrLanguage}}; only the header sets it to TRUE.
* {{applyConfigurationToOptions(...)}}: {{ocrLang}} is set only inside {{if 
(doOcr != null) ... if (doOcr && ...)}}.

The reason is that {{ocrLanguage}} has a default ({{en}}), so the producer 
cannot tell a configured language from the default, and sending {{en}} always 
would override the server default.

h3. Suggested fix
Track whether {{ocrLanguage}} was configured (for example remove the {{en}} 
default from the docling-serve path, or keep a null default and use {{en}} only 
for the CLI), and when it is configured and {{enableOCR}} is not false, send 
{{do_ocr=true}} and {{ocr_lang}}, the same way as the header. At least the 
option description should say that it needs {{doOcr=true}} with docling-serve.

h3. Related: the error of a failed conversion is lost in sync mode
When docling-serve fails a conversion (for example OCR with an unknown 
language, or {{ocrEngine=OCRMAC}} on Linux), the sync call 
({{useAsyncMode=false}}, the default) fails with:
{noformat}
Failed to convert document: An error occurred: {"detail":"Task result not 
found. Please wait for a completion status."}
{noformat}
That 404 text comes from the docling-serve sync endpoint, and the real cause is 
only in the server log. In async mode the docling-java client polls the task 
status and reports {{Async conversion failed for task ...: <error>}}. It would 
help if the sync path recognised this answer and said that the conversion 
failed on the server (pointing to the server log or to {{useAsyncMode=true}} 
for the error text), rather than "Task result not found".

Found while adding OCR options to the {{docling-convert-action}} Kamelet; it 
maps one option to both {{enableOCR}} and {{doOcr}} to work around this.



--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

Reply via email to