
Client-Side Embeddings and Local Semantic Search
Small embedding models are light, fast, and unlock semantic search, similarity, dedup, and routing over content that never leaves the device. Honest scale, storage, and the privacy cliff.
TL;DR: Text embeddings are the quiet workhorse of client-side AI — small embedding models are light and fast, and they unlock semantic search, similarity, dedup, and routing over content that lives entirely in the user's session or device. This article covers why the task profile fits the browser closely, the feature shapes embeddings unlock, storing and querying vectors at honest client scale with brute force as the correct default, and the split patterns once a corpus genuinely outgrows what the client can hold.
Why embeddings fit the browser closely
Embedding models fit the browser's sweet-spot profile closely. Small embedding models are light — the Transformers.js-compatible ONNX builds of all-MiniLM-L6-v2 range from about 23 MB (8-bit) to about 90 MB (32-bit) (as of November 2026, Hugging Face) — run fast on modest hardware, produce compact numeric output, and suit features that call them repeatedly, such as search-as-you-type. That combination matches the sweet-spot task this topic's main guide describes.
The privacy dividend is immediate and concrete. Embedding user-local content entirely on-device means the content itself never has to leave the device to become searchable — search over private notes, in-progress drafts, or session-only data becomes possible without sending that content to a server for indexing.
The quality honesty is worth stating plainly, because it cuts against the instinct to assume every small model is a compromise. A working hypothesis, not a documented rule, is that small embedding models hold up better at semantic similarity than small generative models do at open-ended generation — benchmark the candidate model on your own similarity task before relying on it. On that hypothesis, generation quality degrades visibly as parameter count shrinks, while embedding quality for a well-defined similarity task tends to hold up better at a fraction of the size, which is a large part of why this task shape belongs on the client's side of the ledger by default.
// A minimal embedding pipeline with Transformers.js (as of November 2026, v4.3)
import { pipeline } from '@huggingface/transformers'
const extractor = await pipeline('feature-extraction', 'model-id')
const output = await extractor(text, { pooling: 'mean', normalize: true })The feature shapes embeddings unlock
Semantic search over in-session content is the most direct application: find-in-page or find-in-my-documents that matches meaning rather than exact substrings, so a search for "cancel a subscription" can surface a document that only ever says "end recurring billing."
Similarity and deduplication follow the same mechanism in a different shape. Related-item suggestions, near-duplicate detection across a user-entered list, and clustering a pile of notes or feedback into rough themes are all the same underlying computation — comparing vectors for closeness — applied to a different presentation.
Semantic routing is an underrated shape worth calling out on its own. Classifying an input against a small handful of embedded intents — which form applies, which template fits, which canned answer is appropriate — often replaces what would otherwise require a generative call, at a fraction of the computational cost and with far more predictable behavior.
Every one of these shapes shares one constraint that is easy to violate by accident: the query and the corpus it searches must be embedded by the same model version. Mixing embeddings produced by two different model versions does not fail loudly — it silently degrades results into noise that looks plausible but means nothing, which makes it a genuinely dangerous failure mode to leave unguarded. A search feature that quietly starts returning irrelevant results after a routine model upgrade can be this exact constraint going unenforced — a failure that may surface only when users start complaining that search "got worse" for no apparent reason.
Storing and querying vectors at client scale
Honest scale framing matters before reaching for any tooling. For a client-side corpus of a few thousand to the low tens of thousands of items — the range this section assumes — brute-force cosine similarity computed directly over a typed array is fast, simple, and entirely correct. Reaching for an index before actually measuring whether one is needed is premature optimization wearing a technical disguise.
Persistence for the vectors themselves is straightforward: store them as compact binary artifacts alongside the content they describe. The broader storage-option landscape — which browser API to use for what — belongs to the model-loading side of this topic; what is specific to embeddings here is the arithmetic itself, dimensionality multiplied by float width multiplied by corpus size, which is the honest way to estimate how much space a given corpus of vectors will actually occupy. A few thousand items at a few hundred dimensions in 32-bit floats works out to a handful of megabytes — small next to the embedding model itself (the 8-bit all-MiniLM-L6-v2 ONNX file alone is about 23 MB, as of November 2026), and the arithmetic is worth doing once rather than assumed away.
function cosineSimilarity(a, b) {
let dot = 0, normA = 0, normB = 0
for (let i = 0; i < a.length; i++) {
dot += a[i] * b[i]
normA += a[i] * a[i]
normB += b[i] * b[i]
}
return dot / (Math.sqrt(normA) * Math.sqrt(normB))
}Brute force stops being fine on measurable signals, not on a feeling that the corpus has grown large. Rising latency observed on the actual device, and memory pressure from holding growing numbers of vectors resident, are the two signals worth watching. Small approximate-nearest-neighbor options exist in JavaScript and WebAssembly for when those signals appear — the right choice depends on the specific corpus shape. The honest default posture is to measure first and reach for an index only once the measured numbers, not an assumption about scale, actually justify the added complexity.
Re-embedding deserves recognition as a real, scheduled maintenance event rather than an afterthought. A model upgrade invalidates every previously stored vector at once, because vectors from different model versions are not comparable. Version-stamping every vector and planning an explicit re-embed pass is the same discipline the loading article applies to model versioning, applied here to the derived data the model produces rather than to the model itself.
When the corpus outgrows the client
A handful of split patterns exist at the concept level once a corpus genuinely exceeds what the client can comfortably hold. Embedding on-device while searching a server-side index is one; embedding and searching entirely server-side with client-side caching of results is another; and preserving full client autonomy for just the private subset of the corpus, while the larger public corpus lives server-side, is a third. Each of these shifts the privacy and freshness story in a different direction, and the choice among them is a real architectural decision rather than a default.
The privacy cliff deserves to be named without euphemism. The moment a query embedding leaves the device — sent to a server for comparison against a server-side index — the on-device privacy claim changes shape entirely. Embeddings are derived directly from the content that produced them; they are not anonymized simply by being represented as numbers, and treating them as safe-to-transmit on that basis is a mistake worth avoiding explicitly.
One boundary is worth stating in a single sentence, because it is easy to conflate with this article's territory. Building a site's actual product or content search — autocomplete, typo tolerance, relevance tuning, faceted navigation — is its own engineering craft entirely outside this topic. This article stays specifically on embedding capability over user-local and in-session content, and general client-server routing architecture for hybrid features belongs to its own treatment elsewhere on this topic.
Taken together, embeddings are a small, unglamorous piece of machinery that quietly unlocks the feature shapes this article describes — and the discipline that makes them trustworthy is mostly bookkeeping: pin the model version, measure before indexing, and treat the resulting vectors with the same care as the content they represent.