LoadedIndex

Struct LoadedIndex 

Source
pub struct LoadedIndex {
    pub metadata: Metadata,
    pub codec: ResidualCodec,
    pub ivf: IvfStridedTensor,
    pub doc_codes: StridedTensor<usize>,
    pub doc_residuals: StridedTensor<u8>,
    pub nbits: usize,
}
Expand description

A loaded index optimized for search with StridedTensor storage.

This struct contains all data required for search operations, stored in a format optimized for batch lookups. It uses StridedTensor for efficient retrieval of variable-length sequences.

Fields§

§metadata: Metadata

Index metadata

§codec: ResidualCodec

Residual codec for quantization/decompression

§ivf: IvfStridedTensor

IVF index mapping centroids to document IDs

§doc_codes: StridedTensor<usize>

Document codes (centroid assignments) stored contiguously

§doc_residuals: StridedTensor<u8>

Packed residuals stored contiguously

§nbits: usize

Number of bits for quantization

Implementations§

Source§

impl LoadedIndex

Source

pub fn from_index(index: Index) -> Self

Create a LoadedIndex from an existing Index.

This converts the Index’s per-document storage to contiguous StridedTensor storage.

Source

pub fn get_candidates(&self, centroid_indices: &[usize]) -> Vec<i64>

Get candidate documents from IVF for given centroid indices.

Source

pub fn lookup_documents( &self, doc_ids: &[usize], ) -> (Array1<usize>, Array2<u8>, Array1<i64>)

Lookup codes and residuals for a batch of document IDs.

Returns (codes, residuals, lengths) for efficient batch decompression.

Source

pub fn decompress_documents( &self, doc_ids: &[usize], ) -> Result<(Array2<f32>, Array1<i64>)>

Decompress embeddings for a batch of document IDs.

Returns the decompressed embeddings as a contiguous array along with lengths.

Source

pub fn num_documents(&self) -> usize

Get the number of documents in the index.

Source

pub fn embedding_dim(&self) -> usize

Get the embedding dimension.

Source

pub fn reconstruct(&self, doc_ids: &[i64]) -> Result<Vec<Array2<f32>>>

Reconstruct embeddings for specific documents.

This method retrieves the compressed codes and residuals for each document and decompresses them to recover the original embeddings.

§Arguments
  • doc_ids - Slice of document IDs to reconstruct (0-indexed)
§Returns

A vector of 2D arrays, one per document. Each array has shape [num_tokens, dim].

§Example
use next_plaid::LoadedIndex;

let index = LoadedIndex::load("/path/to/index")?;
let embeddings = index.reconstruct(&[0, 1, 2])?;

for (i, emb) in embeddings.iter().enumerate() {
    println!("Document {}: {} tokens x {} dim", i, emb.nrows(), emb.ncols());
}
Source

pub fn reconstruct_single(&self, doc_id: i64) -> Result<Array2<f32>>

Reconstruct a single document’s embeddings.

Convenience method for reconstructing a single document.

§Arguments
  • doc_id - Document ID to reconstruct (0-indexed)
§Returns

A 2D array with shape [num_tokens, dim].

Auto Trait Implementations§

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