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

pg-smart-search

v1.0.0

Published

High-performance fuzzy search SDK for PostgreSQL with Parallel Search and Zombie Query Prevention

Readme

pg-smart-search 🚀

A high-performance Search SDK for PostgreSQL that provides speed and relevance comparable to specialized search engines for most use cases, while maintaining 100% database sovereignty.

🌟 Key Features

  • 🏎️ Parallel Search Strategy: Runs FTS and Trigram searches concurrently for sub-15ms response times.
  • 🧟 Zombie Query Prevention: Automatically cancels background queries via AbortSignal as soon as a winner is found.
  • Turbo Mode (AOT): Support for stored generated columns (tsvector) for lightning-fast linguistic search.
  • 🧠 Smart Hybrid Fallback: linguistic search -> ILIKE -> Trigram Fuzzy -> Keyboard Layout Correction.
  • 🗄️ Professional Caching: Built-in Memory and Redis providers with configurable TTL.
  • 🏆 Ranking & Relevance: Professional BM25-style ranking using ts_rank_cd.
  • 🤖 Semantic Vector Search: Integrated support for OpenAI and Google Gemini embeddings via pgvector.
  • 📊 Built-in Benchmarking: Real-time performance measurement tool included.

🚀 Performance (Elite Tier)

| Metric | Result (Turbo + Parallel) | | :--------------------------- | :------------------------ | | Average Latency (Hit) | ~10.9ms | | p99 Latency (Worst Case) | ~62.1ms | | Throughput | ~90 req/sec | *measured on laptop, dedicated server results will vary

📊 Search Tiers Comparison

| Tier | Dataset Size | Engine Features | Indices Required | | :----------- | :----------- | :--------------- | :---------------- | | LITE | < 100k | Basic ILIKE | None | | STANDARD | 100k - 1M | Trigrams + FTS | GIN | | ADVANCED | > 1M | Normalized + RUM | RUM + Trigrams | | VECTOR | Semantic | OpenAI/Gemini | pgvector (HNSW) |

🛠️ Quick Start

1. Interactive Setup

The easiest way to initialize your database and generate configuration:

npm run init

2. Basic Usage

import { TrigramSearchEngine, MemoryCacheProvider } from "pg-smart-search";

const engine = new TrigramSearchEngine(adapter, {
  tableName: "hadiths",
  searchColumns: ["text", "title"],
  ftsColumn: "search_vector", // Enabled via Turbo Mode
  cacheProvider: new MemoryCacheProvider(),
  defaultTTL: 3600,
});

const results = await engine.search({
  query: "prayrr", // Typo handled by Fuzzy fallback
  language: "ru", // Supports automatic layout correction
});

🔋 Advanced Features

Smart Caching

Enable Redis for distributed production environments:

import { RedisCacheProvider } from "pg-smart-search";
const cache = new RedisCacheProvider(myRedisClient);

Parallel Fast-Track

The engine doesn't wait for all strategies. If the fast FTS finds results, it returns them immediately and cancels the slower trigram searches via AbortSignal.

Benchmark Your Data

Test the actual performance on your dataset with the built-in tool:

npm run bench

📦 Installation

npm install pg-smart-search

Why pg-smart-search?

It's the "Golden Mean":

  • Faster than ILIKE: Uses GIN/RUM indices and parallel execution.
  • Cheaper than ES: Zero extra infrastructure costs if you already use PG.
  • Smarter than standard SQL: Handles typos, layout issues, and BM25 ranking out of the box.

License

MIT