> For the complete documentation index, see [llms.txt](https://docs.rierino.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.rierino.com/devops/microservices/building-blocks/execution-handlers/ml-and-ai-handlers.md).

# ML & AI Handlers

ML & AI handlers allow incorporation of AI agent and machine learning capabilities

ML & AI handlers add model inference, LLM orchestration, embeddings, and AI protocol support.

Use this page for handler-level details:

* Class names
* Handler parameters
* Runtime dependencies
* Built-in variants

Use [ML & AI Actions](https://docs.rierino.com/devops/api-event-and-process-flows/configuring-saga-steps/event-step/ml-and-ai-actions.md) for action-level saga step fields and parameters.

### Use ML Models

Classes:

* `com.rierino.handler.tensor.TensorScoreEventHandler`
* `com.rierino.handler.onnx.OnnxScoreEventHandler`
* `com.rierino.handler.pmml.PMMLScoreEventHandler`
* `com.rierino.handler.opennlp.OpenNLPScoreEventHandler`

Runs real-time inference using pre-trained ML models.

#### Handler parameters

| Parameter            | Definition                                                                                           | Example          | Default          |
| -------------------- | ---------------------------------------------------------------------------------------------------- | ---------------- | ---------------- |
| `model.state`        | State manager with model configurations                                                              | `model`          | `genai_model`    |
| `model.id`           | Model id to run on this handler instance                                                             | `recommendation` | -                |
| `model.store.system` | System used to store model assets                                                                    | `hdfs_default`   | -                |
| `model.local.dir`    | Local directory used for model assets                                                                | `/tmp`           | `java.io.tmpdir` |
| `store.saga`         | Saga used to read and write chat memory. A model can override it with its own `memorySaga` parameter | `chat_memory`    | -                |
| `roles.variable`     | Variable that resolves the calling user's roles, checked against each model's allowed roles          | `user_roles`     | `user.roles`     |

This handler supports caching.

#### Runtime dependencies

TensorFlow:

```gradle
implementation (group:'com.rierino.custom', name: 'tensor', version:"${rierinoVersion}")
```

ONNX:

```gradle
implementation (group:'com.rierino.custom', name: 'onnx', version:"${rierinoVersion}")
```

PMML:

```gradle
implementation (group:'com.rierino.custom', name: 'pmml', version:"${rierinoVersion}")
```

OpenNLP:

```gradle
implementation (group:'com.rierino.custom', name: 'opennlp', version:"${rierinoVersion}")
```

Action details: [Use ML Models](https://docs.rierino.com/devops/api-event-and-process-flows/configuring-saga-steps/event-step/ml-and-ai-actions/use-ml-models.md)

### Use GenAI Models

Class: `com.rierino.handler.rai.RAIModelEventHandler`&#x20;

Legacy: `com.rierino.handler.langchain4j.LangChainModelEventHandler`

Runs LLM chat and image generation flows through different LLM model providers.

{% hint style="info" %}
The legacy LangChain handler is replaced by RAI handler, which provides a more efficient implementation with more flexible runtime & chat model configurations.
{% endhint %}

#### Handler parameters

| Parameter        | Definition                                                       | Example       | Default  |
| ---------------- | ---------------------------------------------------------------- | ------------- | -------- |
| `model.state`    | State manager with model configurations                          | `genai_model` | -        |
| `model.domain`   | Model domain to include                                          | `chat`        | -        |
| `saga.handler`   | Saga handler used for tool sagas                                 | -             | `saga`   |
| `saga.state`     | State manager with saga definitions used as tools                | -             | `saga`   |
| `schema.state`   | State manager with schema definitions used for state tools       | -             | `schema` |
| `script.handler` | Event handler that is used for executing scripts generated by AI | -             | `script` |

Action details: [Use GenAI Models](https://docs.rierino.com/devops/api-event-and-process-flows/configuring-saga-steps/event-step/ml-and-ai-actions/use-genai-models.md)

### Perform Text Embedding

Class: `com.rierino.handler.rai.EmbeddingEventHandler`

Legacy: `com.rierino.handler.langchain4j.EmbeddingEventHandler`

Creates embeddings for search and retrieval use cases.4

{% hint style="info" %}
The legacy LangChain handler is replaced by RAI handler, which provides a more efficient implementation with more flexible configurations.
{% endhint %}

#### Handler parameters

For ONNX-based models:

| Parameter            | Definition                                 | Example           | Default                   |
| -------------------- | ------------------------------------------ | ----------------- | ------------------------- |
| `model.store.system` | System to fetch ONNX model files from      | `model_fs`        | default Hugging Face repo |
| `model.path`         | Model file path                            | `/model.onnx`     | default ONNX model        |
| `tokenizer.path`     | Tokenizer file path                        | `/tokenizer.json` | default tokenizer         |
| `model.local.dir`    | Local directory for downloaded model files | `/app/models`     | system temp dir           |

For custom embedding providers:

| Parameter          | Definition                                         | Example                                             | Default |
| ------------------ | -------------------------------------------------- | --------------------------------------------------- | ------- |
| `embedding.class`  | Java class implementing the embedding provider     | `dev.langchain4j.model.openai.OpenAiEmbeddingModel` | -       |
| `embeddingMethods` | Method configuration passed to the embedding class | `{"apiKey":"xxx"}`                                  | -       |

Action details: [Perform Text Embedding](https://docs.rierino.com/devops/api-event-and-process-flows/configuring-saga-steps/event-step/ml-and-ai-actions/perform-text-embedding.md)

### **Perform Sparse Text Embedding**

Class: `com.rierino.handler.rai.SparseEmbeddingEventHandler`

Creates sparse (lexical) embeddings with SPLADE or BGE-M3 models. These are used for hybrid or keyword-aware search, for example with Elastic `sparse_vector` fields. It can also add embeddings to a local in-memory sparse store, or search that store.

{% hint style="info" %}
The local sparse store is meant for testing and small, single-replica use cases. For larger data, send the embeddings to a database that supports sparse vectors (such as Elastic) through a state and query manager.
{% endhint %}

#### **Handler parameters**

For single-file ONNX models:

| Parameter            | Definition                                          | Example         | Default                            |
| -------------------- | --------------------------------------------------- | --------------- | ---------------------------------- |
| `model.store.system` | System to fetch ONNX model files from               | `model_fs`      | default Hugging Face repo          |
| `sparse.path`        | Sparse model file path (falls back to `model.path`) | /splade.onnx    | `Qdrant/Splade_PP_en_v1` model     |
| `tokenizer.path`     | Tokenizer file path                                 | /tokenizer.json | `Qdrant/Splade_PP_en_v1` tokenizer |
| `model.local.dir`    | Local directory for downloaded model files          | `/app/models`   | system temp dir                    |

For multi-file ONNX bundles (models with external data files, such as BGE-M3):

| Parameter                 | Definition                                                          | Example                                     | Default                   |
| ------------------------- | ------------------------------------------------------------------- | ------------------------------------------- | ------------------------- |
| `sparse.bundle.path`      | Remote folder that holds the model bundle                           | `/bge-m3`                                   | -                         |
| `sparse.bundle.files`     | Comma-separated list of files to copy, keeping their original names | `model.onnx,model.onnx_data,tokenizer.json` | model and tokenizer files |
| `sparse.bundle.model`     | Model file name within the bundle                                   | `model.onnx`                                | `model.onnx`              |
| `sparse.bundle.tokenizer` | Tokenizer file name within the bundle                               | `tokenizer.json`                            | `tokenizer.json`          |

Bundles are cached locally and skip the download when the same bundle is already complete.

Common model options:

| Parameter     | Definition                                                 | Example         | Default                                        |
| ------------- | ---------------------------------------------------------- | --------------- | ---------------------------------------------- |
| `sparse.mode` | Sparse encoding mode: `SPLADE` or `TOKEN_WEIGHTS` (BGE-M3) | `TOKEN_WEIGHTS` | `SPLADE`                                       |
| `modelName`   | Model name reported by the model                           | `bge-m3`        | `Splade_PP_en_v1` (only for the default model) |
| `outputName`  | ONNX output tensor name to read                            | `sparse_vecs`   | model default                                  |
| `maxLength`   | Maximum token length                                       | `512`           | model default                                  |
| `minWeight`   | Minimum weight for a term to be kept                       | `0.01`          | model default                                  |
| `maxTerms`    | Maximum number of terms kept in the sparse vector          | `256`           | model default                                  |

For custom sparse embedding providers:

| Parameter        | Definition                                                | Example                                         | Default |
| ---------------- | --------------------------------------------------------- | ----------------------------------------------- | ------- |
| `sparse.class`   | Java class implementing the sparse embedding provider     | `io.rierino.rai.xxx.CustomSparseEmbeddingModel` | -       |
| `sparse.methods` | Method configuration passed to the sparse embedding class | `{"apiKey":"xxx"}`                              | -       |

Action details: [Perform Sparse Text Embedding](https://docs.rierino.com/devops/api-event-and-process-flows/configuring-saga-steps/event-step/ml-and-ai-actions/perform-sparse-text-embedding.md)

### **Rerank Documents**

Class: `com.rierino.handler.rai.RerankerEventHandler`

Scores candidate documents against a query and sorts them by relevance. It is typically used after a vector or keyword search to improve retrieval quality in RAG flows.

#### **Handler parameters**

For ONNX-based models:

| Parameter            | Definition                                            | Example         | Default                                   |
| -------------------- | ----------------------------------------------------- | --------------- | ----------------------------------------- |
| `model.store.system` | System to fetch ONNX model files from                 | `model_fs`      | default Hugging Face repo                 |
| `rerank.path`        | Reranker model file path (falls back to `model.path`) | /reranker.onnx  | `Xenova/ms-marco-MiniLM-L-6-v2` model     |
| `tokenizer.path`     | Tokenizer file path                                   | /tokenizer.json | `Xenova/ms-marco-MiniLM-L-6-v2` tokenizer |
| `model.local.dir`    | Local directory for downloaded model files            | `/app/models`   | system temp dir                           |
| `modelName`          | Model name reported by the reranker                   | `bge-reranker`  | `ms-marco-MiniLM-L-6-v2`                  |
| `normalize`          | Whether to normalize relevance scores                 | `true`          | model default                             |
| `maxLength`          | Maximum token length per query–document pair          | `512`           | model default                             |

For custom rerank providers:

| Parameter        | Definition                                      | Example                                | Default |
| ---------------- | ----------------------------------------------- | -------------------------------------- | ------- |
| `rerank.class`   | Java class implementing the rerank provider     | `io.rierino.rai.xxx.CustomRerankModel` | -       |
| `rerank.methods` | Method configuration passed to the rerank class | `{"apiKey":"xxx"}`                     | -       |

Action details: [Rerank Documents](https://docs.rierino.com/devops/api-event-and-process-flows/configuring-saga-steps/event-step/ml-and-ai-actions/rerank-documents.md)

### **Make AI Decisions**

Class: `com.rierino.handler.rai.RAIDecisionEventHandler`

Answers typed questions about a given state, which can include a conversation history. The question types are choice (classification), score (ordinal level) and noul (yes / no / unknown). Answers can include probabilities and confidence. By default it runs zero-shot classification on a local NLI model and makes no LLM call.

#### **Handler parameters**

For ONNX-based (NLI zero-shot) models:

| Parameter              | Definition                                                                    | Example                  | Default                                            |
| ---------------------- | ----------------------------------------------------------------------------- | ------------------------ | -------------------------------------------------- |
| `model.store.system`   | System to fetch ONNX model files from                                         | `model_fs`               | default Hugging Face repo                          |
| `decision.path`        | NLI model file path                                                           | /nli/model.onnx          | `Xenova/DeBERTa-v3-base-mnli-fever-anli` model     |
| `tokenizer.path`       | Tokenizer file path                                                           | /nli/tokenizer.json      | `Xenova/DeBERTa-v3-base-mnli-fever-anli` tokenizer |
| `decision.config.path` | Model `config.json` path, which sets the entailment/contradiction label order | /nli/config.json         | `Xenova/DeBERTa-v3-base-mnli-fever-anli` config    |
| `model.local.dir`      | Local directory for downloaded model files                                    | `/app/models`            | system temp dir                                    |
| `modelName`            | Model name reported in usage output                                           | `deberta-nli`            | `deberta-v3-base-mnli-fever-anli`                  |
| `hypothesisTemplate`   | Template used to build NLI hypotheses from questions                          | `This text is about {}.` | model default                                      |
| `maxLength`            | Maximum token length per premise–hypothesis pair                              | `512`                    | model default                                      |

For custom decision providers:

| Parameter          | Definition                                        | Example                                  | Default |
| ------------------ | ------------------------------------------------- | ---------------------------------------- | ------- |
| `decision.class`   | Java class implementing the decision provider     | `io.rierino.rai.xxx.CustomDecisionModel` | -       |
| `decision.methods` | Method configuration passed to the decision class | `{"apiKey":"xxx"}`                       | -       |

Classes:

* `io.rierino.rai.openai.OpenAiDecisionModel`
* `io.rierino.rai.laya.LayaDecisionModel`

Action details: [Make AI Decisions](https://docs.rierino.com/devops/api-event-and-process-flows/configuring-saga-steps/event-step/ml-and-ai-actions/make-ai-decisions.md)

### Service MCP Requests

Class: `com.rierino.handler.mcp.McpServerEventHandler`

Exposes existing microservice capabilities over MCP.

#### Handler parameters

| Parameter       | Definition                                        | Example       | Default       |
| --------------- | ------------------------------------------------- | ------------- | ------------- |
| `server.state`  | State manager with MCP server configurations      | `mcp_server`  | `genai_model` |
| `server.domain` | Server domain to include                          | `procurement` | -             |
| `saga.handler`  | Saga handler used for tool sagas                  | `ai_saga`     | `saga`        |
| `saga.state`    | State manager with saga definitions used as tools | `ai_saga`     | `saga`        |

Action details: [Service MCP Requests](https://docs.rierino.com/devops/api-event-and-process-flows/configuring-saga-steps/event-step/ml-and-ai-actions/service-mcp-requests.md)

### Service A2A Requests

Class: `com.rierino.handler.a2a.A2AServerEventHandler`

Exposes existing microservice capabilities over A2A.

#### Handler parameters

| Parameter       | Definition                                   | Example       | Default       |
| --------------- | -------------------------------------------- | ------------- | ------------- |
| `server.state`  | State manager with A2A server configurations | `mcp_server`  | `genai_model` |
| `server.domain` | Server domain to include                     | `procurement` | -             |
| `saga.handler`  | Saga handler used for tool sagas             | `ai_saga`     | `saga`        |

Action details: [Service A2A Requests](https://docs.rierino.com/devops/api-event-and-process-flows/configuring-saga-steps/event-step/ml-and-ai-actions/service-a2a-requests.md)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.rierino.com/devops/microservices/building-blocks/execution-handlers/ml-and-ai-handlers.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
