MySQL/MariaDB VECTOR data type
Informix®
A vector is used in AI models to represent the characteristics of an object, that can be a text document, and image or a sound. Recent database engines provide support to store vector data.
Informix version 15 provides the "Vector Blade" extension to store and search for vector data. See Informix documentation for more details.
With Genero BDL, you can useVARCHAR, STRING or TEXT variables, to
store vector data as a JSON array of
numbers:[-3.45, -4.45, 9.234, ... ]Use Genero JSON APIs to manipulate vectors as JSON arrays.
Oracle® MySQL and MariaDB
CREATE TABLE tab1 (
pkey INTEGER NOT NULL PRIMARY KEY,
name VARCHAR(50) NOT NULL,
vect1 VECTOR(256),
...
);
INSERT INTO tab1 values ( 101, 'Mike STORN',
'[-3.45, -4.45, 9.234, ... ]'
);Read SQL Server documentation for more details about AI vector embeddings, and the VECTOR type.
Solution
VECTOR support:- The MySQL
VECTORtype is supported with thedbmmys_9_7ODI driver. - The MariaDB
VECTORtype is supported with thedbmmdb_10_2ODI drivers.
Use TEXT or BYTE FGL variables as SQL input parameters
for VECTOR columns, or as vector function parameters.
TEXT variables as SQL parameters, use the MySQL
STRING_TO_VECTOR() function (or MariaDB VEC_FromText() function),
to cast the character string data to a VECTOR value:DEFINE v1 TEXT
LOCATE v1 IN FILE "myvector.txt"
INSERT INTO tab VALUES ( 101, STRING_TO_VECTOR(v1) )BYTE variables as SQL parameters, the variable can be used directly
without casting. However, the BYTE data must be a valid binary representation of a
MySQL or MariaDB vector:DEFINE v1 BYTE
LOCATE v1 IN FILE "myvector.bin"
INSERT INTO tab VALUES ( 101, v1 )VECTOR data can be fetched into TEXT variables, as long as you
cast the VECTOR values to character strings with the MySQL
VECTOR_TO_STRING() function or MariaDB VEC_FromText()
function:DEFINE v1 TEXT
LOCATE v1 IN MEMORY
SELECT VECTOR_TO_STRING(vector_column) INTO v1 FROM tab WHERE pkey = 101DISTANCE(vector1,vector2,distance-metric)
SQL function. With MariaDB, use
VEC_DISTANCE(vector1,vector2). See respective
database engines documentation for more details.According to MySQL doc:
https://dev.mysql.com/doc/refman/9.7/en/vector-functions.html#function_distance
DISTANCE() is available only for users of MySQL HeatWave on OCI and MySQL AI; it
is not included in MySQL Commercial or Community distributions.
When extracting database schemas with the fgldbsch tool, columns with MySQL or MariaDB VECTOR type
are converted to the FGL BYTE data type.