pub struct QuantizedDiskANN<D>{ /* 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>
impl<D> QuantizedDiskANN<D>
Sourcepub fn from_pq(
base: DiskANN<D>,
pq: ProductQuantizer,
config: QuantizedConfig,
) -> Self
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.
Sourcepub fn from_f16(base: DiskANN<D>, config: QuantizedConfig) -> Self
pub fn from_f16(base: DiskANN<D>, config: QuantizedConfig) -> Self
Create from an existing index using F16 quantization.
Sourcepub fn from_int8(
base: DiskANN<D>,
int8q: Int8Quantizer,
config: QuantizedConfig,
) -> Self
pub fn from_int8( base: DiskANN<D>, int8q: Int8Quantizer, config: QuantizedConfig, ) -> Self
Create from an existing index and a pre-trained Int8Quantizer.
Sourcepub fn num_vectors(&self) -> usize
pub fn num_vectors(&self) -> usize
Number of vectors in the index.
Sourcepub fn get_vector(&self, idx: usize) -> Vec<f32>
pub fn get_vector(&self, idx: usize) -> Vec<f32>
Get a full-precision vector from the base index.
Sourcepub fn search_with_dists(
&self,
query: &[f32],
k: usize,
beam_width: usize,
) -> Vec<(u32, f32)>
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
Sourcepub fn search(&self, query: &[f32], k: usize, beam_width: usize) -> Vec<u32>
pub fn search(&self, query: &[f32], k: usize, beam_width: usize) -> Vec<u32>
Search returning only neighbor IDs.
Sourcepub fn search_batch(
&self,
queries: &[Vec<f32>],
k: usize,
beam_width: usize,
) -> Vec<Vec<u32>>
pub fn search_batch( &self, queries: &[Vec<f32>], k: usize, beam_width: usize, ) -> Vec<Vec<u32>>
Batch search (parallel over queries).
Sourcepub fn search_filtered_with_dists(
&self,
query: &[f32],
k: usize,
beam_width: usize,
labels: &[Vec<u64>],
filter: &Filter,
) -> Vec<(u32, f32)>
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
Sourcepub fn search_filtered(
&self,
query: &[f32],
k: usize,
beam_width: usize,
labels: &[Vec<u64>],
filter: &Filter,
) -> Vec<u32>
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.
Sourcepub fn save_quantized(&self, path: &str) -> Result<(), DiskAnnError>
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]Sourcepub fn open(
base_path: &str,
quantized_path: &str,
dist: D,
config: QuantizedConfig,
) -> Result<Self, DiskAnnError>
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.
Sourcepub fn to_bytes(&self) -> Vec<u8> ⓘ
pub fn to_bytes(&self) -> Vec<u8> ⓘ
Serialize the quantizer + codes to bytes (without the base index).
Sourcepub fn from_bytes(
bytes: &[u8],
dist: D,
config: QuantizedConfig,
) -> Result<Self, DiskAnnError>
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>
impl<D> QuantizedDiskANN<D>
Sourcepub fn build_pq(
vectors: &[Vec<f32>],
dist: D,
file_path: &str,
ann_params: DiskAnnParams,
pq_config: PQConfig,
config: QuantizedConfig,
) -> Result<Self, DiskAnnError>
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.
Sourcepub fn build_f16(
vectors: &[Vec<f32>],
dist: D,
file_path: &str,
ann_params: DiskAnnParams,
config: QuantizedConfig,
) -> Result<Self, DiskAnnError>
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.
Sourcepub fn build_int8(
vectors: &[Vec<f32>],
dist: D,
file_path: &str,
ann_params: DiskAnnParams,
config: QuantizedConfig,
) -> Result<Self, DiskAnnError>
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> 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