Skip to main content

QuantizedDiskANN

Struct QuantizedDiskANN 

Source
pub struct QuantizedDiskANN<D>
where D: Distance<f32> + Send + Sync + Copy + Clone + 'static,
{ /* private fields */ }
Expand description

Quantized DiskANN index — wraps a DiskANN<D> with compressed in-memory codes.

During beam search, distance computations use the compressed codes in RAM instead of reading full f32 vectors from the backing store. After search, an optional re-ranking phase re-scores top candidates with exact vectors.

Implementations§

Source§

impl<D> QuantizedDiskANN<D>
where D: Distance<f32> + Send + Sync + Copy + Clone + 'static,

Source

pub fn from_pq( base: DiskANN<D>, pq: ProductQuantizer, config: QuantizedConfig, ) -> Self

Create from an existing index and a pre-trained ProductQuantizer.

Encodes all vectors from base into the in-memory codes buffer.

Source

pub fn from_f16(base: DiskANN<D>, config: QuantizedConfig) -> Self

Create from an existing index using F16 quantization.

Source

pub fn from_int8( base: DiskANN<D>, int8q: Int8Quantizer, config: QuantizedConfig, ) -> Self

Create from an existing index and a pre-trained Int8Quantizer.

Source

pub fn num_vectors(&self) -> usize

Number of vectors in the index.

Source

pub fn dim(&self) -> usize

Vector dimensionality.

Source

pub fn base(&self) -> &DiskANN<D>

Reference to the underlying base index.

Source

pub fn get_vector(&self, idx: usize) -> Vec<f32>

Get a full-precision vector from the base index.

Source

pub fn search_with_dists( &self, query: &[f32], k: usize, beam_width: usize, ) -> Vec<(u32, f32)>

Search with quantized beam search, returning (id, distance) pairs.

Distances in the returned results are:

  • If rerank_size > 0: exact distances from the base index
  • Otherwise: approximate distances from the quantizer
Source

pub fn search(&self, query: &[f32], k: usize, beam_width: usize) -> Vec<u32>

Search returning only neighbor IDs.

Source

pub fn search_batch( &self, queries: &[Vec<f32>], k: usize, beam_width: usize, ) -> Vec<Vec<u32>>

Batch search (parallel over queries).

Source

pub fn search_filtered_with_dists( &self, query: &[f32], k: usize, beam_width: usize, labels: &[Vec<u64>], filter: &Filter, ) -> Vec<(u32, f32)>

Search with quantized beam search and a metadata filter.

Composes quantized distance computation with label-based filtering. labels must have one entry per vector in the index, with the same ordering as the base index vectors.

Distances in the returned results are:

  • If rerank_size > 0: exact distances from the base index
  • Otherwise: approximate distances from the quantizer
Source

pub fn search_filtered( &self, query: &[f32], k: usize, beam_width: usize, labels: &[Vec<u64>], filter: &Filter, ) -> Vec<u32>

Search with filter, returning only neighbor IDs.

Source

pub fn save_quantized(&self, path: &str) -> Result<(), DiskAnnError>

Save the quantizer state and codes to a sidecar file.

The base index should be saved separately via DiskANN::build_index or already persisted on disk.

§Sidecar Format
[magic: u32 = 0x51414E4E]
[version: u32 = 1]
[quantizer_type: u8]        // 0=PQ, 1=F16, 2=Int8
[num_vectors: u64]
[code_size: u64]
[quantizer_data_len: u64]
[quantizer_data: bincode]
[codes: num_vectors * code_size bytes]
Source

pub fn open( base_path: &str, quantized_path: &str, dist: D, config: QuantizedConfig, ) -> Result<Self, DiskAnnError>

Open a QuantizedDiskANN from a base index path and a sidecar path.

Source

pub fn to_bytes(&self) -> Vec<u8>

Serialize the quantizer + codes to bytes (without the base index).

Source

pub fn from_bytes( bytes: &[u8], dist: D, config: QuantizedConfig, ) -> Result<Self, DiskAnnError>

Deserialize from bytes (base index + quantized data).

Source§

impl<D> QuantizedDiskANN<D>
where D: Distance<f32> + Send + Sync + Copy + Clone + 'static,

Source

pub fn build_pq( vectors: &[Vec<f32>], dist: D, file_path: &str, ann_params: DiskAnnParams, pq_config: PQConfig, config: QuantizedConfig, ) -> Result<Self, DiskAnnError>

Build a PQ-quantized index from scratch.

Source

pub fn build_f16( vectors: &[Vec<f32>], dist: D, file_path: &str, ann_params: DiskAnnParams, config: QuantizedConfig, ) -> Result<Self, DiskAnnError>

Build an F16-quantized index from scratch.

Source

pub fn build_int8( vectors: &[Vec<f32>], dist: D, file_path: &str, ann_params: DiskAnnParams, config: QuantizedConfig, ) -> Result<Self, DiskAnnError>

Build an Int8-quantized index from scratch.

Auto Trait Implementations§

§

impl<D> Freeze for QuantizedDiskANN<D>
where D: Freeze,

§

impl<D> RefUnwindSafe for QuantizedDiskANN<D>
where D: RefUnwindSafe,

§

impl<D> Send for QuantizedDiskANN<D>

§

impl<D> Sync for QuantizedDiskANN<D>

§

impl<D> Unpin for QuantizedDiskANN<D>
where D: Unpin,

§

impl<D> UnwindSafe for QuantizedDiskANN<D>
where D: 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, 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