[ 
https://issues.apache.org/jira/browse/CAMEL-25049?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Luigi De Masi updated CAMEL-25049:
----------------------------------
    Description: 
h2. Motivation

The semantic language introduced by CAMEL-24977 and [PR 
#26813|https://github.com/apache/camel/pull/26813] evaluates one named question 
per invocation. Routes that need several independent judgments about the same 
message currently require separate evaluations.

Add explicit batching of existing named questions, returning answers keyed by 
question name for reuse across ordinary Camel EIPs. TypeSafe AI already 
supports mixed Boolean, Choice and Score questions in one request with a shared 
state.

This is a separate, backward-compatible follow-up to CAMEL-24977.
h2. Proposed approach
 * Reuse existing named question definitions, decision thresholds and 
uncertainty policies.
 * Support an explicit batch expression through the existing generic language 
integration. Illustrative syntax, subject to review:
{code:java}
.setProperty("decision")
    .language("semantic", "refs:urgent,department,priority")
{code}

 * Return a map of normalized decisions keyed by question name, for example 
{{{}urgent -> true{}}}, {{department -> "billing"}} and {{{}priority -> 
2.4{}}}. Preserve detailed per-question results, including available 
probabilities, confidence and provider metadata.
 * Keep Camel's existing model and core Java DSL unchanged. Java, XML and YAML 
use the same semantic expression text. Define unambiguous reference parsing, 
including the treatment of delimiters in question names.
 * Preserve {{{}ref:name{}}}, its return type and existing single-question 
result metadata. Preserve {{{}SemanticAdapter.evaluate(SemanticQuestion, 
Object){}}}.
 * Add a default batch method to {{SemanticAdapter}} that delegates to existing 
single-question evaluation. Existing adapters continue working without 
implementing a new abstract method. Override it in 
{{TypeSafeAiSemanticAdapter}} to send all selected questions in one HTTP 
request. Document that the default fallback performs sequential calls.
 * Initially require all selected questions to use the same effective state 
selector. Evaluate that selector once per batch; reject incompatible selectors 
instead of silently changing a question's input. Questions that depend on an 
earlier answer remain separate evaluations.

h2. Correctness and validation
 * Reject empty selections, duplicate or unknown references, unsupported 
question capabilities and incompatible state selectors before inference where 
possible.
 * Resolve a consistent set of question definitions for each batch, including 
after route/resource reload.
 * Validate the complete response and apply each question's existing decision 
policy before exposing batch results. Missing, extra or invalid answers and 
provider failures follow Camel error handling; valid negative decisions and 
configured uncertainty policies retain their existing meaning.
 * Preserve interruption and lifecycle behavior. Do not expose partial or stale 
batch diagnostics after failure.
 * Batch expressions return maps, with no implicit AND/OR predicate conversion 
and no implicit caching or batching across exchanges.

h2. Acceptance criteria
 * Mixed Boolean, Choice and Score questions work in one batch; the TypeSafe 
adapter makes exactly one HTTP request.
 * Existing single-question routes and adapters continue to work unchanged; the 
default fallback is covered.
 * Tests cover reference validation, state selection, per-question 
decision/uncertainty policies, malformed/provider responses, failure cleanup 
and reload consistency.
 * Document Java and YAML examples, result reuse, provider fallback behavior 
and the shared-state restriction; regenerate affected catalog 
documentation/tooling artifacts.

h2. References
 * CAMEL-24977
 * [Apache Camel PR #26813|https://github.com/apache/camel/pull/26813]
 * [TypeSafe AI: asking multiple questions 
together|https://docs.typesafe.ai/primitives#ask-multiple-questions-together]

_Filed_ _by Codex on behalf of  [~ldemasi]._

  was:
h2. Motivation

The semantic language introduced by CAMEL-24977 and [PR 
#26813|https://github.com/apache/camel/pull/26813] evaluates one named question 
per invocation. Routes that need several independent judgments about the same 
message currently require separate evaluations.

Add explicit batching of existing named questions, returning answers keyed by 
question name for reuse across ordinary Camel EIPs. TypeSafe AI already 
supports mixed Boolean, Choice and Score questions in one request with a shared 
state.

This is a separate, backward-compatible follow-up to CAMEL-24977.

h2. Proposed approach

* Reuse existing named question definitions, decision thresholds and 
uncertainty policies.
* Support an explicit batch expression through the existing generic language 
integration. Illustrative syntax, subject to review:
{code:java}
.setProperty("decision")
    .language("semantic", "refs:urgent,department,priority")
{code}
* Return a map of normalized decisions keyed by question name, for example 
{{urgent -> true}}, {{department -> "billing"}} and {{priority -> 2.4}}. 
Preserve detailed per-question results, including available probabilities, 
confidence and provider metadata.
* Keep Camel's existing model and core Java DSL unchanged. Java, XML and YAML 
use the same semantic expression text. Define unambiguous reference parsing, 
including the treatment of delimiters in question names.
* Preserve {{ref:name}}, its return type and existing single-question result 
metadata. Preserve {{SemanticAdapter.evaluate(SemanticQuestion, Object)}}.
* Add a default batch method to {{SemanticAdapter}} that delegates to existing 
single-question evaluation. Existing adapters continue working without 
implementing a new abstract method. Override it in 
{{TypeSafeAiSemanticAdapter}} to send all selected questions in one HTTP 
request. Document that the default fallback performs sequential calls.
* Initially require all selected questions to use the same effective state 
selector. Evaluate that selector once per batch; reject incompatible selectors 
instead of silently changing a question's input. Questions that depend on an 
earlier answer remain separate evaluations.

h2. Correctness and validation

* Reject empty selections, duplicate or unknown references, unsupported 
question capabilities and incompatible state selectors before inference where 
possible.
* Resolve a consistent set of question definitions for each batch, including 
after route/resource reload.
* Validate the complete response and apply each question's existing decision 
policy before exposing batch results. Missing, extra or invalid answers and 
provider failures follow Camel error handling; valid negative decisions and 
configured uncertainty policies retain their existing meaning.
* Preserve interruption and lifecycle behavior. Do not expose partial or stale 
batch diagnostics after failure.
* Batch expressions return maps, with no implicit AND/OR predicate conversion 
and no implicit caching or batching across exchanges.

h2. Acceptance criteria

* Mixed Boolean, Choice and Score questions work in one batch; the TypeSafe 
adapter makes exactly one HTTP request.
* Existing single-question routes and adapters continue to work unchanged; the 
default fallback is covered.
* Tests cover reference validation, state selection, per-question 
decision/uncertainty policies, malformed/provider responses, failure cleanup 
and reload consistency.
* Document Java and YAML examples, result reuse, provider fallback behavior and 
the shared-state restriction; regenerate affected catalog documentation/tooling 
artifacts.

h2. References

* CAMEL-24977
* [Apache Camel PR #26813|https://github.com/apache/camel/pull/26813]
* [TypeSafe AI: asking multiple questions 
together|https://docs.typesafe.ai/primitives#ask-multiple-questions-together]

_AI-generated by Codex on behalf of luigidemasi._



> camel-semantic: Support batching multiple named questions
> ---------------------------------------------------------
>
>                 Key: CAMEL-25049
>                 URL: https://issues.apache.org/jira/browse/CAMEL-25049
>             Project: Camel
>          Issue Type: Improvement
>          Components: camel-ai
>            Reporter: Luigi De Masi
>            Assignee: Luigi De Masi
>            Priority: Minor
>             Fix For: 4.23.0
>
>
> h2. Motivation
> The semantic language introduced by CAMEL-24977 and [PR 
> #26813|https://github.com/apache/camel/pull/26813] evaluates one named 
> question per invocation. Routes that need several independent judgments about 
> the same message currently require separate evaluations.
> Add explicit batching of existing named questions, returning answers keyed by 
> question name for reuse across ordinary Camel EIPs. TypeSafe AI already 
> supports mixed Boolean, Choice and Score questions in one request with a 
> shared state.
> This is a separate, backward-compatible follow-up to CAMEL-24977.
> h2. Proposed approach
>  * Reuse existing named question definitions, decision thresholds and 
> uncertainty policies.
>  * Support an explicit batch expression through the existing generic language 
> integration. Illustrative syntax, subject to review:
> {code:java}
> .setProperty("decision")
>     .language("semantic", "refs:urgent,department,priority")
> {code}
>  * Return a map of normalized decisions keyed by question name, for example 
> {{{}urgent -> true{}}}, {{department -> "billing"}} and {{{}priority -> 
> 2.4{}}}. Preserve detailed per-question results, including available 
> probabilities, confidence and provider metadata.
>  * Keep Camel's existing model and core Java DSL unchanged. Java, XML and 
> YAML use the same semantic expression text. Define unambiguous reference 
> parsing, including the treatment of delimiters in question names.
>  * Preserve {{{}ref:name{}}}, its return type and existing single-question 
> result metadata. Preserve {{{}SemanticAdapter.evaluate(SemanticQuestion, 
> Object){}}}.
>  * Add a default batch method to {{SemanticAdapter}} that delegates to 
> existing single-question evaluation. Existing adapters continue working 
> without implementing a new abstract method. Override it in 
> {{TypeSafeAiSemanticAdapter}} to send all selected questions in one HTTP 
> request. Document that the default fallback performs sequential calls.
>  * Initially require all selected questions to use the same effective state 
> selector. Evaluate that selector once per batch; reject incompatible 
> selectors instead of silently changing a question's input. Questions that 
> depend on an earlier answer remain separate evaluations.
> h2. Correctness and validation
>  * Reject empty selections, duplicate or unknown references, unsupported 
> question capabilities and incompatible state selectors before inference where 
> possible.
>  * Resolve a consistent set of question definitions for each batch, including 
> after route/resource reload.
>  * Validate the complete response and apply each question's existing decision 
> policy before exposing batch results. Missing, extra or invalid answers and 
> provider failures follow Camel error handling; valid negative decisions and 
> configured uncertainty policies retain their existing meaning.
>  * Preserve interruption and lifecycle behavior. Do not expose partial or 
> stale batch diagnostics after failure.
>  * Batch expressions return maps, with no implicit AND/OR predicate 
> conversion and no implicit caching or batching across exchanges.
> h2. Acceptance criteria
>  * Mixed Boolean, Choice and Score questions work in one batch; the TypeSafe 
> adapter makes exactly one HTTP request.
>  * Existing single-question routes and adapters continue to work unchanged; 
> the default fallback is covered.
>  * Tests cover reference validation, state selection, per-question 
> decision/uncertainty policies, malformed/provider responses, failure cleanup 
> and reload consistency.
>  * Document Java and YAML examples, result reuse, provider fallback behavior 
> and the shared-state restriction; regenerate affected catalog 
> documentation/tooling artifacts.
> h2. References
>  * CAMEL-24977
>  * [Apache Camel PR #26813|https://github.com/apache/camel/pull/26813]
>  * [TypeSafe AI: asking multiple questions 
> together|https://docs.typesafe.ai/primitives#ask-multiple-questions-together]
> _Filed_ _by Codex on behalf of  [~ldemasi]._



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to