Claus Ibsen created CAMEL-26205:
-----------------------------------
Summary: 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
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)