# `Embedding`

A list of numbers with the AI model that made it.

Use it to store model output, since vectors from different models can't be compared. For the numbers alone, use [`Vector`](/docs/types/type-vector.md).

## Shape

| Field | Type | Required? |
|---|---|---|
| `model` | [`ModelId`](/docs/types/type-model-id.md) | Yes |
| `vector` | [`Vector`](/docs/types/type-vector.md) | Yes |

## Example

```jadpo
Embedding {
    model: ModelId { provider: "openai" name: "text-embedding-3-small" }
    vector: [0.5, -0.25, 1.0]
}
```

## Good to know

- `==` tells you whether two are the same. `<` and `list.sort_by` don't take it, so sort by one of its parts instead.

## In JSON

An object of its parts, in a request, a response or `json.write`:

```json
{"model":"openai/text-embedding-3-small","vector":[0.5,-0.25,1]}
{"model":"ollama/nomic-embed-text","vector":[0.0123]}
```

## Details

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

`Embedding` 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 3 columns, each named for the field, `_` and its suffix. This is `{"model":"ollama/nomic-embed-text","vector":[0.0123]}`:

| Column | Type | Holds |
|---|---|---|
| `<field>_model_provider` | `text` | `'ollama'` |
| `<field>_model_name` | `text` | `'nomic-embed-text'` |
| `<field>_vector` | `vector` | `'[0.0123]'::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 |
|---|---|
| `{"model":"openai/text-embedding-3-small","vector":[0.5,-0.25,1]}` | `openai/text-embedding-3-small [0.5; -0.25; 1]` |
| `{"model":"ollama/nomic-embed-text","vector":[0.0123]}` | `ollama/nomic-embed-text [0.0123]` |

### Operations

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>
