[
https://issues.apache.org/jira/browse/CAMEL-26553?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18150668#comment-18150668
]
Karol Krawczyk commented on CAMEL-26553:
----------------------------------------
Investigation and fix for CAMEL-26553:
- Confirmed: spring-ai-embeddings (since CAMEL-26512) and
langchain4j-embeddings (since CAMEL-26205) accepted only a fixed list of types.
So a char[], a Netty ByteBuf, a custom type with its own converter to String,
and a List with such an element all failed. Before CAMEL-26512, spring-ai
converted every element with the type converter. Before CAMEL-26205,
langchain4j-embeddings used getMandatoryBody(TextSegment.class), so it never
embedded these.
- One correction to the description: the fallback is not promoted.
CoreTypeConverterRegistry caches ToStringTypeConverter for the (from,to) pair
before it checks canPromote, so a lookup returns it anyway. The conclusion
holds: a converter lookup cannot tell a real converter from the fallback.
The fix uses the rule from camel-ibm-watsonx-ai (CAMEL-26521) and
camel-alibaba-kms (CAMEL-27035). The value is read with the type converter, and
it fails only when all three hold:
- BodyFacts.kindOf is not PAYLOAD,
- it is not a UUID, URI, URL, java.time value, Date or ByteArrayOutputStream,
- the text equals its toString().
ByteArrayOutputStream, the body camel-tika parse produces, has to be named
explicitly. Its toString() decodes the same bytes the converter reads, so the
text comparison alone would reject it.
The rule is applied per element for a List. A Map, a POJO, a Set and an array
of texts still fail without calling the model. The message says to marshal
first, or to use convertBodyTo(String.class). In spring-ai a number is embedded
as its text again, as before CAMEL-26512.
Known follow-up: camel-langchain4j-embeddingstore (auto-embedding) and
camel-langchain4j-ingest still use the fixed list, so they still fail a char[],
a ByteBuf or a custom converter. They need the same change.
_Reported by Claude Code on behalf of Karol Krawczyk_
> camel-spring-ai-embeddings and camel-langchain4j-embeddings - embed bodies
> that have a real converter to String, such as char[] and ByteBuf
> -------------------------------------------------------------------------------------------------------------------------------------------
>
> Key: CAMEL-26553
> URL: https://issues.apache.org/jira/browse/CAMEL-26553
> Project: Camel
> Issue Type: Improvement
> Reporter: Claus Ibsen
> Priority: Minor
>
> Found in the review of CAMEL-26512 (PR #29108).
> camel-spring-ai-embeddings (with CAMEL-26512) and
> camel-langchain4j-embeddings
> ({{LangChain4jEmbeddingsProducer.isReadableAsText}}) only embed a body of a
> fixed list of text types, and fail other bodies. Bodies that have a real
> converter to String fail too, while before CAMEL-26512 spring-ai embedded
> them:
> * {{char[]}}
> * a Netty {{ByteBuf}} (netty-http with {{disableStreamCache=true}})
> * a custom type with its own converter to String
> * a List with such an element
> Asking the type converter does not tell them apart from a Map or POJO: after
> one fallback conversion, {{lookup(String.class, X.class)}} returns the
> promoted {{ToStringTypeConverter}}. {{BodyFacts.kindOf}} does not help either
> (ByteBuf is DATA, char[] is COLLECTION, Integer is PAYLOAD).
> Today the workaround is {{convertBodyTo(String.class)}} before the endpoint
> (in the 4.24 upgrade guide). Proposed: widen the accepted types in both
> components the same way, e.g. CharSequence, char[], and bodies whose
> converter to String is not the toString fallback.
> _Claude Code on behalf of Claus Ibsen (davsclaus)_
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)