Skip to main content

VecPool

Struct VecPool 

Source
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>

Source

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).

Source

pub fn stride(&self) -> usize

Byte stride of one slot.

Source

pub fn len(&self) -> usize

Number of stored slots.

Source

pub fn is_empty(&self) -> bool

true when no vector is stored.

Source

pub fn pool_bytes(&self) -> usize

Total bytes held.

Source

pub fn slot_fact(&self, i: usize) -> u32

The owning fact of slot i.

Source

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.

Source

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.

Source

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.

Source

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.

Trait Implementations§

Source§

impl<'a> Debug for VecPool<'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for VecPool<'a>

§

impl<'a> RefUnwindSafe for VecPool<'a>

§

impl<'a> Send for VecPool<'a>

§

impl<'a> Sync for VecPool<'a>

§

impl<'a> Unpin for VecPool<'a>

§

impl<'a> UnsafeUnpin for VecPool<'a>

§

impl<'a> UnwindSafe for VecPool<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.