# Generate Embeddings

> Converts text into high-dimensional vector embeddings.

Source: https://docs.sommatic.ai/en/nodes/ai.embed/

- Slug: `ai.embed`
- Family: AI
- Version: 1.0.0
- Status: Partial. On success the worker returns no port, so the engine follows `out`, which this node does not declare: an edge drawn from its success port never fires. Until it is fixed, do not chain nodes after its success path.
- Execution: async

Converts text into high-dimensional vector embeddings.

Embeddings capture the semantic meaning of text as a list of numbers (vectors). These vectors are essential for semantic search, clustering, and RAG (Retrieval Augmented Generation) workflows.

**Use Cases:**
- **Semantic Search:** Preparing data for vector database storage.
- **Clustering:** Grouping similar support tickets.
- **Classification:** Feeding downstream ML models.

## Configuration

- `llm_provider_id` (string, required): The `id` of a `LlmProviderModel` record configured for embeddings (e.g. `wf-llm-provider-*`). The orchestrator delegates to the backend endpoint `POST /cognitive-infrastructure/cognitive-assets/llm-provider/invoke` (operation: embedding). Embedding is sync-only — streaming does not apply. Managed in the webapp at `/cognitive-assets/llm-provider/*`.
- `timeout_ms` (integer, optional): Maximum time to wait for the embedding call to complete. Default 30000.

Its configuration shows the shared execution settings, but this node does not apply retries (`retryOnFail`, `maxTries`) yet. `continueOnFail` is not applied by any node.

## Output ports

- `success` (default): Embeddings generated.
- `error`: Error

## Input contract

- `input` (string | array, required): Text string or array of strings to embed.

## Output contract

- `embeddings` (array<number>, optional): Vector(s) representing the input text.

## In expressions

What a later node can read from this node's output with `$("Generate Embeddings").item.json.<path>` (write your node's label instead of `Generate Embeddings`). **Editor** marks the paths the workflow editor suggests under Previous Nodes (the output contract); **Worker** marks the paths the worker really returns through `success`, from the output shown in Ports.

- `$("Generate Embeddings").item.json.embeddings` (array) = `[…] (4)`: Vector(s) representing the input text.
- `$("Generate Embeddings").item.json.raw` (null) = `null` (Not suggested by the editor)


## How it works

Turns one text into an embedding vector through an embedding-capable provider record. Partial: on success it leaves through `out`, which is not a declared port.

1. Takes the text from the upstream payload: `$json.input`, else `$json.text`. Throws `Missing 'input'` when neither is set.
2. Sends one embedding request through the backend with `llm_provider_id`.
3. Returns `{ embeddings, raw }` with no port, so the engine routes it to `out`. `embeddings` is the single vector (array of numbers), or `null` if the backend answer had none.

## In a workflow

### Node

```json
{
  "node_id": "node-embed-chunk",
  "label": "Embed chunk",
  "operator_slug": "ai.embed",
  "operator_version": "1.0.0",
  "config": {
    "llm_provider_id": "wf-llm-provider-xxxx",
    "timeout_ms": 30000
  }
}
```

### Envelope

```json
{
  "ok": true,
  "data": {
    "embeddings": [
      0.0123,
      -0.0456,
      0.0789,
      0.0012
    ],
    "raw": null
  },
  "port": "out"
}
```

## Output ports (behaviour in the code)

### `success`

Declared but never emitted. On success the engine follows `out`; an edge drawn from `success` never fires. The data shown is what `out` carries.

```json
{
  "embeddings": [
    0.0123,
    -0.0456,
    0.0789,
    0.0012
  ],
  "raw": null
}
```

### `error`

No text was found, the input was not a string or the embedding call failed.

```json
{
  "error": "Missing 'input'"
}
```

## Behaviour in the code

- `input`: Cannot be set on the node: the runtime replaces any configured `input` with the upstream payload. Shape the previous node's output so that `$json.input` or `$json.text` holds the string, e.g. with `data.transform`.
- `timeout_ms`: Passed to the client but not applied to the HTTP request; the platform's default request timeout governs.
- `execution`: Declared but ignored: neither the worker nor the engine reads `retryOnFail`, `maxTries`, `waitBetweenTries`, `continueOnFail`, `alwaysOutputData` or `timeout_ms` from this block.

## Errors

| Message | Port | Cause and fix |
| --- | --- | --- |
| `Missing 'input'` | `error` | The upstream payload has neither `input` nor `text`. A value configured on the node is not used (see config). |
| `LlmInvocationClientService.invokeEmbedding: input (string) is required.` | `error` | The text is not a string, for example an array of strings. Only one string per run is supported; use `flow.split` for lists. |
| `[AiEmbed] Missing 'llm_provider_id' in node config (LlmProviderModel.id, e.g. 'wf-llm-provider-*'). The legacy 'model_id' alias is no longer supported — update the node config to use 'llm_provider_id'.` | `error` | `llm_provider_id` is empty or not a string. Pick a provider record with embedding capability. |
| `LLM Invocation Error (embedding): <backend message>` | `error` | The backend rejected the call (unknown provider record, provider without embeddings, provider error). An HTTP failure shows `LLM Invocation Error (embedding): empty response from backend (<transport error>)`. |

## Notes and limits

- Known defect: the success path returns no port, so the engine uses `out`, which the node does not declare. Do not chain nodes after its success path until it is fixed.
- The input contract allows an array, but only a single string works; the output is one vector, not a list of vectors.
- Embeddings are always synchronous; `invocation_mode` does not apply. `raw` is the provider's raw response when the backend returns it.
- No automatic retries: the engine does not honour `execution.retryOnFail`, `maxTries` or `waitBetweenTries` for this node; a failed call goes straight to `error`.


## Contracts (JSON Schema)

### All (`*.definition.js`)

```json
{
  "slug": "ai.embed",
  "name": "Generate Embeddings",
  "category": "ai",
  "version": "1.0.0",
  "description": "Converts text into high-dimensional vector embeddings.\n\n  Embeddings capture the semantic meaning of text as a list of numbers (vectors). These vectors are essential for semantic search, clustering, and RAG (Retrieval Augmented Generation) workflows.\n\n  **Use Cases:**\n  - **Semantic Search:** Preparing data for vector database storage.\n  - **Clustering:** Grouping similar support tickets.\n  - **Classification:** Feeding downstream ML models.",
  "capabilities": [
    "llm",
    "embeddings",
    "vector",
    "nlp"
  ],
  "config_schema": {
    "type": "object",
    "required": [
      "llm_provider_id"
    ],
    "properties": {
      "llm_provider_id": {
        "type": "string",
        "title": "LLM Provider (Embedding)",
        "description": "The `id` of a `LlmProviderModel` record configured for embeddings (e.g. `wf-llm-provider-*`). The orchestrator delegates to the backend endpoint `POST /cognitive-infrastructure/cognitive-assets/llm-provider/invoke` (operation: embedding). Embedding is sync-only — streaming does not apply. Managed in the webapp at `/cognitive-assets/llm-provider/*`.",
        "x-ui-widget": "llm-provider-picker",
        "x-llm-provider-capabilities": [
          "embedding"
        ]
      },
      "timeout_ms": {
        "type": "integer",
        "title": "Timeout (ms)",
        "description": "Maximum time to wait for the embedding call to complete. Default 30000.",
        "minimum": 1000
      },
      "execution": {
        "type": "object",
        "title": "Execution Settings",
        "properties": {
          "alwaysOutputData": {
            "type": "boolean",
            "title": "Always Output Data",
            "description": "Always output data, even on error (if configured).",
            "default": false
          },
          "retryOnFail": {
            "type": "boolean",
            "title": "Retry On Fail",
            "description": "Retry the execution if it fails.",
            "default": false
          },
          "maxTries": {
            "type": "integer",
            "title": "Max Retries",
            "description": "Number of retries.",
            "default": 3,
            "displayOptions": {
              "show": {
                "retryOnFail": [
                  true
                ]
              }
            }
          },
          "waitBetweenTries": {
            "type": "integer",
            "title": "Wait Between Retries (ms)",
            "default": 1000,
            "displayOptions": {
              "show": {
                "retryOnFail": [
                  true
                ]
              }
            }
          },
          "continueOnFail": {
            "type": "boolean",
            "title": "Continue On Fail",
            "description": "Do not crash workflow on error.",
            "default": false
          },
          "timeout_ms": {
            "type": "integer",
            "title": "Timeout (ms)",
            "description": "Max execution time for this node before it is killed, in milliseconds. Honored by long-running operators (e.g. OCR/extraction, inline code). Default 300000 (5 min).",
            "default": 300000
          }
        }
      }
    }
  },
  "input_contract_schema": {
    "type": "object",
    "properties": {
      "input": {
        "type": [
          "string",
          "array"
        ],
        "description": "Text string or array of strings to embed."
      }
    },
    "required": [
      "input"
    ]
  },
  "output_contract_schema": {
    "type": "object",
    "properties": {
      "embeddings": {
        "type": "array",
        "items": {
          "type": "number"
        },
        "description": "Vector(s) representing the input text."
      }
    }
  },
  "ports": [
    {
      "port_id": "success",
      "label": "Success",
      "is_default": true,
      "description": "Embeddings generated."
    },
    {
      "port_id": "error",
      "label": "Error"
    }
  ],
  "execution_mode": "async",
  "tags": [
    "ai",
    "vector",
    "embedding"
  ],
  "is_stateful": false,
  "publisher": {
    "identity": "org_sommatic_ai",
    "profile": {
      "name": "Sommatic AI",
      "verified": true,
      "url": "https://me.veripass.com/sommatic",
      "logo_url": null
    }
  }
}
```

### config_schema

```json
{
  "type": "object",
  "required": [
    "llm_provider_id"
  ],
  "properties": {
    "llm_provider_id": {
      "type": "string",
      "title": "LLM Provider (Embedding)",
      "description": "The `id` of a `LlmProviderModel` record configured for embeddings (e.g. `wf-llm-provider-*`). The orchestrator delegates to the backend endpoint `POST /cognitive-infrastructure/cognitive-assets/llm-provider/invoke` (operation: embedding). Embedding is sync-only — streaming does not apply. Managed in the webapp at `/cognitive-assets/llm-provider/*`.",
      "x-ui-widget": "llm-provider-picker",
      "x-llm-provider-capabilities": [
        "embedding"
      ]
    },
    "timeout_ms": {
      "type": "integer",
      "title": "Timeout (ms)",
      "description": "Maximum time to wait for the embedding call to complete. Default 30000.",
      "minimum": 1000
    },
    "execution": {
      "type": "object",
      "title": "Execution Settings",
      "properties": {
        "alwaysOutputData": {
          "type": "boolean",
          "title": "Always Output Data",
          "description": "Always output data, even on error (if configured).",
          "default": false
        },
        "retryOnFail": {
          "type": "boolean",
          "title": "Retry On Fail",
          "description": "Retry the execution if it fails.",
          "default": false
        },
        "maxTries": {
          "type": "integer",
          "title": "Max Retries",
          "description": "Number of retries.",
          "default": 3,
          "displayOptions": {
            "show": {
              "retryOnFail": [
                true
              ]
            }
          }
        },
        "waitBetweenTries": {
          "type": "integer",
          "title": "Wait Between Retries (ms)",
          "default": 1000,
          "displayOptions": {
            "show": {
              "retryOnFail": [
                true
              ]
            }
          }
        },
        "continueOnFail": {
          "type": "boolean",
          "title": "Continue On Fail",
          "description": "Do not crash workflow on error.",
          "default": false
        },
        "timeout_ms": {
          "type": "integer",
          "title": "Timeout (ms)",
          "description": "Max execution time for this node before it is killed, in milliseconds. Honored by long-running operators (e.g. OCR/extraction, inline code). Default 300000 (5 min).",
          "default": 300000
        }
      }
    }
  }
}
```

### input_contract_schema

```json
{
  "type": "object",
  "properties": {
    "input": {
      "type": [
        "string",
        "array"
      ],
      "description": "Text string or array of strings to embed."
    }
  },
  "required": [
    "input"
  ]
}
```

### output_contract_schema

```json
{
  "type": "object",
  "properties": {
    "embeddings": {
      "type": "array",
      "items": {
        "type": "number"
      },
      "description": "Vector(s) representing the input text."
    }
  }
}
```

### ports

```json
[
  {
    "port_id": "success",
    "label": "Success",
    "is_default": true,
    "description": "Embeddings generated."
  },
  {
    "port_id": "error",
    "label": "Error"
  }
]
```
