QBit
QBit stores a numeric vector with a fixed element type and dimension. Its distance functions let a query choose how much precision to use when comparing the vector with a reference array.
Creating QBit
QBit(T, N)
QBit(T, N, stride)Parameters
T—Int8,BFloat16,Float32orFloat64.N— A positive number of coordinates. Every input must contain exactlyNnon-NULLcoordinates.stride— A positive group size dividingN. The default isN. A smaller stride must be a multiple of eight.
Coordinates are converted to T. Use JSON array text or an array value as input.
Vector search functions
l2_distance_transposed, cosine_distance_transposed and dot_product_transposed accept a QBit vector, an Array reference and a precision from 1 through the element bit width.
A full-precision probe recovers the stored coordinate values. A lower precision can change the result. The optional used_dims argument must be a positive multiple of stride and cannot exceed N; omitting it requires a reference for the full dimension.
Results are Float64. SQL NULL propagates, nonfinite coordinates raise an error, and cosine distance with a zero-norm vector returns NULL.
Examples
Euclidean distance
The vectors differ by one unit in their final coordinate:
SELECT l2_distance_transposed(
CAST('[1,2,3]' AS QBit(Float32, 3)),
array(1, 2, 4),
32
)
FORMAT csv;1.0An identical reference
SELECT l2_distance_transposed(
CAST('[1,2,3]' AS QBit(Float32, 3)),
array(1, 2, 3),
32
)
FORMAT csv;0.0See vector distance functions for the complete function signatures and aliases.