davsclaus commented on code in PR #29030:
URL: https://github.com/apache/camel/pull/29030#discussion_r4451473585
##########
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:
Checked: the cap is not bypassed. `readText()` holds only the *read* limit:
it stops reading a stream, Reader or file one character past `maxDocumentSize`,
so an oversized body is never loaded whole. The check that fails the exchange
is in `IngestService.ingest(documentId, text)` (`text.length() >
maxDocumentSize` -> `exceeds maxDocumentSize (n > max characters)`). Every text
body reaches that call, including the `TextSegment` and `Document` branches. A
`TextSegment` or `Document` text is already in memory, so a read limit gives no
extra protection there.
Added `oversizedTextSegmentAndDocumentFailLikeAnOversizedString` in
db0f794add87. A 30-character `String`, `TextSegment` and `Document` on a
`maxDocumentSize=20` endpoint each fail with the same `exceeds maxDocumentSize
(30 > 20 characters)` and nothing is written. A `TextSegment` or `Document`
exactly at the cap ingests. No production change was needed.
_Claude Code on behalf of Claus Ibsen (davsclaus)_
--
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]