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

@0din/prompt-toolkit

v0.9.7

Published

Multi-language SDK for LSH signature generation for AI prompt similarity detection

Readme

@0din/prompt-toolkit (TypeScript)

Multi-language SDK for LSH (Locality-Sensitive Hashing) signature generation for AI prompt similarity detection.

This is the TypeScript implementation of the odin-prompt-toolkit algorithm, also available in Rust and Python.

Installation

From Git (Development)

npm install git+https://github.com/0din-ai/prompt-toolkit#main:typescript
# or
yarn add git+https://github.com/0din-ai/prompt-toolkit#main:typescript
# or
pnpm add git+https://github.com/0din-ai/prompt-toolkit#main:typescript

Quick Start

Basic LSH Signatures

import { simhashLshMulti, normalizeVector } from '@0din/prompt-toolkit';

// Your embedding vector (must be L2-normalized)
const vector = [0.5, 0.5, 0.5, 0.5];
const normalized = normalizeVector(vector);

// Generate LSH signatures (3 families, 256 bits, 16 bands)
const families = simhashLshMulti(normalized);

console.log(`Signature: ${families[0].signature}`);
console.log(`Bands: ${families[0].bands}`);

Similarity Comparison

import { 
  simhashLshMulti, 
  hammingDistanceHex, 
  cosineFromHamming 
} from '@0din/prompt-toolkit';

// Generate signatures for two vectors
const families1 = simhashLshMulti(vector1);
const families2 = simhashLshMulti(vector2);

// Compute Hamming distance
const distance = hammingDistanceHex(
  families1[0].signature, 
  families2[0].signature
);

// Estimate cosine similarity
const similarity = cosineFromHamming(distance, 256);
console.log(`Estimated cosine similarity: ${similarity.toFixed(3)}`);

Versioned Signatures

import { 
  signatureString, 
  parseSignatureString,
  SignatureVersion 
} from '@0din/prompt-toolkit';

// Format signature with version
const versionedSig = signatureString(SignatureVersion.V1, signature);
console.log(versionedSig); // "0din-v1:abcd1234..."

// Parse signature string
const parsed = parseSignatureString('0din-v1:abcd1234');
console.log(parsed.version); // 'v1'
console.log(parsed.signature); // 'abcd1234'

API Reference

Core Functions

simhashLshMulti(vector, config?)

Generate LSH signatures for a normalized vector.

Parameters:

  • vector: number[] - L2-normalized embedding vector
  • config?: LshConfig - Optional configuration
    • families?: number - Number of hash families (default: 3)
    • bits?: number - Bits per signature (default: 256)
    • bands?: number - Number of bands (default: 16)

Returns: LSHFamily[] - Array of signatures, one per family

hammingDistanceHex(a, b)

Compute Hamming distance between two hex signatures.

Parameters:

  • a: string - First hex signature
  • b: string - Second hex signature

Returns: number - Hamming distance in bits

cosineFromHamming(distance, totalBits)

Estimate cosine similarity from Hamming distance.

Parameters:

  • distance: number - Hamming distance in bits
  • totalBits: number - Total bits in signature

Returns: number - Estimated cosine similarity [-1, 1]

normalizeVector(vector)

L2-normalize a vector to unit length.

Parameters:

  • vector: number[] - Input vector

Returns: number[] - Normalized vector

Type Definitions

interface LSHFamily {
  family: number;
  bits: number;
  signature: string; // hex string
  bands: string[]; // band slices
}

interface LshConfig {
  families?: number;
  bits?: number;
  bands?: number;
}

enum SignatureVersion {
  V0 = 'v0', // OpenAI (1536 dims)
  V1 = 'v1', // ONNX (1024 dims)
  LATEST = 'latest', // Resolves to V1
}

Signature Versions

  • V0: OpenAI text-embedding-3-large (1536 dimensions, API-based)
  • V1: 0din-jailbreak-embeddings-small ONNX (1024 dimensions, local)
  • Latest: Resolves to V1

Important: V0 and V1 signatures are not comparable due to different embedding spaces.

Algorithm

SimHash via Random Hyperplane LSH (Charikar 2002):

  • Deterministic hyperplanes via SplitMix64 PRNG
  • Default: 3 families × 256 bits × 16 bands
  • Hex-encoded signatures (64 hex chars = 256 bits)
  • Hamming distance → cosine similarity via cos(π × d/n)

See the specification for complete algorithm details.

Development

Setup

cd typescript
npm install

Build

npm run build

Run Tests

npm test

Linting & Formatting

npm run lint
npm run format

License

Apache License 2.0