Skip to main content

Index

Struct Index 

Source
pub struct Index {
    pub params: IndexParams,
    pub codec: ResidualCodec,
    pub doc_ids: Vec<u64>,
    pub doc_centroid_ids: Vec<u32>,
    pub doc_residual_bytes: Vec<u8>,
    pub doc_offsets: Vec<usize>,
    pub ivf: InvertedFile,
}
Expand description

A fully-built PLAID index over a corpus of multi-vector embeddings.

Stored in a flat, StridedTensor-style layout — every document’s encoded tokens live in one of two big contiguous buffers, doc_centroid_ids (one u32 per token) and doc_residual_bytes (packed_bytes_per_token u8s per token). Per-document slicing happens through the precomputed doc_offsets cumulative lengths.

This layout matches fast-plaid’s StridedTensor and buys three things over the older Vec<Vec<EncodedVector>> we used to keep:

  1. Search doesn’t have to walk per-document Vecs on every query to gather codes and residuals — it slices into the flat buffer.
  2. Peak RAM drops: 6.8M tokens at nbits=2 was ~500 MiB of heap for the old nested-Vec headers; the flat layout is ~240 MiB.
  3. GPU decode can Tensor::from_slice the whole slice for a batch of candidates in one kernel launch instead of one-per-token.

Callers that want the per-token view use Index::doc_centroid_ids / Index::doc_residual_bytes — slices into the flat buffers with no allocation.

Fields§

§params: IndexParams§codec: ResidualCodec§doc_ids: Vec<u64>§doc_centroid_ids: Vec<u32>

Flat [total_tokens] vector of per-token centroid indices.

§doc_residual_bytes: Vec<u8>

Flat [total_tokens * packed_bytes_per_token] residual bytes, row-major — each packed_bytes_per_token-long slice is one token’s packed residual.

§doc_offsets: Vec<usize>

Cumulative per-document token counts; length num_docs + 1, doc_offsets[i + 1] - doc_offsets[i] = n_tokens for doc i.

§ivf: InvertedFile

Centroid → tokens inverted file used for candidate generation.

Implementations§

Source§

impl Index

Source

pub fn from_encoded_docs( params: IndexParams, codec: ResidualCodec, doc_ids: Vec<u64>, doc_tokens: Vec<Vec<EncodedVector>>, ivf: InvertedFile, ) -> Self

Construct an Index from per-document EncodedVectors.

Convenience for tests, crate::update::apply_update, and crate::persistence’s legacy-format loader: they still think in terms of Vec<Vec<EncodedVector>>, and this flattens that into the canonical Index layout in one pass.

ivf should already reflect the doc_tokens contents — this helper does not recompute the inverted file, only the flat per-token buffers.

Source

pub fn num_documents(&self) -> usize

Number of documents currently stored in the index.

Source

pub fn num_tokens(&self) -> usize

Total number of encoded tokens across all documents.

Source

pub fn position_of(&self, doc_id: u64) -> Option<usize>

Find the position of a document inside Index::doc_ids.

Source

pub fn doc_token_count(&self, idx: usize) -> usize

Number of encoded tokens for the idx-th document.

Source

pub fn doc_centroid_ids(&self, idx: usize) -> &[u32]

Slice of per-token centroid indices for the idx-th document.

Source

pub fn doc_residual_bytes(&self, idx: usize) -> &[u8] ⓘ

Slice of packed residual bytes for the idx-th document, row-major [n_tokens, packed_bytes_per_token].

Source

pub fn doc_tokens_vec(&self, idx: usize) -> Vec<EncodedVector>

Reconstruct the idx-th document’s tokens as an owned Vec<EncodedVector>.

Allocation-heavy — prefer Index::doc_centroid_ids / Index::doc_residual_bytes on the hot path. Provided as a compatibility shim for crate::update::apply_update and legacy callers that still work in EncodedVector terms.

Trait Implementations§

Source§

impl Clone for Index

Source§

fn clone(&self) -> Index

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Index

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for Index

§

impl RefUnwindSafe for Index

§

impl Send for Index

§

impl Sync for Index

§

impl Unpin for Index

§

impl UnsafeUnpin for Index

§

impl UnwindSafe for Index

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,

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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. 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