Skip to main content

Turbo4Codec

Struct Turbo4Codec 

Source
pub struct Turbo4Codec { /* private fields */ }
Expand description

The Turbo4 codec for a fixed (dimension, rotation-seed) pair.

Implementations§

Source§

impl Turbo4Codec

Source

pub fn new(dim: usize, rotation_seed: u64) -> Result<Self, TurboQuantError>

Build a codec. dim must be even and ≥ 2 (all practical embedding widths are; evenness keeps the two-run nibble layout exact).

Source

pub fn dim(&self) -> usize

Source

pub fn code_len(&self) -> usize

Stored bytes per vector: D/2 nibbles + 8 bytes of constants.

Source

pub fn query_len(&self) -> usize

Query blob length: D int8 codes + 8 bytes of constants.

Source

pub fn encode(&self, v: &[f32]) -> Result<Vec<u8>, TurboQuantError>

Encode a vector into its Turbo4 code blob.

Source

pub fn encode_dual( &self, v: &[f32], ) -> Result<(Vec<u8>, Vec<u8>), TurboQuantError>

Encode both planes from one rotation pass: the Turbo4 code and the 1-bit candidate-generation code (ADR-297 phase C). The bits blob shares this codec’s rotation, so a single query prep serves both.

Source

pub fn encode_query(&self, q: &[f32]) -> Result<Turbo4Query, TurboQuantError>

Prepare a query for traversal + rescoring.

Source

pub fn decode_rotated(&self, blob: &[u8]) -> Vec<f32>

Reconstruct the rotated-space approximation from a code blob (tests/debugging only — the search path never reconstructs).

Source

pub fn decode(&self, blob: &[u8]) -> Vec<f32>

Reconstruct the original-space approximation (inverse rotation applied).

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, 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.