# Upsert Vector

> Inserts or Updates records in a Vector Database.

Source: https://docs.sommatic.ai/en/nodes/ai.vector.upsert/

- Slug: `ai.vector.upsert`
- Family: AI
- Version: 1.0.0
- Status: Experimental. Calls a backend vector upsert endpoint that does not exist yet: nothing is stored.
- Execution: async

Inserts or Updates records in a Vector Database.

Used during the ingestion phase. It takes vectors (and their metadata/text) and stores them in the index for future retrieval.

**Use Cases:**
- Indexing a new document.
- Updating user profile embeddings.

## Configuration

- `index` (string, required)

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): Success
- `error`: Error

## Input contract

- `vectors` (array<object>, required): List of records to insert.

## Output contract

- `count` (number, optional): Number of records UPSERTED.

## In expressions

What a later node can read from this node's output with `$("Upsert Vector").item.json.<path>` (write your node's label instead of `Upsert Vector`). **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.

- `$("Upsert Vector").item.json.count` (number) = `2`: Number of records UPSERTED.
- `$("Upsert Vector").item.json.__port` (string) = `"success"` (Not suggested by the editor)


## How it works

Experimental. Sends `index` and `vectors` to a backend vector-upsert endpoint that does not exist yet, so nothing is stored today; the call fails and the run fails with it.

1. Resolves the node config: expressions in config keys are evaluated against the run; the incoming item is used as-is.
2. Merges the incoming item with the config and requires `index` and a non-empty `vectors` array; a missing one is thrown.
3. POSTs `{ index, vectors }` to the backend. A 404 is thrown as `Upsert service not available on Backend`.
4. If the backend answered with success, it would return `{ __port: "success", count }` with no `port`; the engine would route to `out`, which this node does not declare, so `success` edges would not run.

## In a workflow

### Node

```json
{
  "node_id": "node-vector-upsert",
  "label": "Store embeddings",
  "operator_slug": "ai.vector.upsert",
  "operator_version": "1.0.0",
  "config": {
    "index": "handbook"
  }
}
```

### Envelope

```json
{
  "ok": true,
  "port": "out",
  "data": {
    "__port": "success",
    "count": 2
  }
}
```

## Output ports (behaviour in the code)

### `success`

Never fires: even a successful call is routed to the undeclared `out`. Shape the code would return:

```json
{
  "__port": "success",
  "count": 2
}
```

### `error`

Never returned as an envelope: every failure is thrown and fails the run.

## Behaviour in the code

- `vectors`: Read from the incoming item (or a `vectors` config key, which may be an expression). Each record is `{ id, values, metadata }`; records are sent as they are, without validation.

## Errors

| Message | Port | Cause and fix |
| --- | --- | --- |
| `Missing 'index' config. Set a target index in the node configuration.` | `error` | Thrown, not returned as an envelope: the engine marks the run as failed, unless the node sits inside a `flow.try` scope, which receives the error on its catch branch. |
| `Missing or empty 'vectors' input. Provide at least one vector record.` | `error` | Thrown, not returned as an envelope: the engine marks the run as failed, unless the node sits inside a `flow.try` scope, which receives the error on its catch branch. |
| `Upsert service not available on Backend` | `error` | The backend does not expose the vector-upsert endpoint yet (HTTP 404). Thrown: the run fails unless a `flow.try` scope catches it. |

## Notes and limits

- Not implemented on the backend: there is no vector store to write to. Do not use this node in production workflows.
- The backend request has no timeout set.


## Contracts (JSON Schema)

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

```json
{
  "slug": "ai.vector.upsert",
  "name": "Upsert Vector",
  "category": "ai",
  "version": "1.0.0",
  "description": "Inserts or Updates records in a Vector Database.\n\n  Used during the ingestion phase. It takes vectors (and their metadata/text) and stores them in the index for future retrieval.\n\n  **Use Cases:**\n  - Indexing a new document.\n  - Updating user profile embeddings.",
  "capabilities": [
    "vector",
    "database",
    "write",
    "upsert"
  ],
  "config_schema": {
    "type": "object",
    "required": [
      "index"
    ],
    "properties": {
      "index": {
        "type": "string",
        "title": "Target Index"
      },
      "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": {
      "vectors": {
        "type": "array",
        "description": "List of records to insert.",
        "items": {
          "type": "object",
          "properties": {
            "id": {
              "type": "string"
            },
            "values": {
              "type": "array",
              "items": {
                "type": "number"
              }
            },
            "metadata": {
              "type": "object"
            }
          }
        }
      }
    },
    "required": [
      "vectors"
    ]
  },
  "output_contract_schema": {
    "type": "object",
    "properties": {
      "count": {
        "type": "number",
        "description": "Number of records UPSERTED."
      }
    }
  },
  "ports": [
    {
      "port_id": "success",
      "label": "Success",
      "is_default": true
    },
    {
      "port_id": "error",
      "label": "Error"
    }
  ],
  "execution_mode": "async",
  "tags": [
    "vector",
    "write",
    "database"
  ],
  "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": [
    "index"
  ],
  "properties": {
    "index": {
      "type": "string",
      "title": "Target Index"
    },
    "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": {
    "vectors": {
      "type": "array",
      "description": "List of records to insert.",
      "items": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "values": {
            "type": "array",
            "items": {
              "type": "number"
            }
          },
          "metadata": {
            "type": "object"
          }
        }
      }
    }
  },
  "required": [
    "vectors"
  ]
}
```

### output_contract_schema

```json
{
  "type": "object",
  "properties": {
    "count": {
      "type": "number",
      "description": "Number of records UPSERTED."
    }
  }
}
```

### ports

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