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-throughThe 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>
impl<T> ExactFallbackAdapter<T>
Sourcepub fn new(
fallback_decoder: Box<dyn Fn(CodecId, &[u8]) -> Result<T, DecompressError> + Send + Sync>,
) -> Self
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).
Sourcepub fn with_strict_mode(self, strict: bool) -> Self
pub fn with_strict_mode(self, strict: bool) -> Self
Enable or disable strict mode.
Sourcepub fn decode_exact(
&self,
codec_id: CodecId,
compressed_data: &[u8],
) -> Result<T, DecompressError>
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.
Sourcepub fn decode_batch(
&self,
items: &[(CodecId, &[u8])],
) -> Result<Vec<T>, DecompressError>
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§impl<T> ExactFallbackAdapter<T>where
T: Clone,
impl<T> ExactFallbackAdapter<T>where
T: Clone,
Sourcepub fn decode_clone(
&self,
codec_id: CodecId,
compressed_data: &[u8],
) -> Result<T, DecompressError>
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§
impl<T> Freeze for ExactFallbackAdapter<T>
impl<T = Vec<u8>> !RefUnwindSafe for ExactFallbackAdapter<T>
impl<T> Send for ExactFallbackAdapter<T>
impl<T> Sync for ExactFallbackAdapter<T>
impl<T> Unpin for ExactFallbackAdapter<T>
impl<T> UnsafeUnpin for ExactFallbackAdapter<T>
impl<T = Vec<u8>> !UnwindSafe for ExactFallbackAdapter<T>
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<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.