# Perform Text Embedding

## Handler Parameters

For Onnx models available on a target system:

| Parameter          | Definition                                        | Example         | Default                    |
| ------------------ | ------------------------------------------------- | --------------- | -------------------------- |
| model.store.system | Name of the system to get Onnx model details from | model\_fs       | A default huggingface repo |
| model.path         | File path for the model to use                    | /model.onnx     | A default ONNX model       |
| tokenizer.path     | File path for the tokenizer to use                | /tokenizer.json | A default tokenizer        |
| model.local.dir    | Local directory to store downloaded model files   | /app/models     | System temp dir            |

For non-Onnx models serviced through custom embedding classes:

| Parameter        | Definition                                                      | Example                                           | Default |
| ---------------- | --------------------------------------------------------------- | ------------------------------------------------- | ------- |
| embedding.class  | Java class for using a custom embedding provider                | dev.langchain4j.model.openai.OpenAiEmbeddingModel | -       |
| embeddingMethods | Json object configuration of methods to call on embedding class | {"apiKey": "xxx"}                                 | -       |

This handler requires the following dependency added to [deployment contents](https://docs.rierino.com/devops/microservices/deployments/defining-a-deployment) as well as any custom embedding class dependencies:

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

## Actions

### EmbedText

Transforms text into an embedding. Event metadata fields applicable for this action are as follows:

| Field         | Definition                                         | Example | Default |
| ------------- | -------------------------------------------------- | ------- | ------- |
| inputElement  | Json path for the input in request event payload   | input   | -       |
| outputElement | Json path for the output in response event payload | output  | -       |

With event metadata parameters as:

| Parameter    | Definition                                                                                                  | Example                  | Default |
| ------------ | ----------------------------------------------------------------------------------------------------------- | ------------------------ | ------- |
| inputPattern | JMESpath pattern to apply on input element for getting text and metadata fields                             | {text: "", metadata: ""} | -       |
| extraAction  | Optional extra action to perform after generating embedding ("add" to local index, "search" in local index) | add                      | -       |
| maxResults   | Maximum results to return if "search" extra action is used                                                  | 5                        | -       |
| minScore     | Minimum similarity score required  if "search" extra action is used                                         | 0.5                      | -       |

Input element can be a text value, or an object in {chat, message} format, where "chat" field includes ID of an ongoing chat for an assistant type use case with memory.
