Expand description
Tokenizer Caching Layer
Provides a caching wrapper around any tokenizer implementation to speed up repeated tokenization of the same strings (e.g., system prompts).
§Architecture
- L0 Cache: Whole-string exact match (90% of wins)
- L1 Cache: Prefix matching at fixed boundaries (future work)
§Usage
ⓘ
let tokenizer = Arc::new(HuggingFaceTokenizer::from_file("tokenizer.json")?);
let cached = Arc::new(CachedTokenizer::new(tokenizer, CacheConfig::default()));
let encoding = cached.encode("Hello world")?;Structs§
- Cache
Config - Configuration for the tokenizer cache
- Cache
Stats - Cached
Tokenizer - A caching wrapper around any tokenizer
- L0Cache
- L0 cache implementation using DashMap for lock-free reads.
- L1Cache
- L1 cache implementation with special-token-boundary prefix matching
- L1Cache
Stats - Tokenizer
Fingerprint - A fingerprint of a tokenizer’s configuration