class

RinhaDeBackend::Knn

Inherits Reference < Object

Brute-force exact KNN over the quantized reference dataset. K = 5 makes an insertion-sorted StaticArray cheaper than a heap, and the inner distance loop early-exits the moment the partial L2² already exceeds the current 5th-best distance.

Two layout paths share this class:

  • Block path (block_count > 0): walks the AOSOA-8 dim-interleaved blocks the IVF builder writes. Used by the runtime mmap loader (References.mmap) and any spec/tool that compares brute-force to IVF.

  • Row path (block_count == 0): walks the legacy row-major vectors slice produced by References.load_from_io. Only used by spec fixtures that load example-references.json directly.

Constants

BLOCK_LANES = References::BLOCK_LANES
K = 5
LOGICAL_DIMS = References::LOGICAL_DIMS
SLOTS_PER_BLOCK = References::SLOTS_PER_BLOCK

Constructors

new(refs : References)
Source

Instance methods

fraud_count_top_k(query : StaticArray(Int16, 16)) : Int32

Returns how many of the K nearest neighbors carry the "fraud" label.

Source