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

qd-vectordb

v1.0.0

Published

A high-performance TypeScript Vector Database with LSM storage and KD-tree indexing

Readme

QD VectorDB

A high-performance TypeScript Vector Database with LSM storage and KD-tree indexing, supporting cosine similarity and euclidean distance searches.

npm version License: MIT

Features

  • High Performance: LSM-tree storage design for fast writes and efficient reads
  • KD-Tree Indexing: Accelerated k-NN queries for moderate dimensions
  • Similarity Search: Both cosine similarity and euclidean distance support
  • Concurrency: Thread-safe operations with async RWLock coordination
  • Persistence: WAL + SSTables for durable storage
  • Batch Operations: Efficient bulk insert and delete operations
  • TypeScript: Full type safety with comprehensive type definitions

Installation

npm install qd-vectordb

Quick Start

import { VectorDB } from 'qd-vectordb';

async function example() {
  // Open database
  const db = await VectorDB.open({ 
    dir: './data',
    memtableFlushSize: 100,
    maxSSTablesBeforeCompact: 8
  });

  // Add single vector
  const id = await db.add([0.1, 0.2, 0.3], { label: 'example' });

  // Add multiple vectors in batch
  const ids = await db.addBatch([
    { vector: [1, 0], meta: { category: 'A' } },
    { vector: [0, 1], meta: { category: 'B' } },
  ]);

  // Search by cosine similarity
  const similar = await db.searchSimilar([0.9, 0.1], 5);
  console.log('Similar vectors:', similar);

  // Search by euclidean distance
  const nearby = await db.searchNearby([0.9, 0.1], 5);
  console.log('Nearby vectors:', nearby);

  // Delete operations
  await db.delete(id);
  await db.deleteBatch(ids.slice(0, 2));

  // Get count
  const count = await db.count();
  console.log('Total vectors:', count);

  // Persist and close
  await db.save();
  await db.close();
}

example().catch(console.error);

API Reference

VectorDB.open(options)

Creates and opens a new VectorDB instance.

Parameters:

  • options.dir (string): Directory path for data storage
  • options.memtableFlushSize (number, optional): Threshold for memtable flush (default: 1000)
  • options.maxSSTablesBeforeCompact (number, optional): Max SSTables before compaction (default: 10)

Returns: Promise<VectorDB>

Methods

add(vector, metadata?, id?)

Add a single vector to the database.

  • vector: number[] - The vector to store
  • metadata: Record<string, unknown> (optional) - Associated metadata
  • id: string (optional) - Custom ID, auto-generated if not provided

Returns: Promise<string> - The vector ID

addBatch(items)

Add multiple vectors in a single batch operation.

  • items: Array of { vector: number[], meta?: Record<string, unknown>, id?: string }

Returns: Promise<string[]> - Array of vector IDs

searchSimilar(query, k?)

Search for vectors by cosine similarity.

  • query: number[] - Query vector
  • k: number (optional) - Number of results (default: 10)

Returns: Promise<SearchResult[]> - Results with similarity scores

searchNearby(query, k?)

Search for vectors by euclidean distance.

  • query: number[] - Query vector
  • k: number (optional) - Number of results (default: 10)

Returns: Promise<SearchResult[]> - Results with distances

delete(id) / deleteBatch(ids)

Delete vector(s) by ID.

Returns: Promise<boolean> / Promise<number> - Success status or count deleted

count()

Get total number of vectors in the database.

Returns: Promise<number>

save()

Persist all changes to disk.

Returns: Promise<void>

close()

Close the database and release resources.

Returns: Promise<void>

Types

type Vector = number[];

type Metadata = Record<string, unknown>;

type SearchResult = {
  id: string;
  score?: number;      // For similarity search
  distance?: number;   // For nearby search
  vector: Vector;
  meta?: Metadata;
};

type OpenOptions = {
  dir: string;
  memtableFlushSize?: number;
  maxSSTablesBeforeCompact?: number;
};

Architecture

  • Storage: LSM-tree design with Write-Ahead Log (WAL) and Sorted String Tables (SSTables)
  • Indexing: KD-Tree for efficient k-nearest neighbor queries
  • Concurrency: Async RWLock ensures thread-safe operations
  • Persistence: Configurable memtable flush and SSTable compaction

Development

# Install dependencies
npm install

# Build the project
npm run build

# Run demo
npm run demo

# Clean build artifacts
npm run clean

License

MIT License - see LICENSE file for details.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.