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

@stablemodels/qmd-cf

v0.3.0

Published

Hybrid full-text + vector search for Cloudflare Durable Objects. A DO-native reimagination of qmd.

Readme

@stablemodels/qmd-cf

Hybrid full-text + vector search for Cloudflare Durable Objects. A DO-native reimagination of qmd.

FTS5 runs co-located in the DO's SQLite for zero-latency BM25 keyword search. Optionally add Cloudflare Vectorize for semantic search, fused via Reciprocal Rank Fusion.

Install

npm install @stablemodels/qmd-cf

Peer dependency: @cloudflare/workers-types (optional). Core platform types (SqlStorage, SqlStorageCursor, SqlStorageValue) are re-exported from the main entry point, so most consumers don't need the peer dep at all.

Usage

FTS-only (zero external dependencies)

import { Qmd } from "@stablemodels/qmd-cf";

export class MyDO extends DurableObject {
  qmd: Qmd;

  constructor(ctx: DurableObjectState, env: Env) {
    super(ctx, env);
    this.qmd = new Qmd(ctx.storage.sql);
  }

  async index(id: string, content: string) {
    return this.qmd.index({ id, content });
  }

  async search(query: string) {
    return this.qmd.search(query);
  }
}

Hybrid FTS + Vector

this.qmd = new Qmd(ctx.storage.sql, {
  vectorize: env.VECTORIZE,
  embedFn: (texts) =>
    env.AI.run("@cf/baai/bge-m3", { text: texts }).then((r) => r.data),
});

Requires a Vectorize index and Workers AI binding in your wrangler.toml:

[ai]
binding = "AI"

[[vectorize]]
binding = "VECTORIZE"
index_name = "my-index"

API

Indexing

// Index a document
await qmd.index({ id: "doc.md", content: "...", title: "My Doc" });

// Batch index
await qmd.indexBatch(docs);

// Remove a document
await qmd.remove("doc.md");

Documents support optional title, docType, namespace, and metadata fields. Content hashing skips re-indexing when content is unchanged. Use maxChunksPerDocument in config to guard against extremely large documents.

Searching

// Hybrid search (FTS + vector when configured, FTS-only otherwise)
const results = await qmd.search("query", { limit: 5 });

// FTS-only search
const ftsResults = qmd.searchFts("query");

// Vector-only search
const vecResults = await qmd.searchVector("query");

Filter by docType or namespace:

const results = await qmd.search("query", { docType: "note", namespace: "projects/web" });

Other methods

qmd.has("doc.md");                     // Check if document exists
qmd.get("doc.md");                     // Get document content
qmd.list({ namespace: "projects" });   // List document IDs
qmd.listByNamespace("projects/*");     // List docs by namespace pattern
qmd.stats();                           // Index statistics
qmd.rebuild();                         // Rebuild FTS index

Configuration

const qmd = new Qmd(ctx.storage.sql, {
  config: {
    chunkSize: 3200,          // Max chars per chunk (default: 3200)
    chunkOverlap: 480,        // Overlap between chunks (default: 480)
    strongSignalMinScore: 0.85, // BM25 score threshold to skip vector search (default: 0.85)
    strongSignalMinGap: 0.15,   // Min gap between top-1 and top-2 scores (default: 0.15)
    maxChunksPerDocument: 0,    // Max chunks per doc, 0 = unlimited (default: 0)
  },
});

Contexts

Contexts enrich vector embeddings with semantic path descriptions:

qmd.setContext("projects/", "Engineering project documentation");
qmd.setContext("projects/web/", "Frontend web application docs");

Testing

The package provides test utilities via the /testing subpath:

import { MockSqlStorage, createMockEmbedFn } from "@stablemodels/qmd-cf/testing";
import { Qmd } from "@stablemodels/qmd-cf";

const sql = new MockSqlStorage();
const qmd = new Qmd(sql);

await qmd.index({ id: "doc-1", content: "Hello world" });
const results = qmd.searchFts("hello");

sql.close();

MockSqlStorage is backed by bun:sqlite with real FTS5 support. MockVectorize provides in-memory vector search with brute-force cosine similarity. createMockEmbedFn(dims?) returns a deterministic embedding function for reproducible tests.

Requires Bun as the test runner.

Running the library's own tests

# Unit tests (bun, ~200ms)
bun test tests/*.test.ts

# Workerd integration tests (vitest + @cloudflare/vitest-pool-workers)
vitest run --config vitest.config.ts

# Both
npm test