Skip to main content

ExactFallbackAdapter

Struct ExactFallbackAdapter 

Source
pub struct ExactFallbackAdapter<T = Vec<u8>> { /* private fields */ }
Expand description

Decodes compressed data into exact (full-precision) vectors.

§Exact fallback protocol

compressed_bytes ──► ExactFallbackAdapter ──► exact_vector
                                 │
                                 ├── turbo_quant codec ──► turbo_quant::decode()
                                 ├── fib_quant   codec ──► fib_quant::decode()
                                 └── uncompressed     ──► identity pass-through

The adapter consults the CodecId discriminant and dispatches to the appropriate codec decoder. If no decoder is registered for a given codec, an error is returned rather than silently skipping the decode.

§Codec-agnostic design

The adapter does not have a compile-time dependency on turbo-quant or fib-quant. Instead, it accepts a generic fallback function at construction time. The caller (typically the semantic-memory runtime bootstrap) wires up the actual codec implementations. This keeps the adapter reusable and testable without pulling in heavy codec dependencies.

§Example wiring in the semantic-memory runtime:

let adapter = ExactFallbackAdapter::new(|codec_id, data| {
    match codec_id {
        CodecId::TurboQuant => turbo_quant::decode(data).map_err(|e| DecompressError::DecodeFailed(e.to_string())),
        CodecId::FibQuant    => fib_quant::decode(data).map_err(|e| DecompressError::DecodeFailed(e.to_string())),
        CodecId::Uncompressed => Ok(data.to_vec()),
    }
});

A type-erased decode result for codec dispatch.

We use Vec<u8> as the interchange format between the compression adapter and the semantic-memory runtime. The runtime is responsible for interpreting the bytes into domain types (e.g. Vec<f32> vectors).

T is the output type the caller expects after fallback decode.

Implementations§

Source§

impl<T> ExactFallbackAdapter<T>

Source

pub fn new( fallback_decoder: Box<dyn Fn(CodecId, &[u8]) -> Result<T, DecompressError> + Send + Sync>, ) -> Self

Construct a new adapter with the given fallback decoder.

strict_mode = true causes the adapter to return an error when asked to decode a CodecId that has no registered decoder. When false, unknown codec IDs cause a best-effort pass-through (only valid for CodecId::Uncompressed).

Source

pub fn with_strict_mode(self, strict: bool) -> Self

Enable or disable strict mode.

Source

pub fn decode_exact( &self, codec_id: CodecId, compressed_data: &[u8], ) -> Result<T, DecompressError>

Decode compressed_data that was produced by codec_id.

Returns the exact (full-precision) representation, or an error if the decode fails or the codec is not available.

Source

pub fn decode_batch( &self, items: &[(CodecId, &[u8])], ) -> Result<Vec<T>, DecompressError>

Decode multiple compressed items in sequence.

Returns Ok(results) if all decodes succeed, or Err on the first failure (short-circuit). Use this when you need to decode a batch atomically.

Source

pub fn is_strict(&self) -> bool

Returns true if the adapter is in strict mode.

Source§

impl<T> ExactFallbackAdapter<T>
where T: Clone,

Source

pub fn decode_clone( &self, codec_id: CodecId, compressed_data: &[u8], ) -> Result<T, DecompressError>

Decode a single item, cloning the result if the same data is needed multiple times.

This is useful when the same compressed vector needs to be used in multiple result sets simultaneously.

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

Source§

type Output = T

Should always be Self
Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
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