LiteDAC

Vectors

Vectors

LiteDAC supports working with vector data through two SQLite extensions that implement vector operations:

LiteDAC supports the following vector types:

The TLiteVectorField field type is used to represent table columns of the vector type in a dataset. TLiteVectorField lets you work with vector data as a string in the TinyJSON format or as a TLiteVector object.

Note: SQLite 3 does not provide built-in data types for vector storage—vector columns are stored as BLOB values. To use TLiteVectorField in a dataset, you must explicitly define Data Type Mapping rules for the corresponding fields. For more information, see Data Type Mapping.


LiteQuery1.DataTypeMap.AddFieldNameRule('field_name', TFieldType(ftLiteSingleVector));
LiteQuery1.DataTypeMap.AddFieldNameRule('field_name', TFieldType(ftLiteHalfVector));
LiteQuery1.DataTypeMap.AddFieldNameRule('field_name', TFieldType(ftLiteShortIntVector));
LiteQuery1.DataTypeMap.AddFieldNameRule('field_name', TFieldType(ftLiteByteVector));
LiteQuery1.DataTypeMap.AddFieldNameRule('field_name', TFieldType(ftLiteBitVector));
  

Examples

sqlite-vec

The following example shows how to create a virtual table, insert vector data, and query it using the sqlite-vec extension.

// load the sqlite-vec extension
LiteConnection1.ExecSQL('SELECT load_extension(''vec0.dll'')');

// create a table and insert sample vector data
LiteConnection1.ExecSQL('CREATE VIRTUAL TABLE vector_table USING vec0(vector_field float[2], chunk_size=8)');
LiteConnection1.ExecSQL('INSERT INTO vector_table(vector_field) VALUES (''[1.23,4.56]'')');

// set Data Type Mapping and query vector data
LiteQuery1.DataTypeMap.AddFieldNameRule('vector_field', TFieldType(ftLiteSingleVector));
LiteQuery1.SQL.Text := 'SELECT * FROM vector_table WHERE vector_field match ''[0]''';
LiteQuery1.Open;

sqlite-vector

The following example shows how to create a table, insert vector data, initialize a vector field in the database, and query vector fields using the sqlite-vector extension.

// load the sqlite-vector extension
LiteConnection1.ExecSQL('SELECT load_extension(''vector.dll'')');

// create a table and insert sample vector data
LiteConnection1.ExecSQL('CREATE TABLE vector_table(vector_field BLOB)');
LiteConnection1.ExecSQL('INSERT INTO vector_table(vector_field) VALUES (vector_as_f32(''[1.23,4.56]''))');

// initialize a vector field in the database
conn.ExecSQL('SELECT vector_init(''vector_table'', ''vector_field'', ''type=FLOAT32,dimension=2'');');

// set Data Type Mapping and query vector data
LiteQuery1.DataTypeMap.AddFieldNameRule('vector_field', TFieldType(ftLiteSingleVector));
LiteQuery1.SQL.Text := 'select * from vector_table';
LiteQuery1.Open;
© 1997-2026 Devart. All Rights Reserved. Request Support DAC Forum Provide Feedback