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: MetadataIndex metadata
codec: ResidualCodecResidual codec for quantization/decompression
ivf: IvfStridedTensorIVF 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: usizeNumber of bits for quantization
Implementations§
Source§impl LoadedIndex
impl LoadedIndex
Sourcepub fn from_index(index: Index) -> Self
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.
Sourcepub fn get_candidates(&self, centroid_indices: &[usize]) -> Vec<i64>
pub fn get_candidates(&self, centroid_indices: &[usize]) -> Vec<i64>
Get candidate documents from IVF for given centroid indices.
Sourcepub fn lookup_documents(
&self,
doc_ids: &[usize],
) -> (Array1<usize>, Array2<u8>, Array1<i64>)
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.
Sourcepub fn decompress_documents(
&self,
doc_ids: &[usize],
) -> Result<(Array2<f32>, Array1<i64>)>
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.
Sourcepub fn num_documents(&self) -> usize
pub fn num_documents(&self) -> usize
Get the number of documents in the index.
Sourcepub fn embedding_dim(&self) -> usize
pub fn embedding_dim(&self) -> usize
Get the embedding dimension.
Sourcepub fn reconstruct(&self, doc_ids: &[i64]) -> Result<Vec<Array2<f32>>>
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());
}Auto Trait Implementations§
impl Freeze for LoadedIndex
impl RefUnwindSafe for LoadedIndex
impl Send for LoadedIndex
impl Sync for LoadedIndex
impl Unpin for LoadedIndex
impl UnwindSafe for LoadedIndex
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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