class

RinhaDeBackend::IvfBuilder

Inherits Reference < Object

Builds an IVF (Inverted File) index over the reference dataset. Run once at Docker build time; the resulting reordering, centroids and block-major layout are serialized into references.bin and mmapped by the runtime.

Algorithm: full-batch k-means with k-means++ init, fixed seed, ITERATIONS full passes. Centroids are kept in Float64 during iteration for precision and quantized back to Int16 (same scale as the vectors) at the end so query-time distances stay in the integer fast path.

Output layout (RNH7): each cell's vectors are written in AOSOA-8 dim-interleaved blocks of 8 vectors. A block has LOGICAL_DIMS × SLOTS_PER_BLOCK = 14 × 8 = 112 Int16 lanes (224 B). Within a block, lanes are [d0_v0..d0_v7, d1_v0..d1_v7, ..., d13_v0..d13_v7] so the runtime scan can load 8 i16 of one dim with a single VPMOVSXWD ymm and produce 8 partial squared distances per dim instead of 1 per row.

Constants

DEFAULT_ITERATIONS = 12
DEFAULT_K = 2048
DEFAULT_SEED = 42_u64
PAD_SENTINEL = Int16::MAX

Sentinel lane value used by pad slots inserted to fill out an odd-sized cell's last block (or to pad a whole alignment block when a cell ends on an odd block index). Any query lane lives in [-10_000, 10_000]; (query - Int16::MAX)² per lane × 14 logical dims dominates any real worst-case L2², so a pad slot can never enter the top-5 ranking and the kernel is free to scan it.

Class methods

build(vectors : Slice(Int16), labels : Slice(UInt8), count : Int32, dims : Int32, k : Int32 = DEFAULT_K, iterations : Int32 = DEFAULT_ITERATIONS, seed : UInt64 = DEFAULT_SEED) : Result
Source

Nested types