[
https://issues.apache.org/jira/browse/CAMEL-26205?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18137013#comment-18137013
]
Claus Ibsen commented on CAMEL-26205:
-------------------------------------
Decision for this issue, applied in PR
https://github.com/apache/camel/pull/29032 (commit 48db06428a69): the producer
embeds only text. A body, and each element of a List body, must be a
TextSegment, text, bytes, a stream, a Reader or a file (CharSequence, byte[],
ByteBuffer, InputStream, Reader, StreamCache, ByteArrayOutputStream, File,
Path, WrappedFile), which is read as text; a type converter to TextSegment is
still used when there is one. Any other body or List element, such as a Map or
a POJO, fails with InvalidPayloadException and a hint to convert the body to
text first (convertBodyTo(String) or a marshal to JSON), instead of being
embedded as its toString(). This is the same rule as camel-langchain4j-ingest
(CAMEL-26206). The body types and the component page say so.
_Claude Code on behalf of Claus Ibsen (davsclaus)_
> camel-langchain4j-embeddings - bytes, stream and file bodies cannot be
> embedded, and a stale EMBEDDINGS header sends a later ADD to the batch path
> --------------------------------------------------------------------------------------------------------------------------------------------------
>
> Key: CAMEL-26205
> URL: https://issues.apache.org/jira/browse/CAMEL-26205
> Project: Camel
> Issue Type: Bug
> Components: camel-langchain4j-embeddings
> Reporter: Claus Ibsen
> Assignee: Claus Ibsen
> Priority: Minor
> Fix For: 4.24.0
>
>
> Found while adding the catalog body types of langchain4j-embeddings
> (CAMEL-24961, PR #28401).
> h4. 1. Only a String converts to a TextSegment: bytes, streams and files fail
> {{LangChain4jEmbeddingsProducer.processSingle}} (main 2a465aa4814c, line 67)
> reads the body with {{getMandatoryBody(TextSegment.class)}}, and
> {{LangChain4jEmbeddingsConverter}} (line 32) converts only a {{String}}. A
> {{byte[]}}, {{InputStream}} or file consumer body ({{GenericFile}}) fails
> with a no type conversion error, so a
> {{from("file:...").to("langchain4j-embeddings:...")}} route needs a
> {{convertBodyTo(String.class)}}. Checked on 4.24.0-SNAPSHOT with
> AllMiniLmL6V2.
> Proposed: read the body as a String (the type converter handles bytes,
> streams and files) before building the {{TextSegment}}.
> h4. 2. The single-text path does not clear a stale EMBEDDINGS header
> {{processSingle}} sets {{EMBEDDING}}, {{VECTOR}} and {{TEXT_SEGMENT}} (lines
> 142-144) but leaves an {{EMBEDDINGS}} header from an earlier batch call in
> the same exchange (set at line 164). A later langchain4j-embeddingstore ADD
> checks {{EMBEDDINGS}} first and takes the batch path, storing the old batch
> instead of the new embedding. Read in the code, not run.
> Proposed: remove {{EMBEDDINGS}} and {{TEXT_SEGMENTS}} in the single path (and
> {{EMBEDDING}}/{{TEXT_SEGMENT}} in the batch path).
> h4. 3. The RESPONSE_MODEL header is declared but never set
> {{LangChain4jEmbeddingsHeaders.RESPONSE_MODEL}} (line 39,
> {{CamelLangChain4jEmbeddingsResponseModel}}) is documented as a header of the
> component, but the producer never sets it (it sets only {{REQUEST_MODEL}},
> lines 129 and 150). Read in the code, not run.
> Proposed: set it when the response exposes a model name, or remove it from
> the documented headers.
> h4. 4. The TEXT_SEGMENT header javaType has a leading space
> {{LangChain4jEmbeddingsHeaders}} (line 52) and {{LangChain4jEmbeddings}}
> (line 53) declare {{javaType = " dev.langchain4j.data.segment.TextSegment"}}
> with a leading space, which ends up in the catalog metadata. Read in the
> code, not run.
> Proposed: remove the leading space and regenerate.
> _Claude Code on behalf of davsclaus_
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)