Skip to main content

Crate kute

Crate kute 

Source
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§

AdapterCapabilities
What an adapter declares about itself.
AdapterConfig
Free-form adapter options, e.g. {"field": "event"}.
AdapterSpec
CanonicalInput
Adapter output and tokenizer input: one record of canonical information.
Engine
The engine: a registry plus the common workflows.
EventRecord
The events of one entity, in time order.
EventSchema
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.
EventStream
FnCorpus
A corpus backed by a closure, for streaming sources.
Integrity
Manifest
MergeRule
A learned transformation: tokens left and right, adjacent, become id.
Provenance
Registry
Run-time table of algorithms and adapters.
RepresentationRef
Pointer to an independently versioned mapping from token ids to another representation (FR-015). KVF only references mappings; it never embeds them.
Signature
TestVector
A known input and the ids it must encode to. Shipped inside the vocabulary so any implementation can check itself against the file.
TokenEntry
TokenRecord
The token envelope from FR-005: one token with everything needed to interpret it outside its vocabulary file.
TokenSequence
Token ids scoped to the exact vocabulary that produced them.
TokenizerCapabilities
What a tokenizer declares about itself (FR-002, ADR-0007).
TrainingConfig
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.
VerifyReport
Result of running a vocabulary’s embedded test vectors.
Version
SemVer version as defined by https://semver.org.
Vocabulary
VocabularyId
A vocabulary identifier such as kute:industrial:events.

Enums§

KuteError
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).
PayloadKind
Pretokenizer
How byte input is split into chunks before merges are learned or applied.
Representation
A numeric representation of one token (FR-015).
TimeUnit
What one tick of a timestamp means.
TokenKind
TokenPayload
UnknownPolicy
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§

CorpusSource
A stream of canonical records to train on.
ModalityAdapter
Converts raw bytes of some format to canonical input and back (PRD 9.3).
RepresentationBackend
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_units
How many units (bytes or symbols) tokens decodes 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.

Type Aliases§

Result