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§
Sourcefn encode(&self, vector: &[f32], seed: u64) -> Result<Vec<u8>>
fn encode(&self, vector: &[f32], seed: u64) -> Result<Vec<u8>>
Encode a vector of f32 values into a compressed byte payload.
Sourcefn decode(&self, payload: &[u8], seed: u64) -> Result<Vec<f32>>
fn decode(&self, payload: &[u8], seed: u64) -> Result<Vec<f32>>
Decode a compressed byte payload back into a vector of f32 values.
Sourcefn compression_ratio(&self) -> f64
fn compression_ratio(&self) -> f64
Expected compression ratio (nominal).
Provided Methods§
Sourcefn encode_batch(&self, vectors: &[&[f32]], seed: u64) -> Result<Vec<Vec<u8>>>
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.
Sourcefn decode_batch(&self, payloads: &[&[u8]], seed: u64) -> Result<Vec<Vec<f32>>>
fn decode_batch(&self, payloads: &[&[u8]], seed: u64) -> Result<Vec<Vec<f32>>>
Decode a batch of compressed payloads. Default loops over decode.
Sourcefn encode_batch_compact(
&self,
vectors: &[&[f32]],
seed: u64,
) -> Result<Option<Vec<u8>>>
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.
Sourcefn decode_batch_compact(
&self,
payload: &[u8],
seed: u64,
) -> Result<Option<Vec<Vec<f32>>>>
fn decode_batch_compact( &self, payload: &[u8], seed: u64, ) -> Result<Option<Vec<Vec<f32>>>>
Decode one compact batch payload back into vectors when supported.
Sourcefn is_gpu_accelerated(&self) -> bool
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.
Sourcefn is_gpu_accelerated_for(&self, n: usize, d: usize) -> bool
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.
Sourcefn codebook_digest(&self, _seed: u64) -> Option<String>
fn codebook_digest(&self, _seed: u64) -> Option<String>
Codebook digest (BLAKE3 hex) for provenance receipts. Returns None if the codec doesn’t support this.
Sourcefn rotation_digest(&self, _seed: u64) -> Option<String>
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§
impl KVecCodec for ExactFallbackCodec
impl KVecCodec for FibQuantAdapter
fib only.impl KVecCodec for TurboQuantAdapter
turbo only.