davsclaus opened a new pull request, #29032: URL: https://github.com/apache/camel/pull/29032
Fixes [CAMEL-26205](https://issues.apache.org/jira/browse/CAMEL-26205). ### 1. Bytes, stream and file bodies could not be embedded The producer read the body with `getMandatoryBody(TextSegment.class)`, and `LangChain4jEmbeddingsConverter` converts only a `String`. A `byte[]`, `InputStream` or file consumer body (`GenericFile`) failed with a no type conversion error, so `from("file:...").to("langchain4j-embeddings:...")` needed a `convertBodyTo(String.class)`. The batch path had the same problem for each element of a `List` body. Now a body, and each element of a `List` body, goes through one helper: a `TextSegment` is used as is, a type converter to `TextSegment` is used when there is one (so a custom converter still wins), and anything else is read as text with the exchange charset. No body still fails with `InvalidPayloadException`. ### 2. A stale `EMBEDDINGS` header sent a later ADD to the batch path The single path set `EMBEDDING`, `VECTOR` and `TEXT_SEGMENT` but left an `EMBEDDINGS` header from an earlier batch call on the same exchange. `langchain4j-embeddingstore` ADD checks `EMBEDDINGS` first, so it stored the old batch instead of the new embedding. The batch path also left the single headers behind. Now each call removes the result headers of an earlier call before it sets its own: the batch and single headers, and also the token counts, the finish reason and the request model (those are only set when the response has them, so they could be stale in the same way). ### 4. `TEXT_SEGMENT` header javaType had a leading space `" dev.langchain4j.data.segment.TextSegment"` in `LangChain4jEmbeddingsHeaders` and the deprecated `LangChain4jEmbeddings.Headers`. Fixed and regenerated (component JSON, catalog JSON, endpoint DSL javadoc). ### 3. `RESPONSE_MODEL` is declared but never set: not changed (open question) The producer calls the legacy `EmbeddingModel.embed(TextSegment)` / `embedAll(List)` API. In LangChain4j 1.23 these return a `Response` built from `EmbeddingResponse` with only the content and the token usage: the model name of the response is dropped. The only way to get it is to call `embed(EmbeddingRequest)` and read `EmbeddingResponse.modelName()`. That changes which model method is called (models or mocks that override only `embed(TextSegment)` would be bypassed) and the finish reason is not in `EmbeddingResponse`, so I left it out of this PR. Options: - a) switch to `embed(EmbeddingRequest)`, set `RESPONSE_MODEL` and pass it to the GenAI observation (recommended, as its own JIRA); - b) deprecate the header and drop it from the docs; - c) leave it. ### Tests New `LangChain4jEmbeddingsBodyTest` (AllMiniLmL6V2, local, no external service): bytes, stream, `TextSegment` and file consumer bodies, a batch of a String, bytes and a stream, no body, single after batch, batch after single, and the generated JSON has no javaType with a leading space. 8 of the 9 tests failed before the fix (the `TextSegment` one is a guard). Module: 17 unit tests and 29 ITs pass (4 Pinecone ITs skipped). ### Docs - `@BodyTypes` producerIn now lists bytes, stream and file and no longer says they fail. No yaml-dsl-validator test refers to this component. - New short section "The text to embed" in the component page. Catalog copies regenerated. - No upgrade guide entry: bodies that failed before now work, and only stale headers of an earlier call are removed. _Claude Code on behalf of Claus Ibsen (davsclaus)_ 🤖 Generated with [Claude Code](https://claude.com/claude-code) -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
