# `Vector`

A list of 1 to 16,000 numbers, each a single-precision float, as a model's embedding is. A type built on it fixes how many with `dimensions:`.

[Maths and data](types.md#maths-and-data); not ordered; since Jadpo 0.1.0.

## Make one

It is a list of `Decimal`: build one from a list of them, as you build a named list type of your own.

## Text, JSON and storage

It has no single text form, so `text.from` and `text.parse` don't take it. JSON sends an array of its items.

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

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`.

## 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.

Like every standard type, it also has the contract's own operations: `text.format`, `json.read`, `json.write` and `==`. It isn't ordered, so `<` and sorting don't take it. [Every standard type meets one contract](../topics/every-standard-type-meets-one-contract.md) says how they work.
