pub struct VecPool<'a> { /* private fields */ }Expand description
Flat store of quantized vectors.
The slot bytes are an overlay of a borrowed base and an owned tail:
the owned path (new/push/from_parts) keeps base = &[] with every
slot in tail, byte-for-byte unchanged; the borrowed/overlay path
(from_parts_borrowed/from_parts_overlay) maps an mmap’d section as
base and appends new slots to tail. Because dead slots are
dropped by maintain and never rewritten in place, a slot is wholly in
base or wholly in tail, so a heap opened over a multi-gigabyte mmap
grows without cloning it — reads dispatch on one comparison per slot.
Implementations§
Source§impl<'a> VecPool<'a>
impl<'a> VecPool<'a>
Sourcepub fn new(dim: usize, max_bytes: usize) -> Self
pub fn new(dim: usize, max_bytes: usize) -> Self
Creates an empty pool for dim-dimensional vectors (dim == 0
leaves the layer inert — the pool stays empty).
Sourcepub fn pool_bytes(&self) -> usize
pub fn pool_bytes(&self) -> usize
Total bytes held.
Sourcepub fn push(&mut self, fact: FactId, v: &[f32]) -> Result<u32, Error>
pub fn push(&mut self, fact: FactId, v: &[f32]) -> Result<u32, Error>
Quantizes v and appends it as fact’s slot, returning the slot
index. Ids are not stored sorted — the fact record keeps the index.
§Errors
Error::DimMismatch/Error::Invalid from quantization, or
Error::CapacityExceeded at the byte ceiling.
Sourcepub fn quantize_query(
&self,
v: &[f32],
scratch: &mut VecScratch,
) -> Result<(), Error>
pub fn quantize_query( &self, v: &[f32], scratch: &mut VecScratch, ) -> Result<(), Error>
Quantizes a query vector into scratch.query (sized to stride,
fact left as 0). Reused across searches.
Sourcepub fn cosine_slots(&self, a: u32, b: u32) -> f32
pub fn cosine_slots(&self, a: u32, b: u32) -> f32
Quantized cosine of slots a and b (similar-detection uses it on
two stored facts). Returns 0.0 if either index is out of range.
Sourcepub fn search(
&self,
query: &[f32],
k: usize,
admit: &mut dyn FnMut(FactId) -> bool,
scratch: &mut VecScratch,
out: &mut Vec<(FactId, f32)>,
) -> Result<(), Error>
pub fn search( &self, query: &[f32], k: usize, admit: &mut dyn FnMut(FactId) -> bool, scratch: &mut VecScratch, out: &mut Vec<(FactId, f32)>, ) -> Result<(), Error>
Flat two-phase search: Hamming prefilter on signatures, then exact
quantized-cosine rescore of the best max(4·k, 64) candidates.
admit filters by the shared recall rule; writes the top k
(fact, cosine) into out, descending.