Claus Ibsen created CAMEL-27736:
-----------------------------------

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