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

Cosine 0.6.0: search syntax, boosting and Next.js

Visitors can search for exact phrases and exclude words, you can rank parts of your site higher, and Cosine Pro builds the index for Next.js.

By Seya Weber

Cosine 0.6.0 is out. @sweberdev/cosine and @sweberdev/cosine-react are on npm, and Cosine Pro 0.4.0 is available to subscribers.

Search syntax

Visitors can narrow a search without any setup on your side:

QueryFinds
"reset password"Sections with these words next to each other, in this order
webhook -retrySections about webhooks that do not contain retry

Phrases and exclusions work in keyword mode and also filter the results of the semantic ranking. Small words such as "the" do not break a phrase. A hyphen only excludes at the start of a word, so sign-in and e-mail stay normal words.

Boosting

Not every page deserves the same rank. Weights are stored in the index:

npx cosine build docs --boost /docs/api=1.5 --boost /blog=0.7

Results below /docs/api rank 50 % higher, blog results 30 % lower. Paths match whole segments, and the longest matching path wins.

Cosine Pro: Next.js

@weber-development/cosine-next builds the index from the pages next build has prerendered, or from out/ after a static export:

{ "scripts": { "build": "next build && cosine-next --base-path /docs" } }

The index lands in public/cosine. The last index is kept in .next/cache, which Vercel and most CI setups keep between builds, so fixing a typo embeds one section instead of the whole site. Error pages and noindex pages are skipped, and it reads the <main> element, so navigation stays out of the results. Synonyms and boosts go into a small cosine.config.json.

Pro now covers the Vite family (Astro, VitePress, SvelteKit, Nuxt) with cosine-vite and Next.js with cosine-next.

Update

pnpm add @sweberdev/cosine@latest @sweberdev/cosine-react@latest

Existing indexes keep working without a rebuild. The details are in the docs, and you can try the syntax in the live demo.

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

Cosine 0.5.0: facets and insights trends

Cosine counts results per section of your site for filters, and Cosine Pro now shows whether your docs search gets better: new gaps, fixed gaps and rising queries.

Cosine