davsclaus opened a new pull request, #29029: URL: https://github.com/apache/camel/pull/29029
Fixes [CAMEL-26204](https://issues.apache.org/jira/browse/CAMEL-26204). ### 1. Auto-embedding a TextSegment body stored its toString() With an `embeddingModel` and no `CamelLangChain4jEmbeddingsEmbedding` header, `resolveEmbedding` read the body with `getBody(String.class)`. A `TextSegment` body became `TextSegment { text = ... }`, and that text was embedded and stored, without the metadata. Now a `TextSegment` body is embedded and stored as is, with its metadata. This applies to ADD and to SEARCH (the query). The `CamelLangChain4jEmbeddingsTextSegment` header still takes precedence over the body, as before. ### 2. A List body was embedded as one text The same code turned a `List<String>` body into one text such as `[a, b]`, stored as one entry. Now ADD embeds a `List` (any `Collection`) of `String` or `TextSegment` with `embedAll` and stores it as a batch through the same code as the `CamelLangChain4jEmbeddingsEmbeddings` header path. The body is the `List` of ids, and `CamelLangchain4jEmbeddingStoreEmbeddingIds` supplies your own ids. An empty list, or an element that is not a `String` or `TextSegment`, fails with `IllegalArgumentException` (naming the index and type). SEARCH takes one query, so a `List` body fails with `IllegalArgumentException`. When the `CamelLangChain4jEmbeddingsEmbedding` or `CamelLangChain4jEmbeddingsTextSegment` header is set, the body is not used as a batch: the headers keep their precedence. ### 3. REMOVE accepted any body as an id `remove` converted any body that is not a `Collection` with `getBody(String.class)`, so a `Map` or `42` removed a made-up id and nothing failed. A `Collection` of non-String ids was passed to `removeAll` unchecked. Now REMOVE fails with `IllegalArgumentException` unless the body is text (`CharSequence`, `byte[]`, `InputStream`, `Reader` or `StreamCache`, read as a String) or a `Collection` of `String` ids. Bytes and streams stay accepted so an id from an HTTP request body still works. ### Tests - `LangChain4jEmbeddingStoreAutoEmbedTest` (AllMiniLmL6V2 + `InMemoryEmbeddingStore`): TextSegment body ADD and SEARCH, List of Strings, List of TextSegments with caller ids and metadata, List with the text segment header, List with an Integer element, empty List, SEARCH with a List body. - `LangChain4jEmbeddingStoreBatchOperationsTest`: REMOVE with a Map, an Integer, a List of Integers (fail, nothing removed) and a `byte[]` id (works). - All new tests except the `byte[]` guard failed before the fix (7 + 3). Module: 38 unit tests and 11 ITs (Qdrant, Weaviate, Milvus) pass. ### Docs - Component page: how the body is auto-embedded, and the REMOVE body types. `@BodyTypes` text updated; regenerated JSON and doc copied into `camel-catalog`. - Upgrade guide 4.24: new `camel-langchain4j-embeddingstore` entry (a List body now gives a List of ids, REMOVE now fails on a non-text body). ### Not changed - A `Map` or POJO body for auto-embedding is still read as a String (it may have a type converter users rely on). - An array body (`String[]`) is not treated as a batch. _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]
