Ternlight: A Client-Side 7 MB Ternary Weight Embedding Model Running in WebAssembly
Ternlight is a client-side text embedding model that packages its execution engine and ternary (BitLinear) weights into a 7 MB npm package. Operating entirely on the CPU via WebAssembly, the system delivers similarity search results in approximately 5 milliseconds with zero network dependencies after the initial cache.
Architecture and Weight Quantization
Ternlight reduces the footprint of text embedding models to run natively within browser environments. The underlying architecture utilizes ternary (BitLinear) weights for its linear layers. This quantization strategy enables a compact deployment footprint of 7 MB for the standard engine and weights, and 5 MB for the mini variant (`@ternlight/mini`). By compressing the representation down to ternary weights, the system bypasses the memory overhead typically associated with deployment of Transformer layers, making client-side execution feasible on standard consumer CPUs without requiring GPU acceleration.
Execution Model and Latency
The engine executes client-side inside the browser. By running compute tasks locally on the host CPU, Ternlight eliminates the network transit costs, API round-trips, and server-side compute infrastructure normally required for semantic search pipelines. A single `embed()` query execution on the `@ternlight/mini` tier achieves a latency of approximately 5 milliseconds. Once the engine and weights are initially loaded and cached by the browser, all subsequent embedding and similarity calculations require zero network requests.
Package Integration and API Design
Distributed as a single, self-contained npm package under the MIT license, `@ternlight/base` bundles both the execution engine and the model weights. This architecture removes the need for a separate post-install model download step. The API exposes direct entry points for generating embeddings and calculating vector similarity.
A typical client-side integration requires three lines of code:
```javascript import { embed, similar } from '@ternlight/base'; similar('easy weeknight dinner ideas', recipes, { topK: 3 }); ```
The runtime capabilities of the engine are demonstrated by indexing and executing semantic search queries across the React documentation codebase entirely within the client's browser thread.