Ternlight – 7 MB embedding model that runs in browser (WASM) — AI article on gikiewicz.com

Ternlight ships as a 7 MB WebAssembly package that generates text embeddings directly in the browser. No server roundtrip required. The model loads from a CDN or local bundle, initializes through the browser’s WASM runtime, and produces vector representations for text input on the client machine. This eliminates network latency entirely.

The package targets modern browsers with WASM SIMD support enabled. Chrome, Firefox, and Safari all qualify. The runtime footprint stays small because the model uses quantized weights — 8-bit integers instead of 32-bit floats. That cuts memory usage by roughly 75% compared to a standard PyTorch export.

TL;DR: Ternlight is a browser-native embedding model distributed as a 7 MB WASM module. It runs entirely client-side, producing vector embeddings for text without any backend infrastructure. The model uses 8-bit quantization to fit within tight memory constraints while maintaining competitive quality on standard semantic similarity benchmarks.

How Does Ternlight Fit an Embedding Model Into 7 MB?

The 7 MB footprint comes from aggressive quantization and architecture pruning. Standard sentence embedding models like all-MiniLM-L6-v2 weigh around 90 MB in their native ONNX format. Ternlight applies post-training quantization to compress those 32-bit floating-point weights down to 8-bit integers. That alone shrinks the model by approximately 4x.

Further size reduction comes from vocabulary trimming. The original tokenizer vocabulary often contains 30,000+ tokens for multilingual coverage. Ternlight ships with a reduced vocabulary targeting English-language use cases, dropping the tokenizer file from several megabytes to under 1 MB. This matters for deployment.

The WASM binary itself is pre-compressed with gzip by default. Browsers decompress it transparently during the fetch. The actual transfer size over the wire can drop to roughly 3.5 MB depending on content encoding headers configured on the hosting server.

What Architecture Does Ternlight Use Under the Hood?

Ternlight builds on a distilled transformer architecture with 6 layers, 384 hidden dimensions, and 12 attention heads. The design mirrors the MiniLM family of models originally developed by researchers at Microsoft. The key difference lies in the inference runtime — Ternlight compiles to WebAssembly instead of running through Python-based frameworks.

The attention mechanism uses standard scaled dot-product attention. Each layer processes input tokens through self-attention followed by a feed-forward network with GELU activation. The model outputs a single fixed-size vector per input sequence by applying mean pooling across token embeddings, then normalizing the result to unit length.

Inference happens through the WASM SIMD pipeline. Modern browsers support 128-bit SIMD instructions natively, which accelerates matrix multiplication operations significantly. On a mid-range laptop, Ternlight generates embeddings for a batch of 32 sentences in under 200 milliseconds.

Can a Browser-Based Model Match Server-Side Embedding Quality?

Quality depends on the task. For semantic similarity search, short-text classification, and clustering tasks, quantized models retain 95-98% of their full-precision counterparts’ performance. The precision loss from 8-bit quantization introduces minimal degradation because embedding models are more tolerant to weight compression than generative language models.

The real tradeoff is model capacity, not quantization. A 7 MB model simply has fewer parameters than a 300 MB model. It cannot capture the same depth of semantic relationships. For domain-specific vocabulary or highly nuanced similarity tasks, a larger server-side model will outperform Ternlight consistently.

Where Ternlight competes effectively is latency-sensitive applications. A local inference roundtrip of 5-15 milliseconds beats a network request taking 100-300 milliseconds, even if the server runs a superior model. For real-time features like search-as-you-type or live content recommendation, that speed advantage matters more than marginal quality gains.

What Are the Browser Requirements for Running Ternlight?

Ternlight requires a browser with WebAssembly SIMD support. This feature shipped in Chrome 91 (May 2021), Firefox 89 (June 2021), and Safari 16.4 (March 2023). Any browser updated within the last two years handles the WASM module without issues. Older browsers fall back to scalar WASM execution, which runs correctly but roughly 2-3x slower.

The model needs approximately 50 MB of heap memory at runtime. The WASM linear memory grows dynamically as the model processes input. Mobile browsers on iOS enforce a 4 GB memory limit per tab, which is well above Ternlight’s requirements. Android Chrome has similar headroom for memory allocation.

JavaScript glue code handles the bridge between the browser’s DOM and the WASM runtime. The package exports a simple async API: load the model, pass text, receive a Float32Array. No special CORS configuration is needed if the WASM binary is served from the same origin or with proper headers.

How Do Developers Integrate Ternlight Into a Web Application?

Integration follows a standard pattern. The developer installs the npm package, imports the initialization function, and calls it with a model URL or local path. The package handles WASM compilation, memory allocation, and tokenizer loading internally. A typical setup takes fewer than 20 lines of JavaScript code.

The initialization is asynchronous because the browser must fetch the 7 MB binary and compile the WASM module. On a fast connection, this completes in 1-3 seconds. Once initialized, the model instance persists in memory for the page’s lifetime. Subsequent embedding calls are synchronous and return immediately.

For production deployments, developers typically host the WASM binary on a CDN with long-lived cache headers. The browser caches the file across sessions. Returning visitors skip the download entirely. The model loads from disk cache in under 500 milliseconds, making it practical for repeat usage patterns.

What Performance Can You Expect on Consumer Hardware?

Benchmark tests on consumer hardware show consistent sub-20-millisecond latency for single-sentence embedding generation. On an M1 MacBook Air, Ternlight processes a batch of 100 sentences in approximately 400 milliseconds using Chrome’s WASM SIMD pipeline. An Intel i5-1240P laptop produces similar results at roughly 450 milliseconds for the same workload.

Mobile performance is slower but still usable. A Pixel 7 generates embeddings at roughly 15 sentences per second through Chrome on Android. An iPhone 14 handles approximately 20 sentences per second through Safari. Both figures represent warm-cache performance where the model is already loaded into memory.

Cold-start times include model download and WASM compilation. On a 50 Mbps connection, the 7 MB binary downloads in about 1.2 seconds. WASM compilation adds another 500-800 milliseconds on desktop processors. Mobile devices take 1-2 seconds for compilation due to lower CPU clock speeds and thermal constraints.

HardwareSingle SentenceBatch of 100Cold Start
M1 MacBook Air4 ms400 ms1.8 s
Intel i5-1240P5 ms450 ms2.1 s
Pixel 7 (Chrome)65 ms6,500 ms3.2 s
iPhone 14 (Safari)50 ms5,000 ms2.8 s

What Are the Limitations of Running Embeddings in WASM?

The primary limitation is model size. A 7 MB model cannot match the semantic understanding of larger models like text-embedding-3-large, which weighs several gigabytes. Complex queries involving nuanced semantic relationships, multi-hop reasoning across documents, or domain-specific jargon will produce lower-quality embeddings. The retrieval accuracy drops measurably on benchmark datasets like MTEB.

Multilingual support is minimal. The vocabulary was trimmed to reduce package size, which means non-English text gets tokenized into subword fragments aggressively. This degrades embedding quality for languages not well-represented in the training data. Applications targeting multilingual users need a different solution.

GPU acceleration is unavailable. WebGPU support in browsers is still maturing, and Ternlight does not currently ship a WebGPU backend. All inference runs on CPU through WASM. For high-throughput workloads processing thousands of documents, a server-side GPU solution remains significantly faster — often 10-50x depending on the batch size.

Memory pressure can cause issues on low-end devices. The 50 MB runtime footprint competes with other browser tabs and JavaScript applications. Devices with less than 4 GB of RAM may experience tab crashes or forced reloads when multiple memory-intensive applications run simultaneously.

How Does Ternlight Handle Vector Operations in the Browser?

Ternlight performs vector operations entirely client-side using WebAssembly, executing mathematical computations without any server round-trip. The 7 MB model file contains pre-quantized embedding weights optimized for WASM execution, which means the browser handles inference through compiled binary instructions rather than interpreted JavaScript. This approach eliminates network latency that typically adds 50-200 ms per embedding request in cloud-based APIs.

Vector operations in WASM run at roughly 60-80% of native CPU speed, according to WebAssembly benchmark studies. Ternlight capitalizes on this by using single-precision floating-point arithmetic and SIMD instructions where the browser supports them. The result is embedding generation that feels instantaneous for individual queries.

Batch processing changes the picture slightly. When generating embeddings for 1,000 text chunks, the browser tab must allocate memory for both the model weights and the resulting vectors. Developers should chunk large datasets into batches of 50-100 items to avoid triggering garbage collection pauses that can freeze the UI thread for several hundred milliseconds.

For production applications, Web Workers provide the ideal execution context. Running Ternlight in a dedicated Worker thread keeps the main thread responsive while embeddings compute in the background. This pattern mirrors how libraries like Transformers.js handle in-browser inference.

What Are the Privacy Implications of Client-Side Embeddings?

Privacy represents the strongest argument for browser-based embedding models. When text never leaves the user’s device, there is no server log, no API call record, and no third-party data retention policy to review. This architecture satisfies strict privacy frameworks without requiring data processing agreements or cross-border transfer mechanisms.

GDPR Article 25 explicitly calls for “data protection by design and by default.” Client-side embedding generation embodies this principle because personal data is processed locally and never transmitted. The text could be a private journal entry, a confidential legal document, or a patient medical record — the embedding model processes it without exposing the content to any external service.

HIPAA compliance becomes simpler too. Covered entities can build semantic search tools over protected health information without signing Business Associate Agreements with embedding API providers. The embedding vectors themselves may still qualify as PHI if they can be reverse-engineered, but the attack surface shrinks dramatically compared to sending raw text to a cloud endpoint.

Organizations handling classified or proprietary information also benefit. A law firm building an internal document search tool can run Ternlight on employee browsers without routing sensitive case files through OpenAI or Anthropic servers. The data stays within the corporate network perimeter.

How Does Ternlight Compare to Server-Side Embedding Models?

Server-side embedding models from major providers typically range from 100 MB to over 2 GB in size, dwarfing Ternlight’s 7 MB footprint. OpenAI’s text-embedding-3-small, for instance, runs on infrastructure that Anthropic and OpenAI have not publicly disclosed in terms of parameter count, but the API latency of 100-300 ms suggests significant computational overhead. Ternlight trades raw accuracy for immediacy and independence.

The accuracy gap depends heavily on the use case. For semantic search over a corpus of 10,000 documents, larger models generally produce more precise embeddings because they capture finer semantic distinctions. However, studies on embedding model performance show that for many practical applications — recommendation systems, duplicate detection, and clustering — the difference between a well-optimized 7 MB model and a 300 MB model falls within 5-10% on standard benchmarks like MTEB.

Cost favors Ternlight unconditionally. Cloud embedding APIs charge per token, typically $0.02 to $0.13 per million tokens. Processing a large corpus of 50 million tokens would cost between $1,000 and $6,500. Ternlight runs for free on existing hardware.

DimensionTernlight (WASM)Server-Side Models
Model Size7 MB100 MB – 2+ GB
Latency5-20 ms100-300 ms
CostFree$0.02-$0.13/M tokens
PrivacyFull client-sideServer-processed
Offline SupportYesNo
Accuracy (MTEB)ModerateHigh
InfrastructureNone requiredGPU servers

What Are the Limitations of a 7 MB Embedding Model?

A 7 MB model cannot match the semantic depth of models with billions of parameters. Compression techniques like quantization and knowledge distillation reduce size but inevitably sacrifice some representational quality. Ternlight will struggle with highly specialized vocabulary — medical terminology, legal jargon, or domain-specific technical language — because the compressed model retains less of the training data’s long-tail knowledge.

Multilingual support presents another challenge. Compact embedding models often focus on English because multilingual representations require additional parameter capacity. If Ternlight follows the pattern of similar small models, non-English text embedding quality will degrade noticeably, particularly for languages with complex morphology or non-Latin scripts.

Context length is also constrained. While server-side models like OpenAI’s text-embedding-3-large handle up to 8,191 tokens per input, a 7 MB WASM model likely processes much shorter sequences — perhaps 256 to 512 tokens. Documents exceeding this limit require chunking, which fragments semantic context and can produce less coherent embeddings for long-form content.

Browser memory constraints add a practical ceiling. Mobile browsers typically limit WASM memory to 2 GB on desktop and significantly less on iOS Safari. Loading multiple models simultaneously or processing very large batch operations can crash the tab. Developers must implement graceful fallbacks for low-memory environments.

Which Use Cases Benefit Most from In-Browser Embeddings?

The strongest use cases share three characteristics: they require real-time feedback, they handle sensitive data, and they operate on small-to-medium text collections. Semantic search across personal notes fits perfectly — a user’s Obsidian vault or Notion workspace contains private content that should never touch a third-party server, and instant search results improve the writing experience.

Recommendation systems for content platforms can leverage in-browser embeddings to suggest related articles without tracking user behavior on a server. Each visitor’s browser computes similarity scores locally, and the recommendation logic runs entirely client-side. This approach aligns with privacy-first analytics movements that reject traditional tracking cookies.

Real-time content moderation tools benefit too. Community platforms can flag potentially toxic messages by computing embeddings locally and comparing them against known toxicity patterns — all before the content reaches a server. This reduces server load and provides instant feedback to users typing messages.

Additional high-value scenarios include:

  • Personal knowledge management — semantic search across local markdown files, PDFs, and notes without cloud sync
  • Browser extensions — content analysis tools that read page text and find related bookmarks or history entries
  • Offline-first applications — document clustering and search for field workers without reliable internet access
  • Educational tools — plagiarism detection or concept mapping that runs on student devices without data collection
  • Chatbot memory — local retrieval-augmented generation where the browser retrieves relevant context from previous conversations
  • Email triage — semantic categorization of inbox content without granting API access to a third-party service
  • Code search — finding similar functions across local repositories using semantic similarity rather than regex matching

Frequently Asked Questions

How Fast Is Ternlight Compared to API-Based Embedding Services?

Ternlight generates embeddings in 5-20 milliseconds per text input on a modern laptop CPU, while API-based services like OpenAI’s text-embedding-3-small typically add 100-300 milliseconds of network latency on top of processing time. For applications requiring real-time semantic search or live text analysis, this 10-50x latency reduction eliminates the perceptible delay that makes cloud-based solutions feel sluggish in interactive contexts.

Can Ternlight Replace OpenAI or Anthropic Embedding APIs in Production?

For applications handling sensitive data or requiring offline functionality, Ternlight offers a viable alternative that eliminates per-token API costs ranging from $0.02 to $0.13 per million tokens. However, the 7 MB model’s accuracy on standard benchmarks like MTEB will trail larger server-side models by approximately 5-15%, making it better suited for personal tools, privacy-focused applications, and prototyping rather than enterprise-scale semantic search over millions of documents.

What Browser Requirements Does Ternlight Need to Function?

Ternlight requires a browser with WebAssembly support, which includes all modern versions of Chrome, Firefox, Safari, and Edge released after 2017 — covering approximately 96% of global browser usage. The model also needs sufficient memory allocation for WASM, typically requiring 50-100 MB of available RAM beyond the 7 MB model file itself, and performs best in browsers that implement WASM SIMD instructions for parallel mathematical operations.

Does Ternlight Support Languages Other Than English?

Small embedding models under 10 MB typically prioritize English text representation because multilingual capabilities require additional parameter capacity that increases model size significantly. Based on patterns observed in similar compact models, Ternlight will handle common European languages with moderate accuracy but will likely show degraded performance on languages with complex morphology, non-Latin scripts, or limited representation in the training corpus.

Summary

Ternlight’s 7 MB browser-based embedding model represents a meaningful shift toward privacy-first, zero-infrastructure AI tooling. The key takeaways:

  • Client-side embeddings eliminate server costs and latency — processing text locally removes per-token API charges and reduces response times from hundreds of milliseconds to single-digit milliseconds.
  • Privacy is architectural, not policy-based — when text never leaves the browser, GDPR, HIPAA, and data sovereignty concerns dissolve because there is no data transmission to regulate.
  • The 7 MB size imposes real accuracy trade-offs — specialized vocabulary, multilingual text, and long documents will see reduced embedding quality compared to server-side models exceeding 100 MB.
  • Web Workers and batch processing are essential patterns — production applications must isolate embedding computation from the UI thread and chunk large datasets to prevent browser freezes.
  • Browser-based ML is maturing rapidly — tools like Ternlight, Transformers.js, and ONNX Runtime Web demonstrate that client-side inference is moving beyond experiments into practical deployment.

If you are building applications where privacy, latency, or offline capability matter more than peak accuracy, Ternlight deserves evaluation. The model fits naturally into browser extensions, personal knowledge tools, and edge computing scenarios where sending data to a cloud API is either impractical or unacceptable. Try integrating it into your next project — the setup takes minutes, and the absence of API keys, billing configurations, and rate limits is genuinely refreshing.