diskann_quantization/
traits.rs

1/*
2 * Copyright (c) Microsoft Corporation.
3 * Licensed under the MIT license.
4 */
5
6use std::fmt::Debug;
7
8/// A trait implemented by a quantizer, indicating that it is capable of quantizing the
9/// contents oF `From` into `To`.
10pub trait CompressInto<From, To> {
11    /// Errors that may occur during compression.
12    type Error: std::error::Error + 'static + Send + Sync;
13
14    /// An output type resulting from compression.
15    type Output: Debug + Send + Sync;
16
17    /// Compress the data in `From` into `To`.
18    ///
19    /// If an error is encountered, `To` must be left in a valid but undefined state.
20    fn compress_into(&self, from: From, to: To) -> Result<Self::Output, Self::Error>;
21}
22
23/// A trait implemented by a quantizer, indicating that it is capable of quantizing the
24/// contents oF `From` into `To` with additional help from an argument of type `A`.
25///
26/// One example use case of the additional argument would be a
27/// [`crate::alloc::ScopedAllocator`] through which scratch allocations can be made.
28pub trait CompressIntoWith<From, To, A> {
29    /// Errors that may occur during compression.
30    type Error: std::error::Error + 'static + Send + Sync;
31
32    /// Compress the data in `From` into `To`.
33    ///
34    /// If an error is encountered, `To` must be left in a valid but undefined state.
35    fn compress_into_with(&self, from: From, to: To, with: A) -> Result<(), Self::Error>;
36}
37
38/// Create a distance function (i.e. [`diskann_vector::DistanceFunction`]) from a quantizer.
39pub trait AsFunctor<T> {
40    fn as_functor(&self) -> T;
41}