Expand description
Kannaka Universal Tokenization Engine.
Engine wires the built-in algorithms and adapters into one registry and
offers the operations the CLI, the Python bindings and the benchmarks share:
train through an adapter, encode and decode raw bytes, verify a vocabulary
against its own test vectors.
use kute::{Engine, TrainingConfig, VocabularyId, Pretokenizer, AdapterConfig};
let engine = Engine::new();
let mut config = TrainingConfig::new(VocabularyId::parse("example:greetings").unwrap(), 300);
config.pretokenizer = Pretokenizer::Gpt4;
let corpus = vec![b"hello hello hello world".to_vec()];
let vocab = engine.train("bpe", "text", &AdapterConfig::default(), &corpus, &config).unwrap();
let tokenizer = engine.tokenizer(vocab).unwrap();
let tokens = engine.encode_raw(tokenizer.as_ref(), b"hello world").unwrap();
assert_eq!(engine.decode_raw(tokenizer.as_ref(), &tokens).unwrap(), b"hello world");Re-exports§
pub use kute_adapters as adapters;pub use kute_algorithms as algorithms;pub use kute_bpe as bpe;pub use kute_vocab as vocab;
Modules§
- b64
- Serde helper:
Vec<u8>as standard base64 text. - config
- error
- event
- Typed event streams: symbols that keep their time and their grouping.
- id
- input
Structs§
- Adapter
Capabilities - What an adapter declares about itself.
- Adapter
Config - Free-form adapter options, e.g.
{"field": "event"}. - Adapter
Spec - Canonical
Input - Adapter output and tokenizer input: one record of canonical information.
- Engine
- The engine: a registry plus the common workflows.
- Event
Record - The events of one entity, in time order.
- Event
Schema - How events were read from their source. The schema travels with the stream and is part of its fingerprint, so two streams read from the same file under different schemas are different streams.
- Event
Stream - FnCorpus
- A corpus backed by a closure, for streaming sources.
- Integrity
- Manifest
- Merge
Rule - A learned transformation: tokens
leftandright, adjacent, becomeid. - Provenance
- Registry
- Run-time table of algorithms and adapters.
- Representation
Ref - Pointer to an independently versioned mapping from token ids to another representation (FR-015). KVF only references mappings; it never embeds them.
- Signature
- Test
Vector - A known input and the ids it must encode to. Shipped inside the vocabulary so any implementation can check itself against the file.
- Token
Entry - Token
Record - The token envelope from FR-005: one token with everything needed to interpret it outside its vocabulary file.
- Token
Sequence - Token ids scoped to the exact vocabulary that produced them.
- Tokenizer
Capabilities - What a tokenizer declares about itself (FR-002, ADR-0007).
- Training
Config - Everything a training run needs. Identical configuration and corpus must produce an identical vocabulary (FR-003 deterministic mode is the only mode in v0.1).
- VecCorpus
- An in-memory corpus.
- Verify
Report - Result of running a vocabulary’s embedded test vectors.
- Version
- SemVer version as defined by https://semver.org.
- Vocabulary
- Vocabulary
Id - A vocabulary identifier such as
kute:industrial:events.
Enums§
- Kute
Error - Every failure KUTE reports. Library code returns these instead of panicking, including on malformed or hostile input.
- Modality
- What kind of information a payload carries. Declared by the adapter.
- Payload
- The two canonical shapes a tokenizer accepts (ADR-0004).
- Payload
Kind - Pretokenizer
- How byte input is split into chunks before merges are learned or applied.
- Representation
- A numeric representation of one token (FR-015).
- Time
Unit - What one tick of a timestamp means.
- Token
Kind - Token
Payload - Unknown
Policy - What an encoder does with a symbol its frozen vocabulary does not contain.
Constants§
- KUTE_
VERSION - Version of the KUTE software that produced an artifact.
- KVF_
VERSION - The KVF format version this build reads and writes.
- MAX_
ESCAPES - Most escaped symbols one sequence may carry.
Traits§
- Corpus
Source - A stream of canonical records to train on.
- Modality
Adapter - Converts raw bytes of some format to canonical input and back (PRD 9.3).
- Representation
Backend - Maps token ids to another representation. Mappings are versioned on their own and never change what a token id means (FR-015, ADR-0011).
- Tokenizer
- The generic tokenizer interface (PRD 9.3).
Functions§
- check_
sequence - Check that a token sequence was produced by exactly this vocabulary.
- collect_
files - Files under
path, recursively, in sorted order. A file path is returned as is. Hidden entries (leading dot) inside directories are skipped. - decoded_
bytes_ at_ least - A lower bound on the bytes
tokensdecodes to. For a byte vocabulary it is the decoded length. For a symbol vocabulary it is the total length of the symbol names, before the adapter writes them out, which only adds to it. A symbol may be up to 1024 bytes long, so the number of symbols (decoded_units) says little about the bytes; this does. - decoded_
units - How many units (bytes or symbols)
tokensdecodes to, computed from the token table without decoding. A five-byte id can stand for a 64 KiB token, so callers that decode untrusted sequences check this against a budget first. - hex
- Lowercase hex encoding.
- sha256_
tagged - Hex SHA-256 with the
sha256:prefix used throughout KUTE.