pub struct KvStreamEncoder { /* private fields */ }Expand description
Incremental/streaming KV-cache encoder.
Construct with KvStreamEncoder::new, feed tokens one at a time with
KvStreamEncoder::append_token, and finalize with
KvStreamEncoder::finish to obtain a KvEncodedTensorV1.
The encoder accumulates a BLAKE3 source digest over all appended vectors
using an incremental blake3::Hasher. Pages are buffered as pending
(blocks + metadata) and materialized into KvEncodedPageV1 objects in
finish() once the full source digest is available, ensuring that page
digests match the batch super::codec::encode_kv_tensor path.
Implementations§
Source§impl KvStreamEncoder
impl KvStreamEncoder
Sourcepub fn new(
shape: KvTensorShapeV1,
layout: KvCacheLayoutV1,
profile: KvCompressionProfileV1,
) -> Result<Self>
pub fn new( shape: KvTensorShapeV1, layout: KvCacheLayoutV1, profile: KvCompressionProfileV1, ) -> Result<Self>
Create a new streaming encoder.
Validates the shape, layout, and profile, then builds a quantizer from
the profile. The source digest accumulator is initialized with the
domain tag and expected total element count so that incremental
hashing produces the same result as super::receipt::kv_tensor_digest.
Currently requires batch = 1, layers = 1, kv_heads = 1.
Sourcepub fn append_token(
&mut self,
key_vector: &[f32],
value_vector: &[f32],
) -> Result<AppendReceipt>
pub fn append_token( &mut self, key_vector: &[f32], value_vector: &[f32], ) -> Result<AppendReceipt>
Append one token’s key and value vectors.
Both vectors must have length head_dim and contain only finite values.
Only the vector matching shape.role is encoded into a block; the other
is reported as "raw" in the receipt with zero compressed bytes (it is
not stored in this encoder’s output).
When the current page reaches tokens_per_page blocks, the blocks are
flushed to a pending page buffer (materialized in finish()).
Sourcepub fn finish(self) -> Result<KvEncodedTensorV1>
pub fn finish(self) -> Result<KvEncodedTensorV1>
Finalize the stream and produce the encoded tensor.
Flushes any remaining blocks as the final page, computes the source digest, materializes all pending pages, and builds the compression receipt.
Returns an error if the number of appended tokens does not match
shape.tokens.
Auto Trait Implementations§
impl Freeze for KvStreamEncoder
impl RefUnwindSafe for KvStreamEncoder
impl Send for KvStreamEncoder
impl Sync for KvStreamEncoder
impl Unpin for KvStreamEncoder
impl UnsafeUnpin for KvStreamEncoder
impl UnwindSafe for KvStreamEncoder
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<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for 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.