Skip to content

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 ​

text
QBit(T, N)
QBit(T, N, stride)

Parameters ​

  • T — Int8, BFloat16, Float32 or Float64.
  • N — A positive number of coordinates. Every input must contain exactly N non-NULL coordinates.
  • stride — A positive group size dividing N. The default is N. 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:

sql
SELECT l2_distance_transposed(
    CAST('[1,2,3]' AS QBit(Float32, 3)),
    array(1, 2, 4),
    32
)
FORMAT csv;
text
1.0

An identical reference ​

sql
SELECT l2_distance_transposed(
    CAST('[1,2,3]' AS QBit(Float32, 3)),
    array(1, 2, 3),
    32
)
FORMAT csv;
text
0.0

See vector distance functions for the complete function signatures and aliases.