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

endee-model

v0.1.0

Published

Sparse text embeddings using the BM25 algorithm for vector database integration

Readme

endee-model

A lightweight JavaScript/TypeScript library for generating sparse text embeddings using the BM25 algorithm. Designed to plug into vector databases (Qdrant, Weaviate, etc.) to enable efficient keyword-based (sparse) search, often combined with dense embeddings for hybrid search.

Installation

npm install endee-model

Quick Start

import { SparseModel } from 'endee-model';

const model = new SparseModel('endee/bm25');

const documents = [
  'The quick brown fox jumps over the lazy dog',
  'Machine learning enables computers to learn from data',
];

for (const embedding of model.embed(documents)) {
  console.log(embedding.asDict()); // { tokenId: weight, ... }
}

Usage

Embed Documents

const model = new SparseModel('endee/bm25');

for (const embedding of model.embed(documents, /* batchSize */ 256)) {
  const dict = embedding.asDict();    // { tokenId: weight }
  const obj  = embedding.asObject();  // { indices: Int32Array, values: Float32Array }
}

Embed Queries

Query embeddings use unit weights (all 1.0) over the unique normalised tokens.

for (const embedding of model.queryEmbed('search query text')) {
  console.log(embedding.asDict());
}

// Also accepts an array of queries
for (const embedding of model.queryEmbed(['query one', 'query two'])) {
  console.log(embedding.asDict());
}

Count Tokens

const count = model.tokenCount('some text here');

Work with SparseEmbedding Directly

import { SparseEmbedding } from 'endee-model';

const embedding = SparseEmbedding.fromDict({ 100: 0.5, 200: 0.8, 300: 1.2 });

embedding.asDict();    // { 100: 0.5, 200: 0.8, 300: 1.2 }
embedding.asObject();  // { indices: Int32Array([100, 200, 300]), values: Float32Array([0.5, 0.8, 1.2]) }

Configuration

SparseModel / Bm25Options

| Option | Default | Description | |--------|---------|-------------| | k | 1.2 | BM25 saturation parameter | | b | 0.75 | Length normalisation factor (0 = none, 1 = full) | | avgLen | 256 | Expected average document length in tokens | | language | "english" | Language for stopword removal and stemming | | maxTokenLen | 40 | Tokens longer than this are discarded | | disableStemmer | false | Skip stemming | | cacheDir | undefined | Custom cache directory |

const model = new SparseModel('endee/bm25', {
  k: 1.5,
  b: 0.8,
  language: 'english',
});

Cache directory

Resolved in this order:

  1. cacheDir option
  2. ENDEE_CACHE_PATH environment variable
  3. {os.tmpdir()}/endee_cache

Available Languages

import { bm25Languages } from 'endee-model';

console.log(bm25Languages()); // ['afrikaans', 'arabic', 'english', ...]

How It Works

  1. Tokenisation — text split into word tokens (punctuation stripped)
  2. Normalisation — stopwords removed, oversized tokens discarded
  3. Stemming — tokens reduced to stems via Porter stemmer (English default)
  4. BM25 weights — term-frequency weights computed:
    weight = tf * (k + 1) / (tf + k * (1 - b + b * (docLen / avgLen)))
  5. Token IDs — each token hashed to a stable integer via MurmurHash3

Note: IDF weighting must be applied on the vector index side. This library outputs TF weights only.

Requirements

  • Node.js >= 14

License

MIT