davsclaus opened a new pull request, #29031: URL: https://github.com/apache/camel/pull/29031
Fixes [CAMEL-26208](https://issues.apache.org/jira/browse/CAMEL-26208). ### 1. A List of one text returned a `float[]` instead of a List `SpringAiEmbeddingsProducer` picked the single-text output when there was one input text, also when the body was a `List` of one element. A `List` of two texts gave a `List<float[]>`. So the output shape depended on the list size, and a split or aggregate route broke on lists of one. Now a `List` body always gives a `List<float[]>` and the `CamelSpringAiEmbeddings` and `CamelSpringAiEmbeddingInputTexts` headers. A `String` (or another non-List) body still gives a single `float[]` with the `CamelSpringAiEmbedding`, `CamelSpringAiEmbeddingIndex` and `CamelSpringAiEmbeddingInputText` headers. `spring-ai-vector-store` already reads the List form (`CamelSpringAiEmbeddingInputTexts` plus a `List<float[]>` body), so `embeddings -> vector-store` still works for a List of one. ### 2. A List of non-Strings was passed on unchecked The `List` body was cast to `List<String>` without a check, so a `List` of POJOs, numbers or Maps failed later with a `ClassCastException` inside Spring AI. Now each element is converted to a `String` with the type converter, as a non-List body already is. A `null` element fails with an `IllegalArgumentException` that names its index. ### Related, same method: an empty List An empty `List` was sent to the model; Ollama rejects that ("At least one text is required!"). It now gives an empty `List` body and empty `CamelSpringAiEmbeddings` / `CamelSpringAiEmbeddingInputTexts` headers, without calling the model, so the "List in, List out" rule holds for every size. ### Tests `SpringAiEmbeddingsComponentTest` (fake `EmbeddingModel`): four new tests for a List of one text, a List of non-Strings, a List with a `null` element, and an empty List. All four failed before the fix. Module: 6 unit tests pass. `SpringAiEmbeddingsIT` was not run: it needs an Ollama with the `granite-embedding:30m` model (it is disabled in CI). ### Docs and generated files - `@BodyTypes` of the endpoint updated (it described the old List-of-one behaviour), regenerated the component JSON and copied it and the component doc into `camel-catalog`. No option or header changed, so no endpoint DSL regeneration. - Component doc: the List rules. - Upgrade guide 4.24: new `camel-spring-ai-embeddings` section, as a route that read a `float[]` from a List of one text now gets a List. ### Not changed - Non-List collections (a `Set`, an array) are still converted to one text, as before; the issue only covers `List`. - A POJO element becomes its `toString()`, the same as a POJO body. It does not fail. _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]
