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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@terminals-tech/embeddings

v0.1.0

Published

Ultra-lightweight semantic embeddings for event graphs. Browser-first with swappable providers.

Readme

@terminals-tech/embeddings

Ultra-lightweight semantic embeddings for event graphs. Browser-first with swappable providers.

Zero dependencies on the core, <3MB total with embeddings model. Runs entirely in browsers.

Installation

npm install @terminals-tech/embeddings

Quick Start

import { EmbeddingProviderFactory, SemanticSearch } from '@terminals-tech/embeddings'

// Create the best available provider (auto-detects)
const provider = await EmbeddingProviderFactory.createBest({
  cache: true,
  quantizeCache: true  // Save 75% memory
})

// Create semantic search
const search = new SemanticSearch(provider)

// Add documents
await search.addDocuments([
  { text: 'User logged in successfully' },
  { text: 'Authentication failed due to invalid password' },
  { text: 'Session expired after timeout' }
])

// Search semantically
const results = await search.search('login problems', { topK: 2 })
// Returns documents about authentication failures and session issues

Features

🎯 Ultra-Lightweight

  • TransformersJS Provider: all-MiniLM-L6-v2 (22MB model, 384 dimensions)
  • Mock Provider: Deterministic embeddings for testing (0 dependencies)
  • Memory-Efficient Cache: LRU with optional int8 quantization

🔄 Swappable Providers

// Use TransformersJS (browser-optimized)
const transformer = await EmbeddingProviderFactory.create('transformers', {
  modelId: 'Xenova/all-MiniLM-L6-v2'
})

// Use mock for testing
const mock = await EmbeddingProviderFactory.create('mock')

// Auto-detect best available
const best = await EmbeddingProviderFactory.createBest()

💾 Memory-Efficient Caching

import { EmbeddingCache } from '@terminals-tech/embeddings'

const cache = new EmbeddingCache({
  maxSize: 1000,       // Maximum entries
  ttlMs: 3600000,      // 1 hour TTL
  quantize: true       // Int8 quantization (75% memory savings)
})

// Use with any provider
const provider = new TransformersEmbeddingProvider({
  cache: true,
  cacheSize: 500,
  quantizeCache: true
})

🔍 Semantic Search

const search = new SemanticSearch(provider)

// Add documents with metadata
await search.addDocuments([
  { 
    text: 'Critical error in payment processing',
    metadata: { severity: 'high', timestamp: Date.now() }
  }
])

// Search with threshold
const results = await search.search('payment issues', {
  topK: 5,
  threshold: 0.7  // Minimum similarity score
})

// Find semantic clusters
const clusters = await search.findClusters({
  minClusterSize: 3,
  similarityThreshold: 0.8
})

Integration with @terminals-tech/graph

Enhance your event graphs with semantic understanding:

import { TextGraph } from '@terminals-tech/graph'
import { enhanceGraphWithSemantics } from '@terminals-tech/embeddings'

const graph = new TextGraph()
await enhanceGraphWithSemantics(graph)

// Now extract semantic relationships
const relations = await graph.extractSemanticRelations(
  'The server crashed because memory usage exceeded the limit'
)
// Understands causal relationship even without explicit keywords

// Find semantic clusters in events
const clusters = await graph.findSemanticClusters(events)
// Groups events by meaning, not just structure

Provider Comparison

| Provider | Model Size | Dimensions | Speed | Quality | Dependencies | |----------|------------|------------|-------|---------|--------------| | TransformersJS | 22MB | 384 | Fast | High | @huggingface/transformers | | Mock | 0KB | 64 | Instant | Test | None |

Memory Optimization

With quantization enabled:

  • Float32: 384 dimensions × 4 bytes = 1,536 bytes per embedding
  • Int8: 384 dimensions × 1 byte = 384 bytes per embedding
  • Savings: 75% memory reduction with ~5% accuracy loss

Browser Support

  • ✅ Chrome 90+
  • ✅ Firefox 89+
  • ✅ Safari 14.1+
  • ✅ Edge 90+

WebAssembly and SIMD support recommended for best performance.

API Reference

EmbeddingProvider Interface

interface EmbeddingProvider {
  embed(text: string): Promise<EmbeddingVector>
  embedBatch(texts: string[]): Promise<EmbeddingVector[]>
  similarity(a: EmbeddingVector, b: EmbeddingVector): number
  dispose?(): void
}

SemanticSearch Methods

  • addDocuments(docs) - Add documents to search index
  • search(query, options) - Search for similar documents
  • findClusters(options) - Find document clusters
  • clear() - Clear the search index
  • stats() - Get memory usage statistics

Performance

  • Embedding Generation: ~10ms per sentence (CPU)
  • Similarity Search: <1ms for 1000 documents
  • Memory Usage: ~400KB for 1000 cached embeddings (quantized)
  • Model Load Time: ~2s first load (cached after)

Examples

See the examples/ directory for:

  • full-system.ts - Complete integration with @terminals-tech suite
  • More examples coming soon!

License

MIT © Intuition Labs


Built with ❤️ for developers who want semantic understanding without the complexity.