Skip to main content
Version: V1.4.0

Store vector data

This topic describes how to store unstructured data, semi-structured data, and structured data in a single table in the database. This approach not only leverages the database's core capabilities but also supports hybrid search effectively.

Storage principles​

The database can store data of different modalities, such as text, images, and videos, by converting them into vectors. This enables hybrid search by calculating the distances between vectors. Hybrid search can be simple, based on similarity search of a single vector, or complex, involving a combination of vector and scalar searches.

Since vector search is inherently approximate, it is essential to use various methods to enhance accuracy in practical applications. Accurate search results can provide significant value to your business.

Configure vector index memory​

seekdb uses vector_memory_limit to limit the memory available to the vector module. The default value is 0M, which means 50% of memory_budget. You can also set an explicit value based on your capacity plan:

ALTER SYSTEM SET vector_memory_limit = '2G';

vector_memory_limit is a module limit and does not increase the instance memory budget. For calculation details, see Configure memory for seekdb.

Create a vector column​

The following example shows how to create a table that stores vector data, spatial data, and relational data. The vector column has the VECTOR data type and must specify the dimension when created, with a maximum of 16000 dimensions. The spatial column has the GEOMETRY data type:

CREATE TABLE t (
-- Store relational data (structured data)
id INT PRIMARY KEY,
-- Store spatial data (semi-structured data)
g GEOMETRY,
-- Store vector data (unstructured data)
vec VECTOR(3)
);

Use the INSERT statement to insert vector data​

Once a table with a VECTOR column is created, you can directly use the INSERT statement to insert vectors into the table. When inserting data, the vector must match the dimension specified when the table was created, otherwise an error will occur. This design ensures data consistency and query efficiency. Vectors are represented as standard floating-point number arrays, with each dimension value being a valid floating-point number. Here is a simple example:

INSERT INTO t (id, g, vec) VALUES (
-- Insert structured data
1,
-- Insert semi-structured data
ST_GeomFromText('POINT(1 1)'),
-- Insert unstructured data
'[0.1, 0.2, 0.3]'
);

References​