whatisgithub

What is ternlight?

soycaporal/ternlight — explained in plain English

Analysis updated 2026-05-18

573PythonAudience · developerComplexity · 2/5LicenseSetup · easy

In one sentence

A tiny 5-7 MB WebAssembly embedding engine that turns text into vectors on-device, with no API calls and no GPU required.

Mindmap

mindmap
  root((repo))
    What it does
      Text embeddings
      On-device inference
      Similarity search
    Tech stack
      Rust
      WebAssembly
      Python
      npm
    Use cases
      Search-as-you-type
      Privacy-sensitive apps
      Offline semantic search
    Audience
      Developers
      Edge platform builders

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

What do people build with it?

USE CASE 1

Add instant search-as-you-type semantic search without a network round trip.

USE CASE 2

Embed text on-device in privacy-sensitive apps so queries never leave the browser.

USE CASE 3

Ship semantic search in offline-first browser extensions or desktop apps.

USE CASE 4

Run embeddings inside edge functions on Cloudflare Workers or Vercel Edge with no separate inference service.

What is it built with?

RustWebAssemblyPythonnpmSIMD

How does it compare?

soycaporal/ternlightfacebookresearch/vicregkhrisat/text-humanizer
Stars573574571
LanguagePythonPythonPython
Last pushed2023-07-06
MaintenanceDormant
Setup difficultyeasyhard
Complexity2/54/5
Audiencedeveloperresearchergeneral

Figures from each repo's GitHub metadata at analysis time.

How do you get it running?

Difficulty · easy Time to first run · 5min

Some bundlers like older Vite or webpack need a one-line config change to handle the WebAssembly module.

Use, modify, and redistribute freely, including commercially, as long as you keep the copyright notice.

So what is it?

ternlight is a small text embedding engine that turns sentences into numeric vectors you can compare for similarity, without calling any external API and without needing a GPU. The whole thing, model, tokenizer, and inference engine, fits inside a single WebAssembly file that is only about 5 to 7 megabytes, so it runs directly on a CPU in the browser, on a server, or on edge platforms. The project comes as two npm packages that share the same simple API: a base tier aimed at higher quality, and a mini tier that trades a bit of accuracy for a smaller download and faster embedding. With either one, you call a single function to turn a string into a fixed length vector, then compare vectors with a cosine similarity function, or ask for the most similar items in a list of texts given a query. The technical trick behind the small size is a distilled version of the all-MiniLM-L6 sentence embedding model, trained with ternary weights, meaning every weight in the model is restricted to negative one, zero, or positive one. That lets the math during inference use only additions and subtractions instead of full multiplications, and the model is trained this way from the start rather than compressed afterward. The inference engine itself is written in Rust and compiled to WebAssembly with SIMD instructions, so the simple math still runs fast on ordinary CPU cores, including ARM chips found in devices like a Raspberry Pi. Because everything runs on the user's own device, ternlight is meant for use cases like search-as-you-type interfaces, privacy sensitive apps where text should never leave the device, offline-first browser extensions or desktop apps, edge functions on platforms like Cloudflare Workers or Vercel Edge, and static sites that want semantic search without running a separate backend service. The repository includes the published npm packages, the Rust to WebAssembly inference engine, a Python pipeline for training and quantizing the model, benchmark and evaluation tooling, and design documentation. It works out of the box with most modern bundlers and edge runtimes, though a couple of build tools, like older Vite versions or webpack, need a small config change to handle the WebAssembly module correctly. The project is released under the MIT license.

Copy-paste prompts

Prompt 1
Show me how to install @ternlight/base and embed a list of strings for similarity search.
Prompt 2
Explain the difference between the @ternlight/mini and @ternlight/base packages and when to use each.
Prompt 3
Help me configure Vite or webpack to bundle ternlight's WebAssembly module correctly.
Prompt 4
Walk me through how ternary weight quantization keeps ternlight's embedding model small.

Frequently asked questions

What is ternlight?

A tiny 5-7 MB WebAssembly embedding engine that turns text into vectors on-device, with no API calls and no GPU required.

What language is ternlight written in?

Mainly Python. The stack also includes Rust, WebAssembly, Python.

What license does ternlight use?

Use, modify, and redistribute freely, including commercially, as long as you keep the copyright notice.

How hard is ternlight to set up?

Setup difficulty is rated easy, with roughly 5min to a first successful run.

Who is ternlight for?

Mainly developer.

Open on GitHub → Ask about another repo

This repo across BitVibe Labs

Verify against the repo before relying on details.