This is an automated email from the ASF dual-hosted git repository.
jamesnetherton pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-quarkus.git
The following commit(s) were added to refs/heads/main by this push:
new 78dac8281aa Use IngestIdFilter and handle FILTERED in
langchain4j-ingest
78dac8281aa is described below
commit 78dac8281aa978788af1fdc2cf38f5a1c40b7543
Author: Jiří Ondrušek <[email protected]>
AuthorDate: Thu Dec 3 17:44:26 2026 +0100
Use IngestIdFilter and handle FILTERED in langchain4j-ingest
Reuse Camel's IngestIdFilter (CAMEL-26342) for the pre-parse id check
instead of a copy of the producer's matching. Document that a media
document of unknown type is answered FILTERED (CAMEL-26341) and cover
it with a test.
Co-authored-by: jiriOndrusek-agent <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
---
.../reference/extensions/langchain4j-ingest.adoc | 8 +++----
.../runtime/src/main/doc/usage.adoc | 4 ++--
.../langchain4j/ingest/IngestBuildTimeConfig.java | 4 ++--
.../component/langchain4j/ingest/IngestRoutes.java | 25 +++++-----------------
.../langchain4j/ingest/it/ItBuilderPipelines.java | 9 ++++++++
.../ingest/it/Langchain4jIngestAudioTest.java | 13 +++++++++++
6 files changed, 35 insertions(+), 28 deletions(-)
diff --git
a/docs/modules/ROOT/pages/reference/extensions/langchain4j-ingest.adoc
b/docs/modules/ROOT/pages/reference/extensions/langchain4j-ingest.adoc
index 697fc8e707f..692965555df 100644
--- a/docs/modules/ROOT/pages/reference/extensions/langchain4j-ingest.adoc
+++ b/docs/modules/ROOT/pages/reference/extensions/langchain4j-ingest.adoc
@@ -205,8 +205,8 @@
quarkus.camel.langchain4j.ingest.photos.embedding-store=photos
quarkus.camel.langchain4j.ingest.photos.filter.include-id=**/*.png,**/*.jpg
----
-The MIME type handed to the model comes from `content-type` or, when unset,
from the file extension through Camel's MIME table (wav, mp3, flac, ogg, opus,
m4a, aac and aiff for audio; png, jpg, gif and webp for images; mp4, mov and
webm for video; pdf); a file whose type cannot be determined fails the
exchange, and `content-type` without `modality=media` is rejected like the
parser and splitter conflicts.
-On a directory pipeline such a file — `notes.txt`, `Thumbs.db` — fails again
on every poll, so restrict the ids with `filter.include-id`, as above: it is
checked before the media type.
+The MIME type handed to the model comes from `content-type` or, when unset,
from the file extension through Camel's MIME table (wav, mp3, flac, ogg, opus,
m4a, aac and aiff for audio; png, jpg, gif and webp for images; mp4, mov and
webm for video; pdf); a file whose type cannot be determined — `notes.txt`,
`Thumbs.db` — is answered `FILTERED` and logged at INFO, and `content-type`
without `modality=media` is rejected like the parser and splitter conflicts.
+To keep such files out silently, restrict the ids with `filter.include-id`, as
above: it is checked before the media type.
Images are embedded today by several LangChain4j providers; no provider embeds
audio out of the box yet, so an audio model is a CDI bean of your own that
declares `AUDIO` — typically a client of an audio embedding service — and
either way the same bean embeds the query image or clip at retrieval time.
The Java twin is `IngestPipeline.modality("media")`, and a consumer-fed
pipeline embeds the delivered payload the same way.
@@ -337,8 +337,8 @@ a|icon:lock[title=Fixed at build time]
[[quarkus-camel-langchain4j-ingest-pipeli
MIME type of a media payload, such as `audio/wav` or `image/png`, handed to the
embedding model. When not set, it is derived from the document id's file
extension
-through Camel's MIME table; a document whose type cannot be determined, or
whose
-medium the model does not declare, fails the exchange. Only valid with
+through Camel's MIME table; a document whose type cannot be determined is
filtered,
+one whose medium the model does not declare fails the exchange. Only valid with
`modality=media`: set without it, the pipeline is rejected.
| `string`
|
diff --git a/extensions/langchain4j-ingest/runtime/src/main/doc/usage.adoc
b/extensions/langchain4j-ingest/runtime/src/main/doc/usage.adoc
index ef5383976e1..cfa9af1fd43 100644
--- a/extensions/langchain4j-ingest/runtime/src/main/doc/usage.adoc
+++ b/extensions/langchain4j-ingest/runtime/src/main/doc/usage.adoc
@@ -152,8 +152,8 @@
quarkus.camel.langchain4j.ingest.photos.embedding-store=photos
quarkus.camel.langchain4j.ingest.photos.filter.include-id=**/*.png,**/*.jpg
----
-The MIME type handed to the model comes from `content-type` or, when unset,
from the file extension through Camel's MIME table (wav, mp3, flac, ogg, opus,
m4a, aac and aiff for audio; png, jpg, gif and webp for images; mp4, mov and
webm for video; pdf); a file whose type cannot be determined fails the
exchange, and `content-type` without `modality=media` is rejected like the
parser and splitter conflicts.
-On a directory pipeline such a file — `notes.txt`, `Thumbs.db` — fails again
on every poll, so restrict the ids with `filter.include-id`, as above: it is
checked before the media type.
+The MIME type handed to the model comes from `content-type` or, when unset,
from the file extension through Camel's MIME table (wav, mp3, flac, ogg, opus,
m4a, aac and aiff for audio; png, jpg, gif and webp for images; mp4, mov and
webm for video; pdf); a file whose type cannot be determined — `notes.txt`,
`Thumbs.db` — is answered `FILTERED` and logged at INFO, and `content-type`
without `modality=media` is rejected like the parser and splitter conflicts.
+To keep such files out silently, restrict the ids with `filter.include-id`, as
above: it is checked before the media type.
Images are embedded today by several LangChain4j providers; no provider embeds
audio out of the box yet, so an audio model is a CDI bean of your own that
declares `AUDIO` — typically a client of an audio embedding service — and
either way the same bean embeds the query image or clip at retrieval time.
The Java twin is `IngestPipeline.modality("media")`, and a consumer-fed
pipeline embeds the delivered payload the same way.
diff --git
a/extensions/langchain4j-ingest/runtime/src/main/java/org/apache/camel/quarkus/component/langchain4j/ingest/IngestBuildTimeConfig.java
b/extensions/langchain4j-ingest/runtime/src/main/java/org/apache/camel/quarkus/component/langchain4j/ingest/IngestBuildTimeConfig.java
index 985c966bf62..417cda4e042 100644
---
a/extensions/langchain4j-ingest/runtime/src/main/java/org/apache/camel/quarkus/component/langchain4j/ingest/IngestBuildTimeConfig.java
+++
b/extensions/langchain4j-ingest/runtime/src/main/java/org/apache/camel/quarkus/component/langchain4j/ingest/IngestBuildTimeConfig.java
@@ -88,8 +88,8 @@ public interface IngestBuildTimeConfig {
/**
* MIME type of a media payload, such as `audio/wav` or `image/png`,
handed to the
* embedding model. When not set, it is derived from the document id's
file extension
- * through Camel's MIME table; a document whose type cannot be
determined, or whose
- * medium the model does not declare, fails the exchange. Only valid
with
+ * through Camel's MIME table; a document whose type cannot be
determined is filtered,
+ * one whose medium the model does not declare fails the exchange.
Only valid with
* `modality=media`: set without it, the pipeline is rejected.
*/
Optional<String> contentType();
diff --git
a/extensions/langchain4j-ingest/runtime/src/main/java/org/apache/camel/quarkus/component/langchain4j/ingest/IngestRoutes.java
b/extensions/langchain4j-ingest/runtime/src/main/java/org/apache/camel/quarkus/component/langchain4j/ingest/IngestRoutes.java
index 46e8699a09f..04130cc43f7 100644
---
a/extensions/langchain4j-ingest/runtime/src/main/java/org/apache/camel/quarkus/component/langchain4j/ingest/IngestRoutes.java
+++
b/extensions/langchain4j-ingest/runtime/src/main/java/org/apache/camel/quarkus/component/langchain4j/ingest/IngestRoutes.java
@@ -45,6 +45,7 @@ import org.apache.camel.Predicate;
import org.apache.camel.Processor;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.file.GenericFile;
+import org.apache.camel.component.langchain4j.ingest.IngestIdFilter;
import org.apache.camel.component.langchain4j.ingest.IngestResult;
import org.apache.camel.component.langchain4j.ingest.LangChain4jIngest;
import org.apache.camel.component.langchain4j.ingest.LangChain4jIngestHeaders;
@@ -55,7 +56,6 @@ import org.apache.camel.support.builder.PredicateBuilder;
import
org.apache.camel.support.processor.idempotent.MemoryIdempotentRepository;
import org.apache.camel.support.service.ServiceHelper;
import org.apache.camel.support.service.ServiceSupport;
-import org.apache.camel.util.AntPathMatcher;
import org.apache.camel.util.URISupport;
import org.jboss.logging.Logger;
@@ -420,19 +420,13 @@ public class IngestRoutes extends RouteBuilder {
+ " the parse - a parsed document must not supply its
own identity");
}
});
- String[] include = patterns(includeId);
- String[] exclude = patterns(excludeId);
- if (include != null || exclude != null) {
+ if (!includeId.isBlank() || !excludeId.isBlank()) {
// advisory too: the sink's id patterns, applied before the parse
so an excluded
// document is never parsed, nor fails the parse or the size guard
on every poll.
- // patterns() and this match mirror the private parsePatterns and
idAccepted of the
- // component's LangChain4jIngestProducer, which stay authoritative
- keep them in step
+ // The component's own filter, so the match is the one its
producer applies
+ IngestIdFilter idFilter = IngestIdFilter.of(includeId, excludeId);
route = route.choice()
- .when(exchange -> {
- String id =
exchange.getMessage().getHeader(documentIdHeader, String.class);
- return AntPathMatcher.INSTANCE.anyMatch(exclude, id)
- || (include != null &&
!AntPathMatcher.INSTANCE.anyMatch(include, id));
- })
+ .when(exchange ->
!idFilter.accepts(exchange.getMessage().getHeader(documentIdHeader,
String.class)))
.process(exchange -> {
String id =
exchange.getMessage().getHeader(documentIdHeader, String.class);
if (directory) {
@@ -511,15 +505,6 @@ public class IngestRoutes extends RouteBuilder {
};
}
- /** Comma-separated id patterns, parsed as the component parses them; null
when none remain. */
- private static String[] patterns(String value) {
- String[] patterns = Arrays.stream(value.split(","))
- .map(String::trim)
- .filter(pattern -> !pattern.isEmpty())
- .toArray(String[]::new);
- return patterns.length == 0 ? null : patterns;
- }
-
/**
* A directory pipeline discards the reply, so a filtered document is
logged instead; a named register does not
* keep its file's key, see {@link SourceRegister}.
diff --git
a/integration-tests/langchain4j-ingest/src/main/java/org/apache/camel/quarkus/component/langchain4j/ingest/it/ItBuilderPipelines.java
b/integration-tests/langchain4j-ingest/src/main/java/org/apache/camel/quarkus/component/langchain4j/ingest/it/ItBuilderPipelines.java
index fb47fbe5273..b5ee7f5fb84 100644
---
a/integration-tests/langchain4j-ingest/src/main/java/org/apache/camel/quarkus/component/langchain4j/ingest/it/ItBuilderPipelines.java
+++
b/integration-tests/langchain4j-ingest/src/main/java/org/apache/camel/quarkus/component/langchain4j/ingest/it/ItBuilderPipelines.java
@@ -71,6 +71,15 @@ public class ItBuilderPipelines {
.embeddingModel("audio-model");
}
+ /** Media without a content type: the type comes from the id's extension,
an id without one is filtered. */
+ @Ingest("sounds")
+ IngestPipeline sounds() {
+ return IngestPipeline.from(Source.endpoint(direct("sounds-feed")))
+ .modality("media")
+ .embeddingStore("audio-store")
+ .embeddingModel("audio-model");
+ }
+
/**
* The lambda form of the Endpoint DSL — nothing imported, the IDE lists
every component off
* {@code dsl.}. The object key identifies the document, and the store
addresses buckets by
diff --git
a/integration-tests/langchain4j-ingest/src/test/java/org/apache/camel/quarkus/component/langchain4j/ingest/it/Langchain4jIngestAudioTest.java
b/integration-tests/langchain4j-ingest/src/test/java/org/apache/camel/quarkus/component/langchain4j/ingest/it/Langchain4jIngestAudioTest.java
index 5dfe9f4f63e..bc00d56f03e 100644
---
a/integration-tests/langchain4j-ingest/src/test/java/org/apache/camel/quarkus/component/langchain4j/ingest/it/Langchain4jIngestAudioTest.java
+++
b/integration-tests/langchain4j-ingest/src/test/java/org/apache/camel/quarkus/component/langchain4j/ingest/it/Langchain4jIngestAudioTest.java
@@ -80,6 +80,19 @@ class Langchain4jIngestAudioTest {
assertEquals("clip-7", hits.get(0).get("documentId"));
}
+ /** A media document whose type cannot be told from its id is filtered,
not failed (CAMEL-26341). */
+ @Test
+ void undeterminedMediaTypeIsFiltered() {
+ byte[] clip = wav(400);
+
+ String outcome = RestAssured.given().contentType(ContentType.BINARY)
+ .body(clip)
+ .post("/langchain4j-ingest/feed-binary/sounds/notes")
+ .then().statusCode(200).extract().asString();
+ assertEquals("filtered", outcome);
+ assertTrue(searchByClip(clip).isEmpty(), "the filtered clip must not
be stored");
+ }
+
/**
* A consumer-fed media stream over the cap is refused after max + 1
bytes, whatever CamelFileLength it announces:
* the component reads it no further (CAMEL-25463), read whole it would
report all 32044 bytes.