OceanBase AI Database provides vector data types to support AI-based vector search applications. Using vector data types, you can store and query a floating-point array, such as [0.1, 0.3, -0.9, ...]. Before using vector data, note the following:
Both dense and sparse vector data are supported, with all data elements being single-precision floating-point numbers.
Element values in vector data cannot be NaN or Inf; otherwise, a runtime error is thrown.
The vector dimension must be specified when creating a vector column, for example,
VECTOR(3).You can create dense and sparse vector indexes. For details, see Overview of dense indexes.
Vector data in OceanBase AI Database is stored as arrays.
Both dense and sparse vectors support Hybrid search.
Syntax
A dense vector can contain up to 16,000 floating-point numbers. The syntax is as follows:
-- Dense vector
'[<float>, <float>, ...]'
Sparse vectors are based on the MAP data type and contain unordered key-value pairs. The syntax is as follows:
-- Sparse vector
'{<uint:float>, <uint:float>...}'
Here are examples of creating vector columns and indexes:
-- Create a dense vector column and index.
CREATE TABLE t1(
c1 INT,
c2 VECTOR(3),
PRIMARY KEY(c1),
VECTOR INDEX idx1(c2) WITH (distance=L2, type=hnsw)
);
-- Create a sparse vector column.
CREATE TABLE t2 (
c1 INT,
c2 SPARSEVECTOR
);