pub struct ProductQuantizerImpl<T: ArrowFloatType + Cosine + Dot + L2> {
    pub num_bits: u32,
    pub num_sub_vectors: usize,
    pub dimension: usize,
    pub metric_type: MetricType,
    pub codebook: Arc<T::ArrayType>,
}
Expand description

Product Quantization, optimized for [Apache Arrow] buffer memory layout.

Fields§

§num_bits: u32

Number of bits for the centroids.

Only support 8, as one of u8 byte now.

§num_sub_vectors: usize

Number of sub-vectors.

§dimension: usize

Vector dimension.

§metric_type: MetricType

Distance type.

§codebook: Arc<T::ArrayType>

PQ codebook

((2 ^ nbits) * num_subvector * sub_vector_length) of f32

Use a layout that is cache / SIMD friendly to compute centroid. But not sure how to make distance lookup via PQ code lookup be cache friendly tho.

Layout:

  • row: all centroids for the same sub-vector.
  • column: the centroid value of the n-th sub-vector.
// Centroids for a sub-vector.
Codebook[sub_vector_id][pq_code]

Implementations§

source§

impl<T: ArrowFloatType + Cosine + Dot + L2> ProductQuantizerImpl<T>

source

pub fn new( m: usize, nbits: u32, dimension: usize, codebook: Arc<T::ArrayType>, metric_type: MetricType ) -> Self

Create a ProductQuantizer with pre-trained codebook.

source

pub fn num_centroids(num_bits: u32) -> usize

source

pub fn codebook_length(num_bits: u32, num_sub_vectors: usize) -> usize

Calculate codebook length.

source

pub fn centroids(&self, sub_vector_idx: usize) -> &[T::Native]

Get the centroids for one sub-vector.

Returns a flatten num_centroids * sub_vector_width f32 array.

Trait Implementations§

source§

impl<T: Debug + ArrowFloatType + Cosine + Dot + L2> Debug for ProductQuantizerImpl<T>
where T::ArrayType: Debug,

source§

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

Formats the value using the given formatter. Read more
source§

impl<T: ArrowFloatType + Cosine + Dot + L2 + 'static> ProductQuantizer for ProductQuantizerImpl<T>

source§

fn as_any(&self) -> &dyn Any

source§

fn transform<'life0, 'life1, 'async_trait>( &'life0 self, data: &'life1 dyn Array ) -> Pin<Box<dyn Future<Output = Result<ArrayRef>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Transform a vector column to PQ code column.
source§

fn build_distance_table( &self, query: &dyn Array, code: &UInt8Array ) -> Result<ArrayRef>

Build the distance lookup in f32.
source§

fn num_bits(&self) -> u32

Get the centroids for one sub-vector.
source§

fn num_sub_vectors(&self) -> usize

Number of sub-vectors
source§

fn dimension(&self) -> usize

source§

fn codebook_as_fsl(&self) -> FixedSizeListArray

source§

fn use_residual(&self) -> bool

Whether to use residual as input or not.

Auto Trait Implementations§

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> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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.

§

impl<T> Pointable for T

§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

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>,

§

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.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
§

impl<T> Allocation for T
where T: RefUnwindSafe + Send + Sync,