davsclaus opened a new pull request, #29108:
URL: https://github.com/apache/camel/pull/29108

   Fixes [CAMEL-26512](https://issues.apache.org/jira/browse/CAMEL-26512).
   
   ### A Map or POJO body (or List element) was embedded as its `toString()`
   
   `SpringAiEmbeddingsProducer` read a single body with `getBody(String.class)` 
and, since #29031 (CAMEL-26208), each element of a `List` body with the type 
converter to `String`. The `ToString` fallback converter accepts any object, so 
a `Map` body was embedded as `{a=1, b=2}`, a POJO as its `toString()`, a number 
as `"42"`, and a Spring AI `Document` as `Document{id=..., text=..., ...}`. The 
vector came from text nobody meant to embed, and nothing failed.
   
   Now the body, and each element of a `List` body, must be:
   
   - text (a `CharSequence`), bytes (`byte[]`, `ByteBuffer`, 
`ByteArrayOutputStream`), a stream (`InputStream`, `Reader`, `StreamCache`) or 
a file (`File`, `Path`, `WrappedFile`), read as text with the type converter; or
   - a Spring AI `Document`, embedded as its `getText()`. A `Document` with no 
text (a media document) fails.
   
   Any other value fails with an `InvalidPayloadException` that says to convert 
the body to text first (`convertBodyTo(String)` or a marshal to JSON). For a 
`List` element the message names the index and the type. This is the rule and 
wording of camel-langchain4j-embeddings (CAMEL-26205) and 
camel-langchain4j-embeddingstore (CAMEL-26204, ffc272852e6f). No body and a 
`null` `List` element still fail with `IllegalArgumentException`, as before.
   
   ### Tests
   
   `SpringAiEmbeddingsComponentTest` (fake `EmbeddingModel`):
   
   - new: a `Map` body, a POJO body, a `List` with a `Map` element and a `List` 
with an `Integer` element fail with `InvalidPayloadException` and do not call 
the model; a `Document` body embeds its text; a media `Document` without text 
fails; a stream body is read as text.
   - changed: the CAMEL-26208 test `testListOfNonStringsIsConvertedToText` used 
`List.of(42, new StringBuilder("hello"))` and expected `"42"`. It is now 
`testListOfTextCarriersIsConvertedToText` with a `StringBuilder`, bytes and a 
`Document`.
   
   The six new tests that check the new behaviour failed before the fix (the 
stream test passed before as well; it guards that streams stay accepted). 
Module: 13 unit tests pass, and `SpringAiEmbeddingsIT` (5) passed against a 
local Ollama.
   
   ### Docs and generated files
   
   - `@BodyTypes` `producerIn` is now `text, bytes, stream, file, list` (was 
`any`) with a description that no longer says a Map or POJO is embedded as its 
`toString()`. Regenerated the component JSON and copied it and the component 
doc into `camel-catalog`. No option or header changed, so no endpoint DSL 
regeneration.
   - No test in `camel-yaml-dsl-validator` (`BodyTypeFlowTest`, 
`TextBodyFlowTest`, ...) refers to `spring-ai-embeddings`.
   - Component doc: the accepted bodies and the failure.
   - Upgrade guide 4.24: extended the existing `camel-spring-ai-embeddings` 
section (from CAMEL-26208), as a `Map`, POJO, number or `Document` body that 
was embedded before now fails or gives a different text.
   
   ### Not changed
   
   - A number body or element now fails, the same as in the langchain4j 
components. A route that embeds numbers needs a `convertBodyTo(String.class)`.
   - No type converter to `Document` is tried for other bodies: the Spring AI 
modules have none (the langchain4j components try one to `TextSegment` because 
camel-langchain4j-embeddings ships one).
   - The batch example in the component doc sets the body with a `constant` in 
XML and YAML, which is one `String`, not a `List`. It is outside this fix.
   
   _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]

Reply via email to