AI
Keep vectors next to the data they describe. Add semantic search to MariaDB in plain SQL, with no separate vector store to keep in sync.
The shop sells the three products from the landing page: a desk lamp, a standing desk, and a notebook. A customer opens the shop and types "something to light my desk" into the search box. The search runs the query that every shop starts with, a LIKE match on the product name:
SELECT name FROM shop.products WHERE name LIKE '%light%';It returns an empty set. The shop sells exactly what the customer wants, but the product is called "Desk lamp", and the word "light" appears nowhere in it. Keyword matching compares letters, so it can't see that a lamp is a light.
Semantic search compares meanings instead. An embedding model, which is an AI model that turns text into a list of numbers called a vector, places "something to light my desk" and "Desk lamp" close together because they mean similar things. MariaDB doesn't include an embedding model. Your application calls one, from a provider or running locally, and MariaDB Server stores the vectors in the same database as the products table and finds the nearest ones in SQL.
Vector search is built into MariaDB Community Server, introduced in 11.7 and generally available from the 11.8 long-term release, and into MariaDB Enterprise Server from 11.4.5-3, so there's no plugin or extension to install.
Add Semantic Search
Create a Vector Table
Create a table that holds one VECTOR value per product, with a VECTOR INDEX built for cosine distance, which measures how closely two vectors point in the same direction.
The indexed column must be NOT NULL, and a table can have only one vector index. CREATE TABLE with Vectors covers the M and DISTANCE options.
Insert the Vectors
The VEC_FromText function turns a JSON array of numbers into a vector value. Every row needs the same number of dimensions as the column, which is four here so the numbers stay readable. A real embedding model produces hundreds or thousands, for example VECTOR(768), and your application code writes them. The ids 1 to 3 are the desk lamp, the standing desk, and the notebook from step 2 on the landing page.
The VEC_FromText reference shows the binary format it produces, which is four bytes per dimension.
Find the Nearest Products
The vector in this query stands in for the customer's phrase after the same model embeds it. Sort by the VEC_DISTANCE_COSINE function and stop at a LIMIT, because that ORDER BY ... LIMIT shape is what lets the optimizer walk the vector index. The join to the products table brings back names in the same query.
A smaller distance means a closer match. Using the vector index efficiently lists the query patterns that fall back to a full table scan.
The customer who typed "something to light my desk" now sees the desk lamp first, and the notebook doesn't show up at all.
Build With a Coding Agent
The steps above use made-up vectors. Wiring in a real embedding model, backfilling every product, and keeping the vectors current when a description changes is application code. MariaDB doesn't include a coding agent, but the one you already use can write most of that code with you if it knows MariaDB.
The MariaDB AI plugins give Claude Code, Codex, Pi, Hermes Agent, and OpenCode a set of MariaDB skills, including one for vectors, plus a local sandbox server where the agent can try its SQL before you run it. Add the docs MCP server from the landing page as well, so the agent reads the current VECTOR syntax instead of guessing from older training data. Ask it to add an embedding column for product descriptions, and it can check its own work against the reference. AI Tools covers both kinds of agent work: coding agents that build with you, and production agents that reach live data over MCP.
Keep Going
This page is: Copyright © 2026 MariaDB. All rights reserved.
Last updated
Was this helpful?

