pub struct RollingHashIdMapper { /* private fields */ }Expand description
Maps sequence-aware block hashes to compact, stable u64 ids.
The mapper is intentionally stateful and reusable across requests/turns: a
block of tokens that appears at the same prefix position in two different
requests will be assigned the same id. Equality of leading hash_ids
between rows therefore signals shared prompt prefixes for replay purposes.
hash_ids here are workload identity labels, not literal Dynamo runtime
KV-cache hashes. Producers should not try to reconcile them with a
production cache.
Implementations§
Source§impl RollingHashIdMapper
impl RollingHashIdMapper
Sourcepub fn block_size(&self) -> usize
pub fn block_size(&self) -> usize
Block size that this mapper was constructed with.
Sourcepub fn hash_token_blocks(&mut self, tokens: &[u32]) -> Vec<u64>
pub fn hash_token_blocks(&mut self, tokens: &[u32]) -> Vec<u64>
Hash a sequence of tokens into Mooncake hash_ids.
Tokens are chunked by block_size; each complete block contributes one
compact id derived from Dynamo’s shared KV-hashing contract. A trailing
partial block also contributes one compact id so replay capacity still
covers the full prompt length. Identical prefixes across requests
resolve to identical leading hash_ids once the mapper has seen them.
Sourcepub fn try_hash_token_blocks(&mut self, tokens: &[u32]) -> Result<Vec<u64>>
pub fn try_hash_token_blocks(&mut self, tokens: &[u32]) -> Result<Vec<u64>>
Fallible variant of Self::hash_token_blocks.
Sourcepub fn ids_for_sequence_hashes(&mut self, sequence_hashes: &[u64]) -> Vec<u64>
pub fn ids_for_sequence_hashes(&mut self, sequence_hashes: &[u64]) -> Vec<u64>
Map precomputed sequence-aware block hashes into compact Mooncake IDs.
This is useful for producers that record stable block hashes in the serving path and only compact them during offline trace conversion.