Skip to main content

Module tokenize

Module tokenize 

Source
Expand description

Tokenizers.

Dispatch matrix:

VariantBackendFidelity
HfLlama3 { path }HuggingFace tokenizers (lazy-loaded from a local tokenizer.json)Exact, matches Llama3 billing
TiktokenCl100ktiktoken-rsExact (GPT-4, GPT-4o)
TiktokenO200ktiktoken-rsExact (GPT-5 family)
Claudetiktoken-rsApproximation via cl100k_base
Llama3calibrated~3.5 chars/token (mixed text)
Llama2calibrated~3.3 chars/token
CharsDiv4built-inOffline fallback

HfLlama3 lets users point at any local tokenizer.json (Meta-Llama-3, Mistral, Qwen, etc. — anything the HuggingFace tokenizers crate can load). The file is loaded once per path and cached in a process-global HashMap, so repeated count() calls pay tokenization cost only.

A missing or unparseable vocab path silently falls back to the calibrated heuristic; the scrubber/budget never aborts a pack build because the user pointed at a bad path.

Enums§

Tokenizer