# Vector Search

> Performs a semantic search against a Vector Database.

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

- Slug: `ai.vector.search`
- Family: AI
- Version: 1.0.0
- Status: Experimental. Calls a backend vector search endpoint that does not exist yet: the node cannot return results.
- Execution: async

Performs a semantic search against a Vector Database.

Finds records that are semantically similar to the query vector. Used as the core retrieval step in RAG pipelines.

**Features:**
- **Metadata Filtering:** Restrict search to specific documents (e.g., `{ "user_id": "123" }`).
- **Top-K:** precise control over number of results.
- **Metric:** Cosine Similarity, Euclidean Distance, etc. (DB dependent).

## Configuration

- `index` (string, required): Name of the Vector Index/Collection.
- `k` (integer, optional): Number of results to retrieve. Default: `5`.
- `min_score` (number, optional): Similarity threshold (0.0 - 1.0). Default: `0.7`.

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

- `out` (default): Found matching records.
- `miss`: No matches above threshold.
- `error`: Error

## Input contract

- `vector` (array<number>, required): The embedding vector to search for.
- `filter` (object, optional): Metadata filter object.

## Output contract

- `hits` (array<object>, optional)

## In expressions

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

- `$("Vector Search").item.json.hits` (array) **The worker does not return it: reads as undefined.**
- `$("Vector Search").item.json.__port` (string) = `"success"` (Not suggested by the editor)
- `$("Vector Search").item.json.matches` (array) = `[…] (1)` (Not suggested by the editor)
- `$("Vector Search").item.json.count` (number) = `1` (Not suggested by the editor)


## How it works

Experimental. Sends `vector`, `top_k` and `filter` to a backend vector-search endpoint that does not exist yet, so the node cannot return results 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 `datasource_id` (not the declared `index`) and `vector`; a missing one is thrown.
3. POSTs `{ datasource_id, vector, top_k, filter }` to the backend (`top_k` defaults to 5). A 404 is thrown as `Vector Search service not available on Backend`.
4. If the backend answered with success, it would return `{ __port, matches, count }` with no `port`, so the engine would route to `out` with that whole object as data.

## In a workflow

### Node

```json
{
  "node_id": "node-vector-search",
  "label": "Search similar chunks",
  "operator_slug": "ai.vector.search",
  "operator_version": "1.0.0",
  "config": {
    "index": "handbook",
    "datasource_id": "<datasource_id>",
    "top_k": 5
  }
}
```

### Envelope

```json
{
  "ok": true,
  "port": "out",
  "data": {
    "__port": "success",
    "matches": [
      {
        "id": "doc-001#3",
        "score": 0.83,
        "metadata": {
          "source": "handbook.pdf",
          "page": 12
        },
        "text": "Refunds are processed within 5 business days."
      }
    ],
    "count": 1
  }
}
```

## Output ports (behaviour in the code)

### `out`

Only if the backend endpoint existed and answered `success`. Shape the code would return:

```json
{
  "__port": "success",
  "matches": [
    {
      "id": "doc-001#3",
      "score": 0.83,
      "metadata": {
        "source": "handbook.pdf",
        "page": 12
      },
      "text": "Refunds are processed within 5 business days."
    }
  ],
  "count": 1
}
```

### `miss`

Never fires. With no matches the code sets `__port: "empty"`, which the engine ignores, and still routes to `out`.

### `error`

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

## Behaviour in the code

- `datasource_id / top_k`: Read by the code but not declared; `datasource_id` is required. Add them to the node config.
- `index / k / min_score`: Declared but ignored. No similarity threshold is applied.

## Errors

| Message | Port | Cause and fix |
| --- | --- | --- |
| `Missing 'datasource_id' config. Set a target datasource 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 'vector' input. Provide a vector to search with.` | `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. |
| `Vector Search service not available on Backend` | `error` | The backend does not expose the vector-search 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 search to call. 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.search",
  "name": "Vector Search",
  "category": "ai",
  "version": "1.0.0",
  "description": "Performs a semantic search against a Vector Database.\n\n  Finds records that are semantically similar to the query vector. Used as the core retrieval step in RAG pipelines.\n\n  **Features:**\n  - **Metadata Filtering:** Restrict search to specific documents (e.g., `{ \"user_id\": \"123\" }`).\n  - **Top-K:** precise control over number of results.\n  - **Metric:** Cosine Similarity, Euclidean Distance, etc. (DB dependent).",
  "capabilities": [
    "vector",
    "search",
    "rag",
    "retrieval"
  ],
  "config_schema": {
    "type": "object",
    "required": [
      "index"
    ],
    "properties": {
      "index": {
        "type": "string",
        "title": "Result Index",
        "description": "Name of the Vector Index/Collection."
      },
      "k": {
        "type": "integer",
        "default": 5,
        "title": "Top K",
        "description": "Number of results to retrieve."
      },
      "min_score": {
        "type": "number",
        "default": 0.7,
        "title": "Min Score",
        "description": "Similarity threshold (0.0 - 1.0)."
      },
      "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": {
      "vector": {
        "type": "array",
        "items": {
          "type": "number"
        },
        "description": "The embedding vector to search for."
      },
      "filter": {
        "type": "object",
        "description": "Metadata filter object."
      }
    },
    "required": [
      "vector"
    ]
  },
  "output_contract_schema": {
    "type": "object",
    "properties": {
      "hits": {
        "type": "array",
        "items": {
          "type": "object",
          "properties": {
            "id": {
              "type": "string"
            },
            "score": {
              "type": "number"
            },
            "metadata": {
              "type": "object"
            },
            "text": {
              "type": "string",
              "description": "Original text content (if stored)."
            }
          }
        }
      }
    }
  },
  "ports": [
    {
      "port_id": "out",
      "label": "Hits",
      "is_default": true,
      "description": "Found matching records."
    },
    {
      "port_id": "miss",
      "label": "No Results",
      "description": "No matches above threshold."
    },
    {
      "port_id": "error",
      "label": "Error"
    }
  ],
  "execution_mode": "async",
  "tags": [
    "vector",
    "search",
    "pinecone",
    "weaviate"
  ],
  "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": "Result Index",
      "description": "Name of the Vector Index/Collection."
    },
    "k": {
      "type": "integer",
      "default": 5,
      "title": "Top K",
      "description": "Number of results to retrieve."
    },
    "min_score": {
      "type": "number",
      "default": 0.7,
      "title": "Min Score",
      "description": "Similarity threshold (0.0 - 1.0)."
    },
    "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": {
    "vector": {
      "type": "array",
      "items": {
        "type": "number"
      },
      "description": "The embedding vector to search for."
    },
    "filter": {
      "type": "object",
      "description": "Metadata filter object."
    }
  },
  "required": [
    "vector"
  ]
}
```

### output_contract_schema

```json
{
  "type": "object",
  "properties": {
    "hits": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "score": {
            "type": "number"
          },
          "metadata": {
            "type": "object"
          },
          "text": {
            "type": "string",
            "description": "Original text content (if stored)."
          }
        }
      }
    }
  }
}
```

### ports

```json
[
  {
    "port_id": "out",
    "label": "Hits",
    "is_default": true,
    "description": "Found matching records."
  },
  {
    "port_id": "miss",
    "label": "No Results",
    "description": "No matches above threshold."
  },
  {
    "port_id": "error",
    "label": "Error"
  }
]
```
