Skip to main content

vector_offset

Function vector_offset 

Source
pub fn vector_offset(layout: &VamanaStorageLayout, idx: u64) -> u64
Expand description

Return the byte offset of the full-precision vector for node idx.

This is the offset to pass to an io_uring IORING_OP_READ or pread call to fetch dim * 4 bytes of FP32 data for the given node.

ยงExample

use nodedb_vector::vamana::storage::{VamanaStorageLayout, vector_offset};

let layout = VamanaStorageLayout::new(4, 64, 1.2, 100, 0);
let off = vector_offset(&layout, 5);
// adjacency block: 64 * 4 * 100 = 25600 bytes
// header:          64 bytes
// vectors start:   64 + 25600 = 25664
// vector 5:        25664 + 5 * 4 * 4 = 25664 + 80 = 25744
assert_eq!(off, 25744);