Skip to main content

FibSidecarIndex

Struct FibSidecarIndex 

Source
pub struct FibSidecarIndex<Id>
where Id: Clone + Eq + Debug,
{ /* private fields */ }
Expand description

Generic ID-typed sidecar search index.

Wraps a FibScorer and stores a list of (Id, FibCodeV1) entries. Search uses the Gram-table estimator for each stored code and returns candidates sorted by descending approximate inner product.

The index is cheap to clone (via Clone on the scorer and entries) but in typical usage a single instance is shared by reference across queries.

§Generics

Id must be Clone + Eq + Debug. Common choices are u64, String, or a newtype key. The index does not enforce uniqueness — adding the same ID twice will produce two entries.

Implementations§

Source§

impl<Id> FibSidecarIndex<Id>
where Id: Clone + Eq + Debug,

Source

pub fn new(scorer: FibScorer) -> Self

Construct a new sidecar index from a FibScorer.

The scorer’s profile is cloned for validation of incoming codes. The index starts empty.

Source

pub fn scorer(&self) -> &FibScorer

Return a reference to the underlying scorer.

Source

pub fn profile(&self) -> &FibQuantProfileV1

Return a reference to the profile used for validation.

Source

pub fn add(&mut self, id: Id, code: FibCodeV1)

Add a single encoded vector with a caller-owned ID.

The code’s ambient_dim and block_dim are checked against the scorer’s profile to catch mismatches early.

Source

pub fn add_batch(&mut self, entries: Vec<(Id, FibCodeV1)>)

Add many encoded vectors at once.

Equivalent to calling add in a loop but avoids repeated capacity growth.

Source

pub fn len(&self) -> usize

Number of encoded entries currently stored.

Source

pub fn entries(&self) -> &[(Id, FibCodeV1)]

Return a slice of all (Id, FibCodeV1) entries.

Used by persistence to serialize the index to disk. The slice borrows from the index.

Source

pub fn is_empty(&self) -> bool

Whether the index is empty.

Source

pub fn search( &self, query: &[f32], top_k: usize, oversample: usize, ) -> Result<Vec<ScoredCandidate<Id>>>

Approximate search returning sorted candidates.

Scores every stored code against the query, sorts by descending approximate inner product, and returns the top top_k * oversample candidates (or fewer if the index has fewer entries).

The returned candidates have rank assigned starting from 0. Callers must rerank these candidates with an exact inner product against the original (un-encoded) vectors before acting on results.

Source

pub fn search_with_receipt( &self, query: &[f32], top_k: usize, oversample: usize, ) -> Result<(Vec<ScoredCandidate<Id>>, SearchReceiptV1)>

Approximate search returning both candidates and a SearchReceiptV1.

See search for search semantics. The receipt documents the operational parameters and timing of the search.

Source

pub fn ivf(&self) -> Option<&IvfCoarseQuantizer>

Return a reference to the IVF coarse quantizer, if built.

Source

pub fn ivf_is_built(&self) -> bool

Whether the IVF coarse quantizer has been built.

Source

pub fn build_ivf(&mut self, num_centroids: usize) -> Result<()>

Build the IVF coarse quantizer by running k-means on decoded vectors.

Decodes all stored FibCodeV1 entries to their approximate vectors using the scorer’s quantizer, runs k-means with num_centroids centroids (default: sqrt(N)), and stores the centroids and assignments. After this call, search_ivf will use the IVF path instead of falling back to linear scan.

§Arguments
  • num_centroids — number of k-means centroids (k). Pass (self.len() as f64).sqrt() as usize or let build_ivf_default compute it.
Source

pub fn build_ivf_default(&mut self) -> Result<()>

Build IVF with default k = sqrt(N) centroids.

Source

pub fn search_ivf( &self, query: &[f32], top_k: usize, oversample: usize, nprobe: usize, ) -> Result<Vec<ScoredCandidate<Id>>>

IVF-accelerated search.

Finds the nprobe nearest centroids to the query, gathers all entries assigned to those centroids, scores them using the prepared query (Gram table), and returns the top top_k * oversample candidates sorted by descending approximate inner product.

If IVF is not built (centroids empty or ivf is None), falls back to a full linear scan via search.

Source

pub fn search_with_receipt_ivf( &self, query: &[f32], top_k: usize, oversample: usize, nprobe: usize, ) -> Result<(Vec<ScoredCandidate<Id>>, SearchReceiptIvfV1)>

IVF-accelerated search with receipt.

Like search_ivf but returns a SearchReceiptIvfV1 documenting the IVF parameters used.

Auto Trait Implementations§

§

impl<Id> Freeze for FibSidecarIndex<Id>

§

impl<Id> RefUnwindSafe for FibSidecarIndex<Id>
where Id: RefUnwindSafe,

§

impl<Id> Send for FibSidecarIndex<Id>
where Id: Send,

§

impl<Id> Sync for FibSidecarIndex<Id>
where Id: Sync,

§

impl<Id> Unpin for FibSidecarIndex<Id>
where Id: Unpin,

§

impl<Id> UnsafeUnpin for FibSidecarIndex<Id>

§

impl<Id> UnwindSafe for FibSidecarIndex<Id>
where Id: UnwindSafe,

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V