ZeroTokenizer.Core 1.0.0

dotnet add package ZeroTokenizer.Core --version 1.0.0
                    
NuGet\Install-Package ZeroTokenizer.Core -Version 1.0.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="ZeroTokenizer.Core" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="ZeroTokenizer.Core" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="ZeroTokenizer.Core" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add ZeroTokenizer.Core --version 1.0.0
                    
#r "nuget: ZeroTokenizer.Core, 1.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package ZeroTokenizer.Core@1.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=ZeroTokenizer.Core&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=ZeroTokenizer.Core&version=1.0.0
                    
Install as a Cake Tool

๐Ÿ”ค ZeroTokenizer: Sovereign Pure C# BPE & Tiktoken Engine

License: MIT .NET Multi-Targeting Zero External Dependencies

ZeroTokenizer is an ultra-fast, zero-allocation Byte-Pair Encoding (BPE), WordPiece, and Tiktoken tokenizer engine engineered in 100% pure C# for .NET. It resides in Tier 3 (Perception & Intelligence) of the ZeroPlatform ecosystem.


โšก Key Capabilities

  • Zero-Allocation Tokenizer Pipeline:
    • Direct span-based encoding: int Encode(ReadOnlySpan<char> text, Span<int> destinationTokenIds).
    • Fast token counter: int CountTokens(ReadOnlySpan<char> text) without allocating integer arrays or string chunks.
    • Streaming decoding: int Decode(ReadOnlySpan<int> tokenIds, Span<char> destinationText).
  • BPE & Byte-Level Fallback:
    • Implements the standard Byte-Pair Encoding algorithm with UTF-8 byte fallback (compatible with GPT-2, GPT-4, LLaMA-3, and Qwen models).
  • Tiktoken Engine:
    • Pre-configured regex patterns for cl100k_base (OpenAI GPT-4 / ChatGPT) and o200k_base (GPT-4o).
  • Context Token Budgeter (TokenBudgeter):
    • Greedy Knapsack packing algorithm for LLM prompts, ensuring conversation histories, system instructions, and RAG knowledge fragments never overflow the context window ($128\text{k}$ tokens).
  • Zero External Dependencies & Multi-Targeting:
    • Compatible with .NET 8.0+, .NET Framework 4.6.2+, and .NET Standard 2.0.

๐Ÿš€ Quick Start

1. Count Tokens Without Memory Allocations

using ZeroTokenizer.Core;

var tokenizer = TiktokenTokenizer.CreateCl100kBase();

ReadOnlySpan<char> prompt = "System: Analyze factory vibration telemetry at node 4.";
int tokenCount = tokenizer.CountTokens(prompt);

Console.WriteLine($"Token count: {tokenCount}");

2. Encode and Decode Tokens

using ZeroTokenizer.Core;

var tokenizer = TiktokenTokenizer.CreateCl100kBase();

// Encode into pre-allocated buffer
Span<int> tokenBuffer = stackalloc int[128];
int written = tokenizer.Encode("Hello, ZeroPlatform AI Agent!", tokenBuffer);

// Decode back to string
string reconstructed = tokenizer.Decode(tokenBuffer.Slice(0, written));

3. Context Token Budgeting (Knapsack Packing)

using ZeroTokenizer.Core.Budget;

var budgeter = new TokenBudgeter(tokenizer, maxContextTokens: 4096);

budgeter.AddSystemPrompt("You are an autonomous SCADA diagnostic agent.");
budgeter.AddUserMessage("Why did Motor #3 trigger an over-current fault?");
budgeter.AddKnowledgeItem("Motor #3 Bearing Specification Manual: Max rated current is 45A.", priority: 90);

string packedPrompt = budgeter.BuildPackedPrompt();

๐Ÿ“„ License

Architected and developed by Phong Vรต (kzxl). Released under the MIT License.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 is compatible.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (3)

Showing the top 3 NuGet packages that depend on ZeroTokenizer.Core:

Package Downloads
ZeroLlm.Core

Pure C# in-process Small Language Model (SLM) runtime, GGUF v2/v3 binary parser, Paged KV-Cache allocator, Transformer decoder (RMSNorm, RoPE, SwiGLU, GQA), and token sampling engine for .NET.

ZeroAgent.Core

Pure C# enterprise-grade cognitive AI Agent runtime (ReAct loop, tool registry, episodic memory via ZeroVector, and multi-agent swarm) for .NET.

ZeroPrompt.Core

Pure C# Prompt Engineering & Grammar-Constrained Token Decoding Engine (Zero-Allocation Templates, JSON Schema Finite Automata, Logit Masking, and Dynamic Few-Shot Exemplars) for .NET.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.0 34 9/30/2026