davsclaus opened a new pull request, #29030: URL: https://github.com/apache/camel/pull/29030
Fixes [CAMEL-26206](https://issues.apache.org/jira/browse/CAMEL-26206). ### What was wrong In the default text modality, `LangChain4jIngestProducer` read the body with `getBody(String.class)`. For an object without a real text form, Camel falls back to its `toString()`. So a `TextSegment` body was ingested as the text `TextSegment { text = ... }`, and a `Map` or a POJO as its `toString()`. Nothing told the route. ### What changed - A LangChain4j `TextSegment` or `Document` body gives its text (`text()`). - Text (any `CharSequence`), `byte[]`, `ByteBuffer`, an `InputStream` or `StreamCache`, a `Reader`, a `ByteArrayOutputStream` (the output of a Tika parse), a `File`, a `Path` or a `WrappedFile` is read as text, as before (including the `maxDocumentSize` read limit). - Any other body fails with an `InvalidPayloadException` whose message says what the pipeline reads and to convert the body to text first. Media mode already failed a `Map` or a POJO with an `InvalidPayloadException`, so both modes now fail the same way. - A null body still answers `EMPTY`. ### Tests In `LangChain4jIngestProducerTest`: - `textSegmentAndDocumentBodiesIngestTheirText`: the stored segment text is the text itself. Failed before the fix (it stored `TextSegment { text = ... }`). - `bodyThatIsNotTextFails`: a `Map` and a POJO fail, with and without `maxDocumentSize`, and nothing is written. Failed before the fix. - `textCarriersAreReadAsText`: `StringBuilder`, `byte[]`, `StringReader` and `ByteArrayOutputStream` bodies still ingest their text (a guard for the allow-list; passes before and after). Module suite: 72 tests and 1 IT, all pass. ### Docs and generated files - `@BodyTypes` description no longer says another body is ingested as its `toString()`; regenerated `langchain4j-ingest.json` and copied it and the component doc to the catalog. - Component doc: a paragraph on what body the text mode reads. - Upgrade guide 4.24: new `camel-langchain4j-ingest` entry, since a `Map` or POJO body that used to be ingested now fails. ### Not changed - The metadata of a `Document` or `TextSegment` body is not ingested; the written segments keep only the identity metadata, as for any other body. Carrying the body's metadata over would be a feature of its own. - The `@BodyTypes` carriers are unchanged (TEXT, BYTES, STREAM, FILE, NULL); the description names `TextSegment` and `Document`. _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]
