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

@psraghuveer/memento-embedder-local

v0.4.1

Published

Local-only embedding provider for Memento, backed by transformers.js (bge-small-en-v1.5). Lazy-loaded.

Readme

@psraghuveer/memento-embedder-local

Local-only EmbeddingProvider implementation backed by transformers.js using bge-base-en-v1.5.

Lazy-loaded: importing this module does not download or initialise the model. The first call to embed() does. This keeps npx memento --version and other read-only paths fast and offline.

This is the only embedder shipped in v1 — see ADR 0006 — Local embeddings only in v1.

Install

This package ships as a regular dependency of @psraghuveer/memento (the CLI). @huggingface/transformers is declared as a dependency of this package. No additional install step is needed for CLI users.

For standalone library use:

pnpm add @psraghuveer/memento-embedder-local

If embed() is called without @huggingface/transformers on the resolution path, the dynamic import() fails and createLocalEmbedder surfaces a friendly error pointing back to this README.

Usage

import { createLocalEmbedder } from "@psraghuveer/memento-embedder-local";
import { createMementoApp } from "@psraghuveer/memento-core";

const app = await createMementoApp({
  dbPath: "./memento.db",
  embeddingProvider: createLocalEmbedder({
    // Optional. Defaults shown.
    // model: 'bge-base-en-v1.5',
    // dimension: 768,
    // cacheDir: '/path/to/cache', // when undefined, the CLI resolves to $XDG_CACHE_HOME/memento/models
    // maxInputBytes: 32_768,      // UTF-8-safe truncation before tokenisation
    // timeoutMs: 10_000,          // wallclock cap on a single embed call
  }),
});

The factory returns an EmbeddingProvider whose model and dimension are surfaced synchronously, so the bulk re-embed driver can detect stale rows without paying for a forward pass.

Defaults

The defaults below come from the canonical config registry in @psraghuveer/memento-schema/config-keys. Every embedder.local.* key is immutable at runtime: changing the model or dimension mid-session would silently mix incompatible vector spaces, and the input cap / timeout / cache directory shape resource accounting and disk layout that should not flip under a running process. Operators flip them at startup and run embedding rebuild to migrate stored vectors (ADR 0006, Rule 14).

| Option | Config key | Default | Notes | | :-------------- | :------------------------------ | :------------------------------------------------- | :---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | model | embedder.local.model | bge-base-en-v1.5 | Resolved as Xenova/<model> on Hugging Face. Pin a different Xenova/* model to swap embedders. | | dimension | embedder.local.dimension | 768 | Validated against every produced vector. Mismatch ⇒ throw. Must match the chosen model. | | maxInputBytes | embedder.local.maxInputBytes | 32_768 | UTF-8-safe truncation cap. Inputs above this are truncated before tokenisation; the model's context window is bounded anyway, and this caps the worst-case attention-buffer allocation. | | timeoutMs | embedder.local.timeoutMs | 10_000 | Wallclock cap on a single embed call. Times out via Promise.race; auto-embed swallows the rejection and falls back to "memory written without a vector" (recoverable via embedding rebuild). | | cacheDir | embedder.local.cacheDir | null$XDG_CACHE_HOME/memento/models | The CLI resolves the null default to a per-user XDG path so the model cache is persistent and owner-private, instead of landing inside node_modules/.../@huggingface/transformers/.cache/. | | loader | (no config key — DI only) | createDefaultLoader() | DI hook. Tests inject a fake to keep the suite hermetic. |

Behaviour

  • Single-flight initialisation. Concurrent embed() calls share one in-flight load promise; the runtime is imported and the pipeline is built exactly once per provider.
  • Retry after failure. A failing first embed() clears the cached promise so the next call attempts a fresh load.
  • Mean pooling + L2 normalise. The default loader builds the feature-extraction pipeline with pooling: 'mean' and normalize: true, which is the configuration bge-base-en-v1.5 is trained for. Cosine retrieval over the produced vectors is correct without further normalisation downstream.
  • Plain-array output. embed() returns a readonly number[], not a Float32Array. Callers never see a typed-array reference.

Testing

The vitest suite for this package is hermetic by design — it injects a fake loader and never downloads a model. The default loader is exercised by the manual smoke check below; running it in CI would download ~110 MB on every run.

# manual smoke check
node --input-type=module -e "
  import { createLocalEmbedder } from '@psraghuveer/memento-embedder-local';
  const e = createLocalEmbedder();
  const v = await e.embed('hello world');
  console.log(e.model, e.dimension, v.length, v.slice(0, 3));
"