OceanBase Database provides vector data types to support AI vector search applications. You can store and query a floating-point array, such as [0.1, 0.3, -0.9, ...], by using vector data types. The array must be enclosed in single quotation marks. Before you use vector data, you must be aware of the following information:
- OceanBase Database supports dense and sparse vectors. The elements in a vector are single-precision floating-point numbers.
- The elements in a vector cannot be NaN or Inf. Otherwise, a runtime error is thrown.
- You must specify the dimension of a vector when you create a vector column. For example,
VECTOR(3). - You can create dense indexes and memory-based sparse indexes (hereafter referred to as memory sparse indexes). For details, see Vector Indexes.
- OceanBase Database stores vector data 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>, ...]'
A sparse vector is based on the MAP data type and contains 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 sparse vector columns and memory sparse indexes.
CREATE TABLE t2 (
c1 INT,
c2 SPARSEVECTOR
VECTOR INDEX idx2(c2) WITH (distance=inner_product, type=sindi)
);
