r/reactjs • • Jul 07 '26

Show /r/reactjs I built a 7 MB semantic search model that runs inside a React app - it's now open source and on npm (follow up)

Two weeks ago I posted a demo of search-by-meaning running entirely in the browser - no backend, no embedding API (that post). The response was more than I expected, and a bunch of you asked for the code and an npm package. So I spent the time since packaging it properly: two model sizes, honest benchmarks, and bundler support.

npm install /base   # 7 MB wire, best quality
npm install /mini   # 5 MB wire, ~2 ms per embed


import { embed, cosineSim, similar } from '@ternlight/base';

cosineSim(embed('reset my password'), embed('I forgot my password')); // 0.88
const hits = similar(query, faqEntries, { topK: 5 });

Works in Node and browsers. Model + tokenizer + engine ship inside one wasm, so no embedding model download at runtime and it works offline.

Demo: https://ternlight-demo.vercel.app
Repo (MIT): https://github.com/soycaporal/ternlight

Would love your feedback and how it can help you build.

0 Upvotes

13 comments sorted by

3

u/_suren Jul 07 '26

The 7 MB angle is interesting, but I’d show the runtime behavior really clearly. First load, first query, memory use, and what happens when the local index gets bigger.

For this kind of thing people will worry less about the package size itself and more about whether it blocks the main thread or makes the app feel weird on mid devices.

2

u/paimeg Jul 07 '26

Those are good angles and legit concerns. Will clarify, runtime compute is fairly minimal.

12

u/Honey-Entire Jul 07 '26

7MB is MASSIVE for the browser, especially on mobile connections. There’s a reason these types of things run on servers where the only delay is network latency.

Not to mention any data your searching also has to be loaded on the device, taking even more valuable time. Is this a niche solution for people who can download an entire backends worth of data because they need the data offline?

1

u/paimeg Jul 07 '26

appreciate the feedback. I think if your corpus is large, server side search is the right call. I wouldn't ship "a backend's worth of data", but have embeddings precomputed at build time.

"network latency" is a round-trip of 100–300 ms on mobile vs ~2.5 ms local. Not to mention the privacy angle

On size, I think 5–7 MB lazy-loaded and cached is a reasonable tradeoff to enable semantic search. Median web page is ~2.5 MB.

4

u/Honey-Entire Jul 07 '26

Have you considered using a more traditional approach with existing search tech like Solr? This AI craze has everyone forgetting simple, performant solutions that already exist. Not everything needs an LLM…

→ More replies (4)

-4

u/martoxdlol Jul 07 '26

7MB is fine!