[ 
https://issues.apache.org/jira/browse/CAMEL-27736?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18153263#comment-18153263
 ] 

Gaelle Fournier edited comment on CAMEL-27736 at 12/1/26, 8:39 AM:
-------------------------------------------------------------------

_[~davsclaus] [~ramu11] Some feedback on this_

h3. Design notes from the CAMEL-27544 review

+*The engine has to be split, not moved.*+ {{Query}} on the way in and
{{{}Content{}}}/{{{}TextSegment{}}}/{{{}Metadata{}}}/{{{}EmbeddingMatch{}}} on 
the way out are
LangChain4j types. The neutral module needs its own query (text + metadata map)
and result (text, metadata, score, document id) types; {{QueryMetadataMapper}}
stays in the LangChain4j adapter, and {{ContentConverter}} splits into
selection/limits/cleanup (engine) and body shaping (adapter).

+Invocation SPI.+ {{Target}} today holds {{ProducerTemplate}} + 
{{{}Endpoint{}}}.
The neutral engine needs {{createExchange()}} + {{{}invoke(exchange){}}}, with 
an
endpoint-URI implementation (Java path, unchanged) and a route-processor
implementation ({{{}ai-retriever{}}} consumer). The URI constructor stays.

+Lifecycle.+ For {{ai-retriever}} sources the consumer route should own the
engine (start/stop/suspend with the route, as {{AiToolConsumer}} does); the URI
path keeps self-ownership via {{{}addService{}}}. A stopped source must follow
{{{}onError{}}}, not throw {{{}IllegalStateException{}}}.

+Identity and authorization.+ {{AiToolExecutor.createToolExchange}} copies the
caller's exchange properties so a tool route can be guarded on
{{{}exchangeProperty.subject{}}}. The {{ai-retriever}} path should do the same,
otherwise a retrieval route cannot use {{allowedRoles}} the way a tool route
does. {{CamelLangChain4jRetrieverParams}} remains the way to scope the query.

+Dynamic registration.+ Tools are resolved per exchange. If {{retrieverTags}}
wiring is built once at producer start, sources registered later or stopped are
stale. Either resolve the sources per query from {{AiRetrieverRegistry}} or
rebuild on {{{}AiRetrieverRegistryListener{}}}.

+Routing default.+ I would use all tagged sources by default and make
{{LanguageModelQueryRouter}} opt-in: LLM routing adds a model call and
unpredictable source selection to every query. If used, reuse the agent's model
and leave {{retrieverRoutingModel}} as a later option.

+Naming.+ Since 4.24.0 ships {{{}CamelLangChain4jRetrieverParams{}}}, the 
neutral
engine should define a neutral property name and keep the LangChain4j one as an
alias, so YAML routes do not have to change later.

+Scope.+ The {{camel-openai}} integration is a separate deliverable enabled by
the neutral engine; it should not gate this ticket.


was (Author: JIRAUSER304516):
_[~davsclaus] [~ramu11] Some feedback on this_

h3. Design notes from the CAMEL-27544 review

+b The engine has to be split, not moved.+ {{Query}} on the way in and
{{{}Content{}}}/{{{}TextSegment{}}}/{{{}Metadata{}}}/{{{}EmbeddingMatch{}}} on 
the way out are
LangChain4j types. The neutral module needs its own query (text + metadata map)
and result (text, metadata, score, document id) types; {{QueryMetadataMapper}}
stays in the LangChain4j adapter, and {{ContentConverter}} splits into
selection/limits/cleanup (engine) and body shaping (adapter).

+Invocation SPI.+ {{Target}} today holds {{ProducerTemplate}} + 
{{{}Endpoint{}}}.
The neutral engine needs {{createExchange()}} + {{{}invoke(exchange){}}}, with 
an
endpoint-URI implementation (Java path, unchanged) and a route-processor
implementation ({{{}ai-retriever{}}} consumer). The URI constructor stays.

+Lifecycle.+ For {{ai-retriever}} sources the consumer route should own the
engine (start/stop/suspend with the route, as {{AiToolConsumer}} does); the URI
path keeps self-ownership via {{{}addService{}}}. A stopped source must follow
{{{}onError{}}}, not throw {{{}IllegalStateException{}}}.

+Identity and authorization.+ {{AiToolExecutor.createToolExchange}} copies the
caller's exchange properties so a tool route can be guarded on
{{{}exchangeProperty.subject{}}}. The {{ai-retriever}} path should do the same,
otherwise a retrieval route cannot use {{allowedRoles}} the way a tool route
does. {{CamelLangChain4jRetrieverParams}} remains the way to scope the query.

+Dynamic registration.+ Tools are resolved per exchange. If {{retrieverTags}}
wiring is built once at producer start, sources registered later or stopped are
stale. Either resolve the sources per query from {{AiRetrieverRegistry}} or
rebuild on {{{}AiRetrieverRegistryListener{}}}.

+Routing default.+ I would use all tagged sources by default and make
{{LanguageModelQueryRouter}} opt-in: LLM routing adds a model call and
unpredictable source selection to every query. If used, reuse the agent's model
and leave {{retrieverRoutingModel}} as a later option.

+Naming.+ Since 4.24.0 ships {{{}CamelLangChain4jRetrieverParams{}}}, the 
neutral
engine should define a neutral property name and keep the LangChain4j one as an
alias, so YAML routes do not have to change later.

+Scope.+ The {{camel-openai}} integration is a separate deliverable enabled by
the neutral engine; it should not gate this ticket.

> camel-ai - ai-retriever: routes as RAG sources that AI producers pick by tag, 
> usable from YAML/XML
> --------------------------------------------------------------------------------------------------
>
>                 Key: CAMEL-27736
>                 URL: https://issues.apache.org/jira/browse/CAMEL-27736
>             Project: Camel
>          Issue Type: New Feature
>          Components: camel-ai, camel-langchain4j
>            Reporter: Claus Ibsen
>            Assignee: Ramu
>            Priority: Major
>             Fix For: 4.25.0
>
>
> CAMEL-27544 adds {{CamelContentRetriever}} to camel-langchain4j-core: a 
> LangChain4j {{ContentRetriever}} backed by a Camel endpoint, with a bounded 
> pool, a timeout, an {{onError}} policy, failure counters, body conversion and 
> citation metadata that matches camel-langchain4j-ingest. It is a good engine, 
> but today it can only be used from Java: the user builds the retriever, 
> registers it with {{addService}}, builds a {{RetrievalAugmentor}} and passes 
> it to {{AgentConfiguration}}, which is Java-only as well. Users who build 
> routes in YAML, XML or Kaoto cannot use RAG from routes.
> This ticket proposes a Camel-first way to do it. It reuses the pattern of 
> {{ai-tool}}, where a route registers itself under tags and the AI producer 
> picks the routes whose tags it names.
> h3. 1. A retrieval source is a route
> A new consumer endpoint {{ai-retriever}} (a new camel-ai module) registers 
> the route in an {{AiRetrieverRegistry}}, as {{ai-tool}} and {{ai-resource}} 
> do.
> {code:yaml}
> - route:
>     from:
>       uri: ai-retriever:orders
>       parameters:
>         tags: support
>         description: The customer's recent orders
>         timeout: 2s
>         onError: EMPTY
>         maxResults: 5
>         documentIdKey: orderId
>       steps:
>         - setHeader:
>             name: CamelHttpQuery
>             simple: 
> "customer=${exchangeProperty.CamelLangChain4jRetrieverParams[customerId]}"
>         - to: https://orders.internal/api/search
>         - unmarshal:
>             json: {}
> - route:
>     from:
>       uri: ai-retriever:articles
>       parameters:
>         tags: support
>         description: Support articles about orders and refunds
>       steps:
>         - to: langchain4j-embeddingstore:kb?action=SEARCH
> {code}
> The options that are Java setters of {{CamelContentRetriever}} today 
> ({{timeout}}, {{onError}}, {{maxResults}}, {{maxChars}}, {{concurrency}}, 
> {{queueCapacity}}, {{documentIdKey}}) become endpoint options, so they are in 
> the catalog, Kaoto and the Camel CLI.
> h3. 2. The AI producer picks the sources by tag
> {code:yaml}
> - route:
>     from:
>       uri: platform-http:/chat
>       steps:
>         - to:
>             uri: langchain4j-agent:support
>             parameters:
>               provider: openai
>               modelName: gpt-4.1
>               tags: support            # tools, as today
>               retrieverTags: support   # new: RAG sources
> {code}
> When it starts, the producer looks up the tagged retrievers and builds the 
> RAG wiring:
> * one source: a {{DefaultRetrievalAugmentor}} with that source
> * several sources: a {{LanguageModelQueryRouter}} that picks the relevant 
> ones from each route's {{description}}, or a {{DefaultQueryRouter}} (all 
> sources) with {{retrieverRouting=all}}
> * a {{DefaultContentInjector}} that includes {{camel_retrieval_source}} and 
> {{camel_retrieval_document_id}}, so answers can cite their sources without 
> any setup
> * the caller identity goes in as invocation parameters, the same as for 
> {{ai-tool}} and {{ai-resource}} routes, so a route scopes its search the same 
> way everywhere
> {{agentConfiguration.retrievalAugmentor}} stays as the Java escape hatch; 
> setting both is a startup error.
> h3. 3. What changes in CamelContentRetriever
> It stays as the engine underneath:
> * it calls the consumer route through an invoker (the registry entry, as 
> {{AiToolExecutor}} does for tools) instead of an endpoint URI; the public 
> constructor with an endpoint URI can stay for Java users
> * the bounded execution, timeout, {{onError}}, counters, body conversion and 
> cleanup move into the framework-neutral {{ai-retriever}} module, and 
> {{CamelContentRetriever}} becomes a thin LangChain4j adapter over it. Then 
> {{camel-openai}} can use the same sources (retrieve before the chat call and 
> inject the content) without LangChain4j, the way {{ai-tool}} serves 
> langchain4j-agent, camel-openai and the MCP server today.
> h3. What it brings
> * RAG with no Java: YAML, XML and Kaoto users get it, and the retrieval 
> routes show in the TUI, the route diagrams and {{camel get}} like any other 
> route
> * one retrieval route serves every AI producer, and could later become an MCP 
> resource template too
> * no new mental model: "tag your routes, name the tags on the producer" is 
> how tools already work
> h3. Open points
> * the name: {{ai-retriever}} or {{ai-knowledge}}
> * reuse {{ai-resource}} instead? It is also a read-only route, but it has no 
> query, its URIs are for MCP clients, and it lacks the result shaping; a 
> separate endpoint is clearer
> * whether {{LanguageModelQueryRouter}} uses the agent's chat model or a 
> separate, cheaper one ({{retrieverRoutingModel}})
> _Claude Code on behalf of davsclaus_



--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

Reply via email to