Quantization Types since v1.1.0
Quantization can be applied not only to indexes but also directly to vectors. To this end, VectorChord provides data types for quantized vectors.
rabitq8 is the data type of a quantized vector. For the same dimension, its cost is about vector) and halfvec). This type is named after its quantization algorithm.[1]
CREATE TABLE items (id bigserial PRIMARY KEY, embedding rabitq8(3));
INSERT INTO items (embedding) VALUES (quantize_to_rabitq8('[0,0,0]'::vector));
INSERT INTO items (embedding) VALUES (quantize_to_rabitq8('[1,1,1]'::vector));
INSERT INTO items (embedding) VALUES (quantize_to_rabitq8('[2,2,2]'::vector));
--- ...
SELECT id FROM items ORDER BY embedding <-> quantize_to_rabitq8('[0.9,0.9,1.1]'::vector) LIMIT 100;Like them, an index can be created on columns of type rabitq8, too.
CREATE INDEX ON items USING vchordrq (embedding rabitq8_l2_ops);By using rabitq8, both the table size and index size become vector. The cost is that both performance and precision are compromised by quantization noticeably. Therefore, it is applicable in scenarios that retrieve a large number of results.
In addition, there is also the rabitq4 type. rabitq8 quantized vectors use rabitq4 quantized vectors use only
Reference
Operator Classes
Refer to
Types
rabitq8 since v1.1.0
- Description: The data type of a quantized vector that uses
uint8for internal storage. It's based on extended RaBitQ.[1:1]
rabitq4 since v1.1.0
- Description: The data type of a quantized vector that uses
uint4for internal storage. It's based on extended RaBitQ.[1:2]
Functions
quantize_to_rabitq8(vector) since v1.1.0
- Description: Quantizes a vector to
rabitq8. - Result:
rabitq8, the quantized vector - Arguments:
vector, the vector to be quantized
- Example:
SELECT quantize_to_rabitq8('[1,1,1]'::vector)
quantize_to_rabitq8(halfvec) since v1.1.0
- Description: Quantizes a vector to
rabitq8. - Result:
rabitq8, the quantized vector - Arguments:
halfvec, the vector to be quantized
- Example:
SELECT quantize_to_rabitq8('[1,1,1]'::halfvec)
quantize_to_rabitq4(vector) since v1.1.0
- Description: Quantizes a vector to
rabitq4. - Result:
rabitq4, the quantized vector - Arguments:
vector, the vector to be quantized
- Example:
SELECT quantize_to_rabitq4('[1,1,1]'::vector)
quantize_to_rabitq4(halfvec) since v1.1.0
- Description: Quantizes a vector to
rabitq4. - Result:
rabitq4, the quantized vector - Arguments:
halfvec, the vector to be quantized
- Example:
SELECT quantize_to_rabitq4('[1,1,1]'::halfvec)
Operators
<->(rabitq8, rabitq8) since v1.1.0
- Description: Calculates L2 distance of two quantized vectors.
- Result:
real, L2 distance of two quantized vectors - Arguments:
rabitq8rabitq8
<#>(rabitq8, rabitq8) since v1.1.0
- Description: Calculates negative dot product distance of two quantized vectors.
- Result:
real, negative dot product distance of two quantized vectors - Arguments:
rabitq8rabitq8
<=>(rabitq8, rabitq8) since v1.1.0
- Description: Calculates cosine distance of two quantized vectors.
- Result:
real, cosine distance of two quantized vectors - Arguments:
rabitq8rabitq8
<->(rabitq4, rabitq4) since v1.1.0
- Description: Calculates L2 distance of two quantized vectors.
- Result:
real, L2 distance of two quantized vectors - Arguments:
rabitq4rabitq4
<#>(rabitq4, rabitq4) since v1.1.0
- Description: Calculates negative dot product distance of two quantized vectors.
- Result:
real, negative dot product distance of two quantized vectors - Arguments:
rabitq4rabitq4
<=>(rabitq4, rabitq4) since v1.1.0
- Description: Calculates cosine distance of two quantized vectors.
- Result:
real, cosine distance of two quantized vectors - Arguments:
rabitq4rabitq4
Jianyang Gao, Yutong Gou, Yuexuan Xu, Yongyi Yang, Cheng Long, Raymond Chi-Wing Wong, "Practical and Asymptotically Optimal Quantization of High-Dimensional Vectors in Euclidean Space for Approximate Nearest Neighbor Search", SIGMOD 2025, available at https://arxiv.org/abs/2409.09913. ↩︎ ↩︎ ↩︎