Skip to main content

KVecCodec

Trait KVecCodec 

Source
pub trait KVecCodec: Send + Sync {
Show 13 methods // Required methods fn codec_id(&self) -> CodecId; fn encode(&self, vector: &[f32], seed: u64) -> Result<Vec<u8>>; fn decode(&self, payload: &[u8], seed: u64) -> Result<Vec<f32>>; fn dim(&self) -> usize; fn compression_ratio(&self) -> f64; // Provided methods fn encode_batch( &self, vectors: &[&[f32]], seed: u64, ) -> Result<Vec<Vec<u8>>> { ... } fn decode_batch( &self, payloads: &[&[u8]], seed: u64, ) -> Result<Vec<Vec<f32>>> { ... } fn encode_batch_compact( &self, vectors: &[&[f32]], seed: u64, ) -> Result<Option<Vec<u8>>> { ... } fn decode_batch_compact( &self, payload: &[u8], seed: u64, ) -> Result<Option<Vec<Vec<f32>>>> { ... } fn is_gpu_accelerated(&self) -> bool { ... } fn is_gpu_accelerated_for(&self, n: usize, d: usize) -> bool { ... } fn codebook_digest(&self, _seed: u64) -> Option<String> { ... } fn rotation_digest(&self, _seed: u64) -> Option<String> { ... }
}
Expand description

A codec compresses and decompresses KV vectors.

Required Methods§

Source

fn codec_id(&self) -> CodecId

Return the codec identifier (“fib_k4_n32”, “turbo_8bit”, etc.).

Source

fn encode(&self, vector: &[f32], seed: u64) -> Result<Vec<u8>>

Encode a vector of f32 values into a compressed byte payload.

Source

fn decode(&self, payload: &[u8], seed: u64) -> Result<Vec<f32>>

Decode a compressed byte payload back into a vector of f32 values.

Source

fn dim(&self) -> usize

The expected dimension of input/output vectors.

Source

fn compression_ratio(&self) -> f64

Expected compression ratio (nominal).

Provided Methods§

Source

fn encode_batch(&self, vectors: &[&[f32]], seed: u64) -> Result<Vec<Vec<u8>>>

Encode a batch of vectors in one call.

The default implementation calls encode in a loop. Codecs that can exploit batch-level parallelism (e.g. fib-quant with gpu-backend) override this to issue a single batched dispatch.

The returned byte payloads are in the same order as vectors.

Source

fn decode_batch(&self, payloads: &[&[u8]], seed: u64) -> Result<Vec<Vec<f32>>>

Decode a batch of compressed payloads. Default loops over decode.

Source

fn encode_batch_compact( &self, vectors: &[&[f32]], seed: u64, ) -> Result<Option<Vec<u8>>>

Encode a batch into one amortized binary payload when supported.

Default None preserves legacy per-vector block storage. The fib adapter overrides this with FB2 so pool storage pays the codec profile/header once per layer side instead of once per vector.

Source

fn decode_batch_compact( &self, payload: &[u8], seed: u64, ) -> Result<Option<Vec<Vec<f32>>>>

Decode one compact batch payload back into vectors when supported.

Source

fn is_gpu_accelerated(&self) -> bool

True if this adapter has access to GPU acceleration at runtime.

This is distinct from the gpu feature being compiled in: a corpus too small for the GPU’s batch threshold will fall through to CPU even when the feature is on. The pool build receipt uses this to set the backend field honestly.

The default probes device availability only. Codecs that gate on batch size / dim should override Self::is_gpu_accelerated_for.

Source

fn is_gpu_accelerated_for(&self, n: usize, d: usize) -> bool

True if a batch of n vectors at dimension d would actually dispatch to GPU. Default falls back to the device-availability probe; codecs with a runtime threshold should override.

Source

fn codebook_digest(&self, _seed: u64) -> Option<String>

Codebook digest (BLAKE3 hex) for provenance receipts. Returns None if the codec doesn’t support this.

Source

fn rotation_digest(&self, _seed: u64) -> Option<String>

Rotation digest (BLAKE3 hex) for provenance receipts. Returns None if the codec doesn’t support this.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl KVecCodec for ExactFallbackCodec

Source§

impl KVecCodec for FibQuantAdapter

Available on crate feature fib only.
Source§

impl KVecCodec for TurboQuantAdapter

Available on crate feature turbo only.