pg-smart-search
Getting Started

Introduction

Why pg-smart-search exists and when to use it. Compare search tiers and understand the core philosophy.

Introduction

pg-smart-search is a Node.js search engine SDK that lives entirely inside your PostgreSQL database. It is designed for developers who want search quality comparable to specialized engines but refuse to maintain separate infrastructure.

Who is this for?

  • Startups & SMBs who can't justify a $500/mo ElasticSearch cluster.
  • Enterprise Backend Engineers who need strict data sovereignty (GDPR, HIPAA).
  • Node.js/TypeScript developers looking for a native, type-safe search integration.

Note: tier doesn't switch automatically based on dataset size — you set it explicitly in TrigramEngineConfig (default STANDARD); the table below is sizing guidance, not autodetection.

Search Tiers Comparison

TierDataset SizeEngine FeaturesIndices Required
LITE< 100k rowsBasic ILIKENone
STANDARD100k - 1M rowsHedged FTS + ILIKE/trigramGIN (FTS) + GiST/GIN (trigram)
ADVANCED> 1M rowsword_similarity rankingGiST/GIN pg_trgm (not RUM — see Search Tiers)
VECTORSemanticOpenAI/Gemini + pgvector (HNSW)pgvector HNSW

Benchmarks

Measured with npm run bench:real against one specific PostgreSQL 16 instance, 1M rows, GIN + GiST indexes — not a universal number, and not directly comparable to your hardware or dataset:

  • Cold Latency (avg): ~56ms, P95: ~204ms
  • Cached Latency (avg): ~0.02ms
  • Algorithmic Scaling: varies by tier — see Search Tiers for which parts are actually index-served vs. in-memory sorted.

Run npm run bench:real against your own schema and data rather than trusting numbers measured on someone else's machine.