pub struct TokenEstimation {
pub chars_per_token: usize,
}Expand description
How many characters of serialized JSON count as one token in the cheap
no-tokenizer heuristic. Configured under [context.estimation] and threaded
through estimate_tokens and friends.
The default (4) is the universal rough heuristic; the per-model calibration
ratio (model-self-tuning, docs/design/model-self-tuning.md §2.3) scales the
result on top. Exposed as a setting because a different model/tokenizer may
pack a different number of chars per token — a smart default that adapts when
an expert (human or LLM) tunes it.
Fields§
§chars_per_token: usizeImplementations§
Source§impl TokenEstimation
impl TokenEstimation
Sourcepub fn new(chars_per_token: usize) -> Self
pub fn new(chars_per_token: usize) -> Self
Construct from an explicit ratio (for tests / call sites that aren’t config-driven). A zero is clamped to 1 so division never panics.
Sourcepub fn tokens_for_chars(&self, chars: usize) -> usize
pub fn tokens_for_chars(&self, chars: usize) -> usize
Token estimate for a chars-character string (ceiling-divide, so a
1-char fragment never estimates to zero — err toward counting, 18.1).
Sourcepub fn chars_for_tokens(&self, tokens: usize) -> usize
pub fn chars_for_tokens(&self, tokens: usize) -> usize
The inverse: a character budget for tokens tokens. Used to size a
summarizer input cap from a token budget.
Trait Implementations§
Source§impl Clone for TokenEstimation
impl Clone for TokenEstimation
Source§fn clone(&self) -> TokenEstimation
fn clone(&self) -> TokenEstimation
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreimpl Copy for TokenEstimation
Source§impl Debug for TokenEstimation
impl Debug for TokenEstimation
Source§impl Default for TokenEstimation
impl Default for TokenEstimation
Source§impl<'de> Deserialize<'de> for TokenEstimation
impl<'de> Deserialize<'de> for TokenEstimation
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
impl Eq for TokenEstimation
Source§impl PartialEq for TokenEstimation
impl PartialEq for TokenEstimation
Source§impl Serialize for TokenEstimation
impl Serialize for TokenEstimation
impl StructuralPartialEq for TokenEstimation
Auto Trait Implementations§
impl Freeze for TokenEstimation
impl RefUnwindSafe for TokenEstimation
impl Send for TokenEstimation
impl Sync for TokenEstimation
impl Unpin for TokenEstimation
impl UnsafeUnpin for TokenEstimation
impl UnwindSafe for TokenEstimation
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
impl<T> ErasedDestructor for Twhere
T: 'static,
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>
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 more