Vector Overview
Official MariaDB Vector reference: VECTOR(n) data type, VECTOR INDEX (M, DISTANCE=euclidean|cosine), VEC_FromText() inserts, VEC_DISTANCE() queries.
Vectors are available from MariaDB Community Server 11.7 and from MariaDB Enterprise Server 11.4.5-3.
MariaDB Vector is a feature that allows MariaDB Server to perform as a relational vector database. Vectors generated by an AI model can be stored and searched in MariaDB.
MariaDB Vector was introduced in MariaDB Community Server 11.7, a rolling release, and is generally available from MariaDB Community Server 11.8 onwards, the first long-term support (LTS) release to include it.
In MariaDB Enterprise Server, vector search was backported to the 11.4 release series and is available from MariaDB Enterprise Server 11.4.5-3 onwards. It is also included in MariaDB Enterprise Server 11.8, which is generally available from 11.8.3-1 onwards.
The initial implementation uses the modified HNSW algorithm for searching in the vector index (to solve the so-called Approximate Nearest Neighbor problem), and defaults to Euclidean distance. Concurrent reads/writes and all transaction isolation levels are supported.
MariaDB uses int16 for indexes, which gives 15 bits to store the value, rather than 10 bits for float16.
Creating
Vectors can be defined using VECTOR INDEX for the index definition, and using the VECTOR data type in the CREATE TABLE statement.
CREATE TABLE v (
id INT PRIMARY KEY,
v VECTOR(5) NOT NULL,
VECTOR INDEX (v)
);The distance function used to build the vector index can be euclidean (the default) or cosine. An additional option, M, can be used to configure the vector index. 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.
CREATE TABLE embeddings (
doc_id BIGINT UNSIGNED PRIMARY KEY,
embedding VECTOR(1536) NOT NULL,
VECTOR INDEX (embedding) M=8 DISTANCE=cosine
);Inserting
Vector columns store 32-bit IEEE 754 floating point numbers.
Alternatively, you can use VEC_FromText() function:
Querying
For vector indexes built with the euclidean function, VEC_DISTANCE_EUCLIDEAN can be used. It calculates a Euclidean (L2) distance between two points:
Most commonly, this kind of query is done with a limit, for example to return vectors that are closest to a given vector, such as from a user search query, image or a song fragment:
For vector indexes built with the cosine function, VEC_DISTANCE_COSINE can be used. It calculates a Cosine distance between two vectors:
The VEC_DISTANCE function is a generic function that behaves either as VEC_DISTANCE_EUCLIDEAN or VEC_DISTANCE_COSINE, depending on the underlying index type:
There is no function for dot product (also called inner product) distance available in many other vector databases. Dot product is not a proper distance measure (for example, vector's closest match is not necessarily itself) and is only used for performance reasons, because it is often faster than cosine or euclidean and produces the same results if vectors are normalized. In MariaDB optimized implementation euclidean and cosine measures are the fastest, and dot product, if implemented, would not provide any performance benefits. Use euclidean or cosine (they are equally fast) for normalized vectors.
Using the Vector Index Efficiently
The optimizer uses the vector index only when the ORDER BY is the literal VEC_DISTANCE_*(column, vector) call (or its alias) sorted ascending, together with a LIMIT. Two common patterns defeat the index and fall back to a full table scan.
Wrapping the distance in an expression. To sort by a similarity score (for example 1 - cosine distance), compute the score in an outer query and keep the inner ORDER BY on the bare distance:
Filtering by a distance threshold. A bare WHERE VEC_DISTANCE(...) < threshold with no ORDER BY ... LIMIT is a range predicate that the index cannot drive, so it falls back to a full table scan. To use the index, retrieve an indexed top-K and apply the threshold to it, for example in a subquery:
The LIMIT is a hard cap on how many rows the index returns before the threshold is applied, so choose it generously if many rows may match, otherwise qualifying rows beyond the limit are silently dropped. (Adding the WHERE directly to an ORDER BY ... LIMIT query also uses the index, but with the same hard cap.)
System Variables
There are a number of system variables used for vectors. See Vector System Variables.
Vector Framework Integrations
MariaDB Vector is integrated in several frameworks, see Vector Framework Integrations.
What is a Vector?
Video summary
A vector (an embedding) is an ordered list of numbers.
AI models map content (like text) into vectors.
Similar meanings end up close together in vector space.
RAG and semantic search retrieve relevant items by finding the nearest vectors.
See Also
MariaDB Vector project page — feature summary, benchmark results, talks, tutorials, and FAQ
Big Vector Search Benchmark: 10 databases comparison (blog post • 2026) — MariaDB 11.8 and 12.3 measured against pgvector, pgvectorscale, Qdrant, Milvus, Weaviate, OpenSearch and others on one million OpenAI embeddings
Vector indexes, large server, dbpedia-openai dataset: MariaDB, Qdrant and pgvector (blog post • 2025) — independent third-party benchmark by Mark Callaghan (Small Datum)
Everything you need to know to start building apps with AI and RAG (video • 40 minutes • 2026)
What exactly is a vector in AI and RAG? (video • 1 minute • 2026)
Get to know MariaDB’s Rocket-Fast Native Vector Search - Sergei Golubchyk (video • 37 minutes • 2025)
MariaDB Vector, a new Open Source vector database that you are already familiar with - Sergei Golubchik (video • 27 minutes • 2024)
AI first applications with MariaDB Vector - Vicentiu Ciorbaru (video • 22 minutes • 2025)
MariaDB Vector: A storage engine for LLMs - Kaj Arnö and Jonah Harris (video • 12 minutes • 2025)
Try RAG with MariaDB Vector on your own MariaDB data! (blog post • 5 minutes • 2024)
The post, written by Robert Silén, explains how to build a Retrieval-Augmented Generation (RAG) system using MariaDB's native vector storage. It covers:
Preparation: Setting up a MariaDB 11.7+ environment and creating a table with the
VECTORdata type.Indexing: Using OpenAI's embedding model to vectorize documentation and store it in MariaDB.
Search & Generation: Performing a nearest-neighbor search (
VEC_DISTANCE_EUCLIDEAN) to find relevant context for a user's question and feeding that context into an LLM for an accurate response.
MariaDB Knowledge Base RAG demo (runnable demo • Python)
MariaDB RAG demo with OpenAI (runnable demo • Java)
MariaDB skills for AI agents — includes
mariadb-vector/SKILL.md, with usage and tuning guidance for Claude Code and other AI agents
This page is licensed: CC BY-SA / Gnu FDL
Last updated
Was this helpful?

