Expand description
Vector quantization for IVF indexes
TurboQuant (tq) is the float codec: training-free, used by both the
per-segment flat scan and the trained-router IVF-TQ leaves.
Structs§
- TqCodec
- Complete TQ codec for one field dimension. Cheap to build (sub-millisecond)
and immutable; share via
Arcper open segment. - TqEncode
Scratch - Reusable per-thread encode buffers (hot-path allocation hygiene).
- TqFlat
Builder - Streaming builder for one segment’s TQ payload: doc/ordinal columns plus a
block-packed codes column ready for
ann_diskserialization. - TqQuery
Plan - Per-query LUTs:
padded_dim × 16i8 tables (globally-scaled quantizations) for the block kernels. The intermediate f32 tables are dropped after quantization — they are not read on the search path.
Constants§
- TQ_
BLOCK_ LANES - Vectors per scoring block; one lane per vector.
- TQ_
CODEC_ VERSION - Bumping this refuses to mix payloads across incompatible codec revisions. v2: padding-free 3-round rotation (sub-FWHT + signs + permutation per round) replaced the single-round power-of-two-padded FWHT — 768-dim codes shrank 33% and the codebook density now uses the true dimension.
Functions§
- tq_
block_ bytes - Bytes of one scoring block: 16 f32 gammas + 16 packed nibble rows.
- tq_
codes_ column_ len - Total codes-column bytes for
countvectors (final block zero-padded). - tq_
codes_ column_ len_ checked - Overflow-checked
tq_codes_column_lenfor untrusted header values. - tq_
expected_ fingerprint - Fingerprint every payload built for
dimmust carry (no codebook build). - tq_
ivf_ block_ bytes - Bytes of one IVF-TQ scoring block: 16 f32 residual scales + 16 f32 gammas
- tq_
ivf_ codes_ column_ len_ checked - Overflow-checked IVF-TQ codes-column length for untrusted header values.
- tq_
pack_ block - Pack up to 16 nibble rows (+ gammas) into one block. Missing lanes are
zero-filled.
rowsarepadded_dim-length 0..=15 values. - tq_
pack_ ivf_ block - Pack an IVF-TQ block: per-lane residual scales, gammas, then nibbles.
- tq_
padded_ dim - Code-layout dimension: the input dimension rounded up to an even count
(two 4-bit coordinates per byte), floored at [
TQ_MIN_PADDED_DIM]. Since codec v2 the rotation is padding-free, so this tracks the true dimension instead of the next power of two. Cheap; usable for header validation without building a codec. - tq_
score_ block - Score one block (16 lanes) into
scores.blockis[16 × f32 gamma][padded_dim × 8 packed nibbles]; lanes past the run’s vector count hold zero padding and must be ignored by the caller. - tq_
score_ ivf_ block - Score one IVF-TQ block:
score[lane] = cluster_dot + scale · (base + gamma · qjl), wherecluster_dot = ⟨normalized query, centroid⟩is the probed cluster’s shared contribution andscale = ‖residual‖. - tq_
shared_ codec - Process-wide codec cache. A codec is a pure function of the dimension and costs a Lloyd solve to build; segment opens and merges share one instance per dimension instead of re-deriving it.