gnodet-bot commented on code in PR #29030:
URL: https://github.com/apache/camel/pull/29030#discussion_r4449062159


##########
components/camel-ai/camel-langchain4j-ingest/src/main/java/org/apache/camel/component/langchain4j/ingest/LangChain4jIngestProducer.java:
##########
@@ -306,6 +313,38 @@ private IngestResult ingestUnlessFiltered(Exchange 
exchange, String documentId,
         return textService.ingest(documentId, textBody(exchange));
     }
 
+    /**
+     * The text of the body: a LangChain4j {@code TextSegment} or {@code 
Document} gives its text, and text, bytes, a
+     * stream, a Reader or a file is read as text. Any other body, such as a 
Map or a POJO, fails as an
+     * InvalidPayloadException instead of being ingested as its toString().
+     */
+    private String textBody(Exchange exchange) throws InvalidPayloadException, 
IOException {
+        Object body = exchange.getMessage().getBody();
+        if (body instanceof TextSegment segment) {
+            return segment.text();
+        }
+        if (body instanceof Document document) {
+            return document.text();
+        }

Review Comment:
   ⚠️ **Gap: `maxDocumentSize` not enforced for `TextSegment` / `Document` 
bodies**
   
   Both `TextSegment` and `Document` branches return `segment.text()` / 
`document.text()` directly, bypassing `readText()` where the `readLimit()` / 
`maxDocumentSize` check lives. A user who configures a size cap will have it 
silently ignored for these body types.
   
   One approach — delegate through `readText` for a consistent limit:
   ```suggestion
               return readText(exchange, document.text());
   ```
   (And the same for the `TextSegment` branch: `return readText(exchange, 
segment.text());`)
   
   Alternatively, extract a `checkSize(String text)` helper shared by all paths.



-- 
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