VOOZH about

URL: https://mariadb.com/docs/server/reference/sql-structure/vectors/create-table-with-vectors

⇱ CREATE TABLE with Vectors | Server | MariaDB Documentation


Webinar | Modernizing High-Volume Payment Systems: Real-Time Architecture and Demo
Watch Now
For the complete documentation index, see llms.txt. This page is also available as Markdown.

WEBINAR

The Next Generation of MariaDB: Powered by Vector Search

Vectors are available from MariaDB 11.7.

MariaDB has a dedicated VECTOR(N) data type with a built-in data validation. N is the number of dimensions that all vector values in the column have.

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

Consider the following table:

CREATETABLEembeddings (
 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:

CREATETABLEembeddings (
 doc_id BIGINT UNSIGNED PRIMARY KEY,
 embedding VECTOR(1536) NOT NULL,
VECTORINDEX (embedding)
);

Note that there can be only one vector index in the table, and the indexed vector column must be NOT NULL.

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

Declare DISTANCE explicitly. The default is euclidean, and a query using a different distance function than the one the index was built for cannot use the index, it falls back to a full table scan. Match the distance function to the metric your embedding model recommends.

This page is licensed: CC BY-SA / Gnu FDL

Last updated

Was this helpful?

Was this helpful?

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