API version: 0.3.0

---

# Vector

`vector` holds an embedding, a list of numbers with a fixed number of dimensions.

| Value                                | Example              |
| ------------------------------------ | -------------------- |
| list of exactly `dimensions` numbers | `[0.12, -0.5, 0.33]` |

## Settings

| Setting       | Meaning                                                                                                                                                                                                     |
| ------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `dimensions`  | Required, except for embeddings. The number of dimensions, a positive whole number.                                                                                                                         |
| `elementType` | `float` (default), `byte` (whole numbers from -128 to 127) or `bit` (8 dimensions per number, `dimensions` has to be a multiple of 8).                                                                      |
| `similarity`  | `cosine` (default), `dot_product`, `l2_norm` or `max_inner_product`. `bit` vectors only use `l2_norm`.                                                                                                      |
| `embedding`   | Optional, top level properties only. Lets the API calculate the vector from a text, see [embeddings](#embeddings).                                                                                          |
| `visibility`  | `hidden` (default) or `public`. Hidden vectors are stored and searchable but not part of element responses, see [visibility](/reference/schemas.md#visibility). The normalized definition always states it. |

Values are lists of numbers with exactly `dimensions` entries. Vectors of the type `bit` store 8 dimensions in every
integer (-128 to 127), so values have `dimensions / 8` entries. A vector can be required like every property, but it
can not be the `items` of a list. The index is described in [vector indices](/reference/indices/vector.md), searching by
vector similarity in the [vector search example](/reference/search/elasticsearch-query-dsl-mixin/vector-search.md).

## Embeddings

With `embedding`, the vector is calculated by the API instead of being written by clients:

| Setting    | Meaning                                                                                                                  |
| ---------- | ------------------------------------------------------------------------------------------------------------------------ |
| `provider` | Required. The name of an [embedding provider](/reference/configuration.md) of the configuration.                         |
| `source`   | Required. An [Expr Lang](/reference/formats-and-languages/expr-lang.md) expression which returns the text of the vector. |

- `dimensions` is taken from the provider and stored in the normalized definition, so the index always matches the
  vectors of the provider. It can be stated, but has to be the number of the provider. `elementType` is always `float`.
- The source only sees the element itself: `elementType`, the node label or relation type, and `document`, the
  properties of the element like in [rules](/reference/schemas/rules.md), without internal properties and without the
  vectors of embeddings. A string is the text of the vector; `null` and empty strings mean that the element has no text.
- Requests can not write the vector, `400 Bad Request` names the provider. `PUT` keeps it.
- When an element is written, its text is compared with the text before the write. A new or changed text announces the
  element to the background job `cron:calculate-embeddings`, which runs every 5 minutes, sends the texts to the
  provider and writes the vectors. Until then the previous vector stays, new elements have none. No text removes the
  vector right away.
- Writing the vector changes `updatedAt`, but not `updatedBy`.
- If the source fails or returns something else than a string or `null`, or the provider fails, the error is logged and
  the vector is not changed. A missing vector is calculated again on the next write of the element.
- Changing the source of a schema does not calculate the vectors of existing elements again.

```json
{
  "type": "vector",
  "embedding": {
    "provider": "openai",
    "source": "document.title != nil && document.description != nil ? document.title + \": \" + document.description : nil"
  },
  "index": "vector"
}
```

## Storage

| Database      | Stored as        | Notes                                                                                                                      |
| ------------- | ---------------- | -------------------------------------------------------------------------------------------------------------------------- |
| MongoDB       | array of numbers | (default)                                                                                                                  |
| Neo4j         | list of numbers  | with `"storage": "graph"` or the [placement role](/reference/schemas/placement.md#placement-roles) `vector` moved to Neo4j |
| Elasticsearch | `dense_vector`   | search copy, indexed for the intent `vector`                                                                               |

The [search copy](/reference/databases/elasticsearch.md) is written unless the property or the type sets `"search": false`.
Where a property is stored is explained in [placement](/reference/schemas/placement.md).

## Indices

`vector`, also inside objects, see [the vector intent](/reference/indices/vector.md).

## Limits

The API does not limit the number of dimensions. Elasticsearch accepts at most 4096 dimensions for `dense_vector`,
see [Elasticsearch](/reference/databases/elasticsearch.md).

## Example

Schema:

```json
{
  "type": "vector",
  "dimensions": 3,
  "similarity": "cosine",
  "index": "vector"
}
```

Input, the element response does not contain the hidden vector unless the schema sets `"visibility": "public"`:

```json
{
  "data": {
    "embedding": [
      0.12,
      -0.5,
      0.33
    ]
  }
}
```

---

Home: [Ember Nexus API docs](/index.md)

Full site map: [llms.txt](/llms.txt)

Previous: [List](/reference/schemas/types/list.md)

Next: [Placement](/reference/schemas/placement.md)
