← All models

feature-extraction · text · WASM · ~30 MB

Model2Vec — embeddings with no transformer at inference

Most text embedders run a neural network for every sentence. Model2Vec does not. It is a distilled lookup table: each token has one precomputed vector, and to embed a sentence you just gather those vectors and average them. No attention, no layers, no forward pass — so it does a tiny fraction of the work of an encoder like MiniLM (often 10–100× faster), and the model itself costs almost nothing; the little wall-clock you see is mostly tokenization. Type below and watch meaning become geometry, instantly. Nothing leaves your device.

At a glance

Modelminishlab/potion-base-8M
Task / pipelinefeature-extraction (static token embeddings)
ArchitectureModel2Vec StaticModel — token→vector lookup table + mean pooling (a torch EmbeddingBag), then PCA to 256-d and L2-normalize. No attention, no transformer forward pass.
Output256-dimensional unit vector per text
RuntimeONNX Runtime Web (the official onnx/model.onnx) + the Transformers.js tokenizer, in a Web Worker
Precisionfp32 ONNX (the table is tiny — quantization buys little)
BackendWebAssembly (runs anywhere; no WebGPU needed)
Download~30 MB (mostly the embedding table), cached after first load
LicenseMIT
Web APIsWebAssembly, Web Workers, Cache Storage — all Baseline widely available

Run it

Put one sentence per line, then embed. The matrix shows the cosine similarity between every pair (1.00 = identical direction). Watch the timing readout — this is the whole point.

Cosine similarity matrix

Speed

–
µs / sentence
–
sentences / sec

There is no network to run per sentence — just a table lookup and an average — so the model itself costs next to nothing. On a large batch the per-sentence cost drops toward the microscopic gather-and-average; on tiny batches the wall-clock you see is mostly tokenization overhead.

See inside — the static lookup, step by step

Pick a sentence to see exactly what happens: it is split into tokens, each token is replaced by its one fixed vector from the table (that is the entire "model"), and those vectors are averaged into the 256-number sentence vector. There is no attention between tokens and no layer to run — which is why swapping to a bigger corpus barely changes the speed.

Embed some sentences to inspect one.

Why it matters

Embeddings power search, dedup, clustering, recommendations, and retrieval for LLMs. The usual cost is running a transformer per item — fine for a few sentences, painful for millions or on a phone. Model2Vec collapses that to a lookup, so you can embed a huge corpus, or re-embed on every keystroke, on hardware that could never run an attention model at that rate. It trades a little quality for a lot of speed and a tiny footprint.

Use cases

Basics

Two sentences, one cosine number — and the microsecond timing behind it.

Practical

Semantic search over a large pasted corpus, ranked by meaning — where speed is the feature.

Wild

Live similarity as you type: re-embed on every keystroke, no debounce needed.

Multi-model

Model2Vec prefilter → a slower cross-encoder reranks only the shortlist.

How the API works

Model2Vec's ONNX is a torch EmbeddingBag (mean) — it needs input_ids and offsets, so we run it directly with ONNX Runtime Web and tokenize with Transformers.js:

import * as ort from "onnxruntime-web";
import { AutoTokenizer } from "@huggingface/transformers";

const tok = await AutoTokenizer.from_pretrained("minishlab/potion-base-8M");
const session = await ort.InferenceSession.create(onnxBytes); // onnx/model.onnx

// Bag every token of every sentence; offsets mark where each sentence starts.
const ids = [], offsets = [];
for (const text of texts) {
  offsets.push(ids.length);
  for (const id of tok(text, { add_special_tokens: false }).input_ids.data) ids.push(BigInt(id));
}
const out = await session.run({
  input_ids: new ort.Tensor("int64", BigInt64Array.from(ids), [ids.length]),
  offsets:   new ort.Tensor("int64", BigInt64Array.from(offsets.map(BigInt)), [offsets.length]),
});
// out.embeddings → [batch, 256], already L2-normalized → cosine is a dot product.

No pipeline() forward pass, no attention. The "model" is the embedding table baked into that ONNX; inference is a gather and a mean. It runs in a Web Worker, and the ONNX is stored via the Cache API so it auto-initialises offline on return visits.

References