[ 
https://issues.apache.org/jira/browse/CAMEL-26205?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18136908#comment-18136908
 ] 

Claus Ibsen commented on CAMEL-26205:
-------------------------------------

PR: https://github.com/apache/camel/pull/29032

Fixed in the PR: (1) bytes, stream and file bodies, and such elements of a List 
body, are read as text; a TextSegment and a TextSegment type converter still 
win. (2) Each call removes the result headers of an earlier call, so a single 
text after a batch no longer leaves EMBEDDINGS behind for a later 
embeddingstore ADD. (4) The leading space of the TEXT_SEGMENT javaType is gone 
and the catalog is regenerated.

Not fixed: (3) RESPONSE_MODEL. The producer calls the legacy embed(TextSegment) 
/ embedAll(List) API, and in LangChain4j 1.23 that Response drops the model 
name. Getting it needs a switch to embed(EmbeddingRequest) and 
EmbeddingResponse.modelName(), which changes which model method is called 
(models or mocks that override only embed(TextSegment) would be bypassed) and 
has no finish reason. Options: a) switch to embed(EmbeddingRequest) and set 
RESPONSE_MODEL (recommended, as its own JIRA); b) deprecate the header and drop 
it from the docs; c) leave it.

_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)

Reply via email to