# CREATE TABLE with Vectors

<table data-view="cards"><thead><tr><th align="center"></th><th align="center"></th><th align="center"></th><th data-hidden data-card-cover data-type="files"></th></tr></thead><tbody><tr><td align="center"><strong>WEBINAR</strong></td><td align="center">The Next Generation of MariaDB: Powered by Vector Search</td><td align="center"><a href="https://go.mariadb.com/GLBL-WBN-2025-01-30-WhatsnewinMariaDB-ES.html?utm_source=onpagepromo&#x26;utm_medium=kb&#x26;utm_campaign=webinar-platform-vector"><strong>Watch Now</strong></a></td><td><a href="broken-reference">Broken file</a></td></tr></tbody></table>

{% hint style="info" %}
[Vectors](https://mariadb.com/docs/server/reference/sql-structure/vectors) are available from [MariaDB 11.7](https://app.gitbook.com/s/aEnK0ZXmUbJzqQrTjFyb/community-server/old-releases/11.7/what-is-mariadb-117).
{% endhint %}

MariaDB has a dedicated [VECTOR(N)](https://mariadb.com/docs/server/reference/sql-structure/vectors/vector) data type with a built-in data validation. `N` is the number of dimensions that all vector values in the column have.

{% hint style="info" %}

* Vector indexes are dimensionality-specific.
* All vectors inserted into an indexed column must match the index's target dimensionality.
* Inserting vectors with different dimensionalities will result in an error.
  {% endhint %}

Consider the following table:

```sql
CREATE TABLE embeddings (
        doc_id BIGINT UNSIGNED PRIMARY KEY,
        embedding VECTOR(1536)
);
```

To have a fast vector search, you have to index the vector column, creating a `VECTOR` index:

```sql
CREATE TABLE embeddings (
        doc_id BIGINT UNSIGNED PRIMARY KEY,
        embedding VECTOR(1536) NOT NULL,
        VECTOR INDEX (embedding)
);
```

{% hint style="warning" %}
Note that there can be only one vector index in the table, and the indexed vector column must be `NOT NULL`.
{% endhint %}

There are two options that can be used to configure the vector index:

* `M` — Larger values mean slower `SELECT` and `INSERT` statements, larger index size and higher memory consumption, but more accurate results. The valid range is from `3` to `200`.
* `DISTANCE` — Distance function to build the vector index for. Searches using a different distance function will not be able to use a vector index. Valid values are `cosine` and `euclidean` (the default).

```sql
CREATE TABLE embeddings (
        doc_id BIGINT UNSIGNED PRIMARY KEY,
        embedding VECTOR(1536) NOT NULL,
        VECTOR INDEX (embedding) M=8 DISTANCE=cosine
);
```

<sub>*This page is licensed: CC BY-SA / Gnu FDL*</sub>

{% @marketo/form formId="4316" %}
