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

@memberjunction/ai-local-embeddings

v5.14.0

Published

MemberJunction AI Provider - Local Embeddings Models

Readme

@memberjunction/ai-local-embeddings

MemberJunction AI provider for local text embeddings using Transformers.js. This package runs embedding models directly on your machine, eliminating the need for external API calls, API keys, or per-token charges.

Architecture

graph TD
    A["LocalEmbedding<br/>(Provider)"] -->|extends| B["BaseEmbeddings<br/>(@memberjunction/ai)"]
    A -->|uses| C["Transformers.js<br/>(@xenova/transformers)"]
    C -->|loads from| D["Hugging Face Hub<br/>(or local cache)"]
    C -->|runs| E["Feature Extraction<br/>Pipeline"]
    E -->|generates| F["Embedding Vectors"]
    B -->|registered via| G["@RegisterClass"]

    style A fill:#7c5295,stroke:#563a6b,color:#fff
    style B fill:#2d6a9f,stroke:#1a4971,color:#fff
    style C fill:#2d8659,stroke:#1a5c3a,color:#fff
    style D fill:#b8762f,stroke:#8a5722,color:#fff
    style E fill:#2d6a9f,stroke:#1a4971,color:#fff
    style F fill:#2d8659,stroke:#1a5c3a,color:#fff
    style G fill:#b8762f,stroke:#8a5722,color:#fff

Features

  • Offline Operation: Run embedding models locally without internet (after initial download)
  • No API Keys Required: Eliminate dependency on external services
  • Cost-Effective: No per-token charges for embeddings
  • Privacy-Focused: Data never leaves your infrastructure
  • Multiple Models: Support for various sentence-transformer models from Hugging Face
  • Automatic Caching: Models are downloaded once and cached locally
  • Batch Processing: Efficient batch embedding with configurable batch sizes (default 32)
  • Model Preloading: Warm up models before first inference
  • Quantized Models: Use quantized models for better performance

Supported Models

| Model | Dimensions | Description | |-------|------------|-------------| | all-MiniLM-L6-v2 | 384 | Lightweight general-purpose embeddings | | all-MiniLM-L12-v2 | 384 | Higher quality with more layers | | all-mpnet-base-v2 | 768 | Best quality general-purpose embeddings | | paraphrase-multilingual-MiniLM-L12-v2 | 384 | Multilingual support (50+ languages) | | gte-small | 384 | General Text Embeddings (efficient) | | bge-small-en-v1.5 | 384 | BAAI General Embeddings (English) |

Installation

npm install @memberjunction/ai-local-embeddings

Usage

Single Text Embedding

import { LocalEmbedding } from '@memberjunction/ai-local-embeddings';

const embedder = new LocalEmbedding();

const result = await embedder.EmbedText({
    text: 'Your text to embed',
    model: 'Xenova/all-MiniLM-L6-v2'
});

console.log(result.vector); // Float32Array of embedding values

Batch Embedding

const results = await embedder.EmbedTexts({
    texts: ['First text', 'Second text', 'Third text'],
    model: 'Xenova/all-MiniLM-L6-v2'
});

console.log(results.vectors.length); // 3 embedding vectors

Configuration

embedder.SetAdditionalSettings({
    cacheDir: '/path/to/model/cache',
    useQuantized: true
});

Model Management

// Preload a model for faster first inference
await embedder.preloadModel('Xenova/all-mpnet-base-v2');

// Clear model cache to free memory
embedder.clearCache();
LocalEmbedding.clearSharedCache(); // Static method

Environment Variables

| Variable | Default | Description | |----------|---------|-------------| | TRANSFORMERS_CACHE_DIR | ./.cache/transformers | Directory for storing downloaded models | | TRANSFORMERS_LOCAL_URL | (empty) | Optional local URL for model files |

ESM/CommonJS Compatibility

This package is built as CommonJS. The underlying @xenova/transformers library is ESM-only, so dynamic imports are used as a workaround (the official recommended approach by HuggingFace for CommonJS environments).

Class Registration

Registered as LocalEmbedding via @RegisterClass(BaseEmbeddings, 'LocalEmbedding').

Dependencies

  • @memberjunction/ai - Core AI abstractions
  • @memberjunction/global - Class registration
  • @xenova/transformers - Hugging Face Transformers.js runtime