pub struct NgramCache { /* private fields */ }Expand description
Token-level n-gram cache for speculative draft generation.
Records bigram and trigram patterns from generated text and predicts likely next tokens based on observed frequencies.
Implementations§
Source§impl NgramCache
impl NgramCache
Sourcepub fn record(&mut self, tokens: &[u32])
pub fn record(&mut self, tokens: &[u32])
Record a sequence of tokens into the cache.
Updates both bigram and trigram frequency tables.
Sourcepub fn predict_one(&self, context: &[u32]) -> Option<u32>
pub fn predict_one(&self, context: &[u32]) -> Option<u32>
Predict the most likely next token given the context.
Tries trigram first (higher accuracy), falls back to bigram.
Returns None if no matching pattern is found.
Sourcepub fn draft(&self, context: &[u32], lookahead: usize) -> Vec<u32>
pub fn draft(&self, context: &[u32], lookahead: usize) -> Vec<u32>
Predict up to lookahead tokens by chaining predictions.
Each predicted token is appended to the context for the next prediction. Stops early if no prediction is available.
Sourcepub fn trigram_count(&self) -> usize
pub fn trigram_count(&self) -> usize
Number of unique trigram keys stored.
Sourcepub fn bigram_count(&self) -> usize
pub fn bigram_count(&self) -> usize
Number of unique bigram keys stored.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for NgramCache
impl RefUnwindSafe for NgramCache
impl Send for NgramCache
impl Sync for NgramCache
impl Unpin for NgramCache
impl UnsafeUnpin for NgramCache
impl UnwindSafe for NgramCache
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
Mutably borrows from an owned value. Read more
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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>
Converts
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>
Converts
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 more