npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

libsql-search

v0.11.1

Published

Semantic search for static sites using libSQL/Turso with multi-provider embeddings

Readme

libsql-search

npm version JSR CI License: MIT

libsql-search adds semantic search to Markdown-backed sites with a small TypeScript API. It indexes frontmatter and content from files on disk, stores vectors in libSQL/Turso, and lets you query by meaning instead of exact keywords.

Use it when you want:

  • one indexing/search API across external embedding providers
  • direct control over vector dimensions, table names, and deployment shape
  • a lightweight library instead of a hosted search product

Install

@libsql/client is a peer dependency.

pnpm add libsql-search @libsql/client
npm install libsql-search @libsql/client
deno add jsr:@logan/libsql-search npm:@libsql/client@^0.17.0

For npm usage, the package requires Node >=22.12.0.

@tursodatabase/database is supported as an optional peer, behind the separate libsql-search/turso entry point. It is experimental and exact-search-only, because Turso Database has no ANN vector index. Nothing is installed or resolved for it unless you opt in — see the Turso Database backend guide.

On npm/pnpm, the peer range is @libsql/client ^0.15.0 || ^0.17.0. Both lines are supported: every behavior this package depends on — vector_top_k()'s result shape, the vector index error wording that search() matches on, and transactional batch() rollback — is identical across them, so an existing 0.15.x install does not have to move. There is no 0.16.x line upstream, which is why the range is a disjunction rather than a span. The packaged build is smoke-tested against both arms on every release, at the newest release each arm admits (currently 0.15.15 and 0.17.4).

On JSR/Deno the range does not apply to you. deno.json declares no dependency on @libsql/client — this package imports only its types — so the client you deno add separately is constrained by nothing on our side, and a plain deno add npm:@libsql/client will silently take whatever is newest, including a future major we have never tested. Deno also cannot express our range: npm:@libsql/client@^0.15.0 || ^0.17.0 is a parse error, as is any >=/< span. Pin an arm yourself instead:

deno add jsr:@logan/libsql-search npm:@libsql/client@^0.17.0

Note for 0.17.x: the client no longer exports ./package.json, so require("@libsql/client/package.json") throws ERR_PACKAGE_PATH_NOT_EXPORTED. Nothing in this package reads it, but tooling of yours that inspected the client manifest by specifier needs a direct node_modules path instead. See @libsql/client version differences for the other upgrade-visible change.

Quick Start

This example uses a separately deployed OpenAI-compatible embedding service. libsql-search never loads or hosts an embedding model in-process.

import { createClient } from "@libsql/client";
import { createTable, indexContent, search } from "libsql-search";

const client = createClient({
  url: "libsql://your-db.turso.io",
  authToken: "your-auth-token",
});

const embeddingOptions = {
  provider: "openai-compatible" as const,
  baseUrl: process.env.EMBEDDING_BASE_URL!,
  apiKey: process.env.EMBEDDING_API_KEY,
  model: "bge-large-en-v1.5",
  dimensions: 1024,
};

await createTable(client, "articles_bge_1024", 1024);

await indexContent({
  client,
  contentPath: "./content",
  tableName: "articles_bge_1024",
  embeddingOptions,
});

const results = await search({
  client,
  query: "how do I deploy my docs site",
  tableName: "articles_bge_1024",
  limit: 5,
  embeddingOptions,
});

console.log(results.map((result) => ({
  slug: result.slug,
  title: result.title,
  distance: result.distance,
})));

Important behavior:

  • Call createTable() before indexing or searching. It creates the <tableName>_embedding_idx vector index that search() needs.
  • Keep table width, provider, and dimensions aligned across create/index/query.
  • indexContent() embeds every document before it touches the database, then replaces the table in one transaction, so a failed rebuild leaves the previous index intact.
  • indexContent() throws IndexingError when a file fails; pass failurePolicy: "skip" to rebuild from the remaining files.
  • indexContent() throws IndexingError when no source files are found; pass allowEmptyIndex: true to intentionally empty the index.
  • Every provider sends indexed and queried text to an external service; review that service's privacy, retention, and pricing terms.

Search Accuracy And Performance

search() queries the <tableName>_embedding_idx vector index through libSQL's vector_top_k(). It does not score every row, so query cost no longer grows linearly with the size of the index.

That index is an approximate-nearest-neighbor structure, so the default search path is approximate and can miss a true nearest neighbor. To limit the loss, search() over-fetches candidates from the index, recomputes the true cosine distance for each, and orders exactly by (distance, id) before trimming to limit. Distances on returned rows are always exact, and result ordering is fully deterministic — including when two rows tie — even though the index's own candidate order is not.

Two options control the trade-off:

// Widen the index probe to raise recall (default: max(limit * 4, 32))
await search({ client, query, embeddingOptions, limit: 10, candidates: 200 });

// Bypass the index entirely: exact, but linear in table size
await search({ client, query, embeddingOptions, exact: true });

exact: true is the only way to guarantee exactness. Use it for small corpora, for correctness checks against the index path, and for tables that have no vector index.

Requirements: vector_top_k() and libsql_vector_idx() need a libSQL build with native vector support. The peer dependency is @libsql/client ^0.15.0 || ^0.17.0, verified against 0.15.15 and 0.17.4; remote Turso/libSQL servers must support vector indexes as well. See the API reference for full semantics, and Indexing and operations for tables created before the index existed.

Providers

Built-in providers:

  • cloudflare with @cf/baai/bge-m3 at 1024 dimensions
  • mistral with mistral-embed at 1024 dimensions
  • gemini with gemini-embedding-2 at 128-3072 dimensions, default 3072
  • openai with text-embedding-3-small or text-embedding-3-large, default 768
  • openai-compatible for trusted OpenAI-compatible endpoints such as TEI

Docs

License

MIT