pg-smart-search
Getting Started

Quick Start

Set up pg-smart-search in 3 minutes. Install the package, run the interactive CLI, and execute your first search.

Quick Start

Get typo-tolerant, parallel search running in your PostgreSQL database in three steps. (Actual latency depends on your dataset and hardware — see Benchmarks.)

Step 1: Install the package

Install Package
$npm install pg-smart-search

Step 2: Initialize your database

The CLI will automatically create the required indices and generated columns for your dataset.

npx pg-smart-init

Follow the interactive prompts to select your table, columns, and search tier.

Migrations in CI/CD? The CLI is fully interactive with no flags and no non-interactive mode — it can't run unattended in a pipeline today. Run it once locally and commit the generated search-setup.sql as a normal migration instead. See CLI & Migrations.

Step 3: Implement the Search Engine

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

// Wrap your own pg.Pool (or Prisma/Drizzle/etc.) in a 3-method DatabaseAdapter --
// see /docs/guides/configuration for the interface and a minimal example.
const adapter = yourDbAdapter;

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

// Execute search with typo tolerance ("laptpp" instead of "laptop")
const results = await engine.search({
  query: "laptpp",
  language: "en",
});

console.log(results);

Next Steps