Skip to main content
Introducing packages.sweber.dev
All posts
Release2 min read

Cosine 0.1.0 released

Semantic search for documentation sites that runs entirely in the browser. Keyword results on the first keystroke, ranking by meaning once the model has loaded. No server, no API key.

By Seya Weber

Cosine 0.1.0 is out. It adds search by meaning to your documentation site without a search server or an API key. @sweberdev/cosine and @sweberdev/cosine-react are on npm under the MIT licence.

Why

Most docs search either needs a hosted service or matches only exact words. Someone who types "how do I get rid of the app" finds nothing on a page called "Uninstall". Cosine closes that gap in the browser. cosine build splits your Markdown, MDX or HTML pages at their headings and stores a small vector for each section next to your site. Keyword results appear on the first keystroke, and once the embedding model has loaded, the ranking combines keywords and meaning. Queries are never sent anywhere.

What is in 0.1.0

  • An index builder and CLI for Markdown, MDX and built HTML, split at headings with deep links.
  • Hybrid ranking in the browser: BM25 keyword search with prefix matching plus cosine similarity on embeddings.
  • Instant keyword results, semantic ranking as soon as the model is loaded, and keyword-only search for visitors who save data.
  • Compact int8 vectors of about 400 bytes per section. The library itself is about 7 KB gzip.
  • An accessible <cosine-search> web component in English, German, French and Italian that works in any framework.
  • A React component and hooks, English or multilingual models, and the option to serve the model from your own domain for the GDPR and the Swiss FADP.

Install

pnpm add @sweberdev/cosine @huggingface/transformers

Build the index from your docs and add the search field:

<!-- npx cosine build docs --out public/cosine --base-url /docs -->
<script type="module">
  import "@sweberdev/cosine/element"
</script>

<cosine-search index="/cosine/cosine-index.json" lang="de"></cosine-search>

The English model is about 23 MB. It loads only when the search field gets focus and is then cached by the browser.

Try it in the live demo. The full reference is at packages.sweber.dev/cosine/docs.

Cosine Pro

Cosine Pro is available from 9 CHF per month. It adds a Vite plugin that builds the index with every build in Vite, Astro, VitePress, SvelteKit and Nuxt and re-embeds only the sections that changed, plus search insights without tracking: queries without results and results nobody opened. Plans and checkout are on the package page.

Package in this post

Cosine

Semantic search for documentation sites that runs entirely in the browser. No search server, no API key, no query leaves the device.

pnpm add @sweberdev/cosine @huggingface/transformers
View package

Related posts

Release

Derivative 0.1.0 released

A self-hosted changelog and "What's new" widget, built from the Changesets, CHANGELOG.md or commits you already have. No SaaS, no tracking, about 6 kB.

Derivative
Release

Integral 0.1.0 released

Licenses, plans and feature entitlements for developers who sell software. Signed offline license keys, Polar.sh license keys and React feature gates, without a licensing SaaS.

Integral
Release

Logarithm 0.1.0 released

A self-hosted audit log for SaaS apps: who changed what, and when. Field-level diffs in your own Postgres or SQLite, and a ready React view for your customers' admins.

Logarithm