[
https://issues.apache.org/jira/browse/CAMEL-27544?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Gaelle Fournier updated CAMEL-27544:
------------------------------------
Description:
Camel's RAG story today is vector-shaped on both sides: CAMEL-24621 closed the
ingestion half (camel-langchain4j-ingest gets documents _into_ an embedding
store), and camel-langchain4j-embeddingstore / chat / agent search one on the
retrieval side. The one route-backed path that exists —
{{LangChain4jRagAggregatorStrategy}} in camel-langchain4j-chat — is route-side
manual wiring before a chat call, and it does not reach LangChain4j's
{{RetrievalAugmentor}} / AI Services at all. Meanwhile, much of what an AI
assistant needs to answer a question is not in a vector store: the customer's
orders behind a REST API, rows in a relational database, a contract in a DMS, a
ticket in a legacy system — all places Camel already reaches with its 300+
components. A user who wants route-backed retrieval in a real RAG pipeline has
to hand-write a {{ContentRetriever}} wrapper around a {{{}ProducerTemplate{}}},
and own its timeout, error, thread-pool and type-conversion semantics in every
application. This ticket proposes closing that gap with a small class in
camel-langchain4j-core.
*What it brings*
{{CamelContentRetriever}} turns any Camel endpoint — a route, a Kamelet or a
component — into a LangChain4j {{{}ContentRetriever{}}}:
{code:java}
{{CamelContentRetriever orders = new CamelContentRetriever(camelContext,
"orders", "direct:orders")
.setTimeout(Duration.ofSeconds(2))
.setOnError(OnError.EMPTY);
camelContext.addService(orders);RetrievalAugmentor augmentor =
DefaultRetrievalAugmentor.builder()
.queryRouter(LanguageModelQueryRouter.builder()
.chatModel(chatModel)
.retrieverToDescription(Map.of(orders, "The customer's recent orders"))
.build())
.contentInjector(new DefaultContentInjector())
.build();}}
{code}
The retriever sends the query text as the message body and the query metadata
as exchange properties ({{{}langchain4j.query.userMessage{}}},
{{{}...chatMemoryId{}}}, one {{...param.<key>}} per AI Service invocation
parameter — the caller's identity, so routes can scope queries per tenant). The
response body becomes the content list: {{{}String{}}}, {{TextSegment}} and
{{Content}} elements pass through, {{Map}} elements become {{key: value}}
lines, anything else goes through the Camel type converter. Every segment is
stamped {{camel_retrieval_source}} and, when configured,
{{camel_retrieval_document_id}} (mirroring {{{}camel_ingest_*{}}}), and
response headers prefixed {{langchain4j.metadata.}} become segment metadata —
the reserved keys never come from response headers, while a route may set the
document id itself (e.g. mapping an ingest document id for citation).
*Why users will like it*
* {*}Nothing new to learn{*}: the retrieval source is an ordinary Camel route;
the wiring is plain LangChain4j — {{{}DefaultQueryRouter{}}},
{{{}LanguageModelQueryRouter{}}}, {{ExpandingQueryTransformer}} and
{{DefaultRetrievalAugmentor}} all work unchanged, and vector-backed and
route-backed retrievers mix in one augmentor.
* {*}Per-source failure and cost policy{*}: {{{}timeout{}}}, {{on-error}}
(fail/empty), {{max-results}} and {{max-chars}} — a slow or broken source
degrades the answer instead of failing the AI interaction.
* {*}Bounded by construction{*}: retrieval runs on the retriever's own bounded
executor ({{{}concurrency{}}}, {{{}queue-capacity{}}}), so a saturated source
rejects and follows {{on-error}} rather than blocking the caller; registered
with {{CamelContext.addService}} the template and executor stop with the
context, and a call queued at shutdown follows {{on-error}} instead of hanging
(CAMEL-26578).
* {*}Safe defaults{*}: identity arrives only through the invocation-parameter
properties; the recommendation is read-only credentials for the backing system
and parameterized queries, since the query text comes from an LLM-transformed
user message.
*Provenance and proof*
A working proof of concept exists, tested at three levels: 65 unit tests in
camel-langchain4j-core; integration tests in camel-quarkus behind
{{{}@RegisterAiService{}}}, in JVM and native image; and a runnable Camel JBang
example that mixes a metadata-driven source, a template source and a real
vector source (in-process all-MiniLM-L6-v2 model, searched through
{{{}langchain4j-embeddingstore{}}}) behind one augmentor. Verified against
LangChain4j 1.24.0, the version Camel 4.24 ships with; documentation and
catalog wiring included. The camel-quarkus RAG bridge will build its
config-driven sources on top of this class once Camel Quarkus moves to Camel
4.24 — one engine, maintained once.
*Scope and follow-ups*
Proposed as Preview. Deliberately programmatic in this increment — no endpoint
and no configuration; config-driven sources in the Camel Quarkus bridge,
Kamelets ({{{}rag-search-*{}}}, {{{}rag-rest{}}}) and converters for
component-specific payloads (SQL rows, search hits) are follow-ups. Blocking
{{retrieve()}} only — {{retrieveAsync}} is still {{@Experimental}} in
LangChain4j. Multimodal user messages are not mapped to the {{userMessage}}
property in v1.
_Assisted by Claude Code on behalf of gfournier._
was:
Camel's RAG story today is vector-shaped on both sides: CAMEL-24621 closed the
ingestion half (camel-langchain4j-ingest gets documents _into_ an embedding
store), and camel-langchain4j-embeddingstore / chat / agent search one on the
retrieval side. The one route-backed path that exists —
{{LangChain4jRagAggregatorStrategy}} in camel-langchain4j-chat — is route-side
manual wiring before a chat call, and it does not reach LangChain4j's
{{RetrievalAugmentor}} / AI Services at all. Meanwhile, much of what an AI
assistant needs to answer a question is not in a vector store: the customer's
orders behind a REST API, rows in a relational database, a contract in a DMS, a
ticket in a legacy system — all places Camel already reaches with its 300+
components. A user who wants route-backed retrieval in a real RAG pipeline has
to hand-write a {{ContentRetriever}} wrapper around a {{{}ProducerTemplate{}}},
and own its timeout, error, thread-pool and type-conversion semantics in every
application. This ticket proposes closing that gap with a small class in
camel-langchain4j-core.
*What it brings*
{{CamelContentRetriever}} turns any Camel endpoint — a route, a Kamelet or a
component — into a LangChain4j {{{}ContentRetriever{}}}:
{{CamelContentRetriever orders = new CamelContentRetriever(camelContext,
"orders", "direct:orders")
.setTimeout(Duration.ofSeconds(2))
.setOnError(OnError.EMPTY);
camelContext.addService(orders);RetrievalAugmentor augmentor =
DefaultRetrievalAugmentor.builder()
.queryRouter(LanguageModelQueryRouter.builder()
.chatModel(chatModel)
.retrieverToDescription(Map.of(orders, "The customer's recent
orders"))
.build())
.contentInjector(new DefaultContentInjector())
.build();}}
The retriever sends the query text as the message body and the query metadata
as exchange properties ({{{}langchain4j.query.userMessage{}}},
{{{}...chatMemoryId{}}}, one {{...param.<key>}} per AI Service invocation
parameter — the caller's identity, so routes can scope queries per tenant). The
response body becomes the content list: {{{}String{}}}, {{TextSegment}} and
{{Content}} elements pass through, {{Map}} elements become {{key: value}}
lines, anything else goes through the Camel type converter. Every segment is
stamped {{camel_retrieval_source}} and, when configured,
{{camel_retrieval_document_id}} (mirroring {{{}camel_ingest_*{}}}), and
response headers prefixed {{langchain4j.metadata.}} become segment metadata —
the reserved keys never come from response headers, while a route may set the
document id itself (e.g. mapping an ingest document id for citation).
*Why users will like it*
* {*}Nothing new to learn{*}: the retrieval source is an ordinary Camel route;
the wiring is plain LangChain4j — {{{}DefaultQueryRouter{}}},
{{{}LanguageModelQueryRouter{}}}, {{ExpandingQueryTransformer}} and
{{DefaultRetrievalAugmentor}} all work unchanged, and vector-backed and
route-backed retrievers mix in one augmentor.
* {*}Per-source failure and cost policy{*}: {{{}timeout{}}}, {{on-error}}
(fail/empty), {{max-results}} and {{max-chars}} — a slow or broken source
degrades the answer instead of failing the AI interaction.
* {*}Bounded by construction{*}: retrieval runs on the retriever's own bounded
executor ({{{}concurrency{}}}, {{{}queue-capacity{}}}), so a saturated source
rejects and follows {{on-error}} rather than blocking the caller; registered
with {{CamelContext.addService}} the template and executor stop with the
context, and a call queued at shutdown follows {{on-error}} instead of hanging
(CAMEL-26578).
* {*}Safe defaults{*}: identity arrives only through the invocation-parameter
properties; the recommendation is read-only credentials for the backing system
and parameterized queries, since the query text comes from an LLM-transformed
user message.
*Provenance and proof*
A working proof of concept exists, tested at three levels: 65 unit tests in
camel-langchain4j-core; integration tests in camel-quarkus behind
{{{}@RegisterAiService{}}}, in JVM and native image; and a runnable Camel JBang
example that mixes a metadata-driven source, a template source and a real
vector source (in-process all-MiniLM-L6-v2 model, searched through
{{{}langchain4j-embeddingstore{}}}) behind one augmentor. Verified against
LangChain4j 1.24.0, the version Camel 4.24 ships with; documentation and
catalog wiring included. The camel-quarkus RAG bridge will build its
config-driven sources on top of this class once Camel Quarkus moves to Camel
4.24 — one engine, maintained once.
*Scope and follow-ups*
Proposed as Preview. Deliberately programmatic in this increment — no endpoint
and no configuration; config-driven sources in the Camel Quarkus bridge,
Kamelets ({{{}rag-search-*{}}}, {{{}rag-rest{}}}) and converters for
component-specific payloads (SQL rows, search hits) are follow-ups. Blocking
{{retrieve()}} only — {{retrieveAsync}} is still {{@Experimental}} in
LangChain4j. Multimodal user messages are not mapped to the {{userMessage}}
property in v1.
_Assisted by Claude Code on behalf of gfournier._
> camel-langchain4j - CamelContentRetriever Camel endpoint into a LangChain4j
> ContentRetriever
> --------------------------------------------------------------------------------------------
>
> Key: CAMEL-27544
> URL: https://issues.apache.org/jira/browse/CAMEL-27544
> Project: Camel
> Issue Type: New Feature
> Components: camel-ai, camel-langchain4j
> Reporter: Gaelle Fournier
> Assignee: Gaelle Fournier
> Priority: Major
> Fix For: 4.24.0
>
>
> Camel's RAG story today is vector-shaped on both sides: CAMEL-24621 closed
> the ingestion half (camel-langchain4j-ingest gets documents _into_ an
> embedding store), and camel-langchain4j-embeddingstore / chat / agent search
> one on the retrieval side. The one route-backed path that exists —
> {{LangChain4jRagAggregatorStrategy}} in camel-langchain4j-chat — is
> route-side manual wiring before a chat call, and it does not reach
> LangChain4j's {{RetrievalAugmentor}} / AI Services at all. Meanwhile, much of
> what an AI assistant needs to answer a question is not in a vector store: the
> customer's orders behind a REST API, rows in a relational database, a
> contract in a DMS, a ticket in a legacy system — all places Camel already
> reaches with its 300+ components. A user who wants route-backed retrieval in
> a real RAG pipeline has to hand-write a {{ContentRetriever}} wrapper around a
> {{{}ProducerTemplate{}}}, and own its timeout, error, thread-pool and
> type-conversion semantics in every application. This ticket proposes closing
> that gap with a small class in camel-langchain4j-core.
> *What it brings*
> {{CamelContentRetriever}} turns any Camel endpoint — a route, a Kamelet or a
> component — into a LangChain4j {{{}ContentRetriever{}}}:
> {code:java}
> {{CamelContentRetriever orders = new CamelContentRetriever(camelContext,
> "orders", "direct:orders")
> .setTimeout(Duration.ofSeconds(2))
> .setOnError(OnError.EMPTY);
> camelContext.addService(orders);RetrievalAugmentor augmentor =
> DefaultRetrievalAugmentor.builder()
> .queryRouter(LanguageModelQueryRouter.builder()
> .chatModel(chatModel)
> .retrieverToDescription(Map.of(orders, "The customer's recent orders"))
> .build())
> .contentInjector(new DefaultContentInjector())
> .build();}}
> {code}
> The retriever sends the query text as the message body and the query metadata
> as exchange properties ({{{}langchain4j.query.userMessage{}}},
> {{{}...chatMemoryId{}}}, one {{...param.<key>}} per AI Service invocation
> parameter — the caller's identity, so routes can scope queries per tenant).
> The response body becomes the content list: {{{}String{}}}, {{TextSegment}}
> and {{Content}} elements pass through, {{Map}} elements become {{key: value}}
> lines, anything else goes through the Camel type converter. Every segment is
> stamped {{camel_retrieval_source}} and, when configured,
> {{camel_retrieval_document_id}} (mirroring {{{}camel_ingest_*{}}}), and
> response headers prefixed {{langchain4j.metadata.}} become segment metadata —
> the reserved keys never come from response headers, while a route may set the
> document id itself (e.g. mapping an ingest document id for citation).
> *Why users will like it*
> * {*}Nothing new to learn{*}: the retrieval source is an ordinary Camel
> route; the wiring is plain LangChain4j — {{{}DefaultQueryRouter{}}},
> {{{}LanguageModelQueryRouter{}}}, {{ExpandingQueryTransformer}} and
> {{DefaultRetrievalAugmentor}} all work unchanged, and vector-backed and
> route-backed retrievers mix in one augmentor.
> * {*}Per-source failure and cost policy{*}: {{{}timeout{}}}, {{on-error}}
> (fail/empty), {{max-results}} and {{max-chars}} — a slow or broken source
> degrades the answer instead of failing the AI interaction.
> * {*}Bounded by construction{*}: retrieval runs on the retriever's own
> bounded executor ({{{}concurrency{}}}, {{{}queue-capacity{}}}), so a
> saturated source rejects and follows {{on-error}} rather than blocking the
> caller; registered with {{CamelContext.addService}} the template and executor
> stop with the context, and a call queued at shutdown follows {{on-error}}
> instead of hanging (CAMEL-26578).
> * {*}Safe defaults{*}: identity arrives only through the
> invocation-parameter properties; the recommendation is read-only credentials
> for the backing system and parameterized queries, since the query text comes
> from an LLM-transformed user message.
> *Provenance and proof*
> A working proof of concept exists, tested at three levels: 65 unit tests in
> camel-langchain4j-core; integration tests in camel-quarkus behind
> {{{}@RegisterAiService{}}}, in JVM and native image; and a runnable Camel
> JBang example that mixes a metadata-driven source, a template source and a
> real vector source (in-process all-MiniLM-L6-v2 model, searched through
> {{{}langchain4j-embeddingstore{}}}) behind one augmentor. Verified against
> LangChain4j 1.24.0, the version Camel 4.24 ships with; documentation and
> catalog wiring included. The camel-quarkus RAG bridge will build its
> config-driven sources on top of this class once Camel Quarkus moves to Camel
> 4.24 — one engine, maintained once.
> *Scope and follow-ups*
> Proposed as Preview. Deliberately programmatic in this increment — no
> endpoint and no configuration; config-driven sources in the Camel Quarkus
> bridge, Kamelets ({{{}rag-search-*{}}}, {{{}rag-rest{}}}) and converters for
> component-specific payloads (SQL rows, search hits) are follow-ups. Blocking
> {{retrieve()}} only — {{retrieveAsync}} is still {{@Experimental}} in
> LangChain4j. Multimodal user messages are not mapped to the {{userMessage}}
> property in v1.
>
> _Assisted by Claude Code on behalf of gfournier._
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)