# `Vector`

A list of numbers, as an AI model's embedding holds them.

Use it for similarity search. To keep the numbers with the model that made them, use [`Embedding`](/docs/types/type-embedding.md). For a fixed length, build your own type with `dimensions:`.

## Shape

A list of `Decimal`.

## Example

```jadpo
[0.5, -0.25, 1.0]
```

## Good to know

- It holds from 1 to 16,000 numbers.
- `==` tells you whether two are the same. `<` and `list.sort_by` don't take it.

## In JSON

An array of its items, in a request, a response or `json.write`:

```json
[0.5,-0.25,1]
[0.0123,-0.00456,0.789]
[1250.5]
```

## Details

<details>
<summary>Text form, storage, how it is shown, and operations</summary>

`Vector` is in the group Maths and data, and has been in Jadpo since 0.1.0.

### Text form

It has no single text form, so `text.from` and `text.parse` don't take it.

### How it is stored

It is stored in one column named for the field, of type `vector`. `[0.0123,-0.00456,0.789]` is stored as `'[0.0123,-0.00456,0.789]'::vector`.

### How it is shown to people

`text.format(value, locale:)` shows it to people in their locale.

With `locale: Locale.en_gb`:

| Value | Shown |
|---|---|
| `[0.5,-0.25,1]` | `[0.5; -0.25; 1]` |
| `[0.0123,-0.00456,0.789]` | `[0.0123; -0.00456; 0.789]` |
| `[1250.5]` | `[1,250.5]` |

### Operations

- `ai.distance(a: Vector, b: Vector) -> Decimal`: How far apart `a` and `b` are, two vectors of one type, as that type's `distance:` compares them and pgvector works it out: smaller is nearer. Cosine, the default, is from 0 to 2; euclidean from 0; inner product is the negative inner product.

It also takes `text.format`, `json.read`, `json.write` and `==`. [How every standard type behaves](/docs/every-standard-type-meets-one-contract.md) says how they work.

</details>
