talira

pg_textsearch

PostgreSQL extension for BM25 relevance-ranked full-text search

open sourcePostgreSQLself-hostablefree

pg_textsearch is a PostgreSQL extension from Tiger Data (formerly Timescale) that adds a bm25 index type and an <@> operator, so ORDER BY content <@> 'search terms' LIMIT 10 returns rows ranked by BM25 rather than by ts_rank. It uses Postgres's own text search configurations for tokenizing, answers top-k queries with Block-Max WAND, and supports expression, partial and partitioned indexes, parallel builds, replication and tsquery Boolean and phrase filters. It's released under the PostgreSQL licence and needs PostgreSQL 17 or newer; pairing it with pgvector gives hybrid keyword and vector search in one database. It runs on Tiger Cloud and self-hosted Postgres, and Google Cloud offers it in preview on AlloyDB and Cloud SQL.

Problems it solves

  • rank Postgres full-text search results by BM25 instead of ts_rank
  • add keyword search next to pgvector embeddings so I can fuse both rankings for hybrid retrieval
  • fast top-10 keyword search in Postgres without scoring every row that matches
  • BM25 index over a JSONB field or several text columns in Postgres
  • relevance-ranked keyword search in Postgres under a permissive licence I can ship to customers
  • good search relevance without running a separate search cluster next to our Postgres database
  • one keyword index per language for a multilingual documents table in Postgres
  • Chinese full-text search ranked by relevance in Postgres

Features

  • bm25 index access method with configurable k1 and b
  • <@> operator for ranked ORDER BY ... LIMIT queries, and to_bm25query() to name the index
  • uses PostgreSQL text search configurations, including Chinese through zhparser
  • Block-Max WAND for fast top-k queries
  • expression, partial and partitioned indexes, including JSONB fields and text arrays
  • Boolean and phrase filtering with tsquery (&, |, !, <->, prefix matching)
  • parallel index builds, segment compression and background compaction (with pg_durable)
  • physical replication and hot standby support
  • prebuilt packages for Linux amd64 and arm64; builds from source on macOS and Windows

Limitations

  • Doesn't run on PostgreSQL 16 or older: it supports PostgreSQL 17, 18 and the 19 release candidate1
  • Doesn't give scores you can compare across partitions: BM25 statistics are kept per partition of a partitioned table1
  • Doesn't have built-in faceted search2
  • Doesn't index TimescaleDB compressed chunks or compressed table data2

Alternatives

The same job

These do what pg_textsearch does.

  1. ParadeDB Postgres for full-text search, vector retrieval and aggregations, as an extension (pg_search)
  2. Elasticsearch Open source search, analytics, and AI platform
  3. VectorChord-bm25 Native BM25 ranking index in PostgreSQL
  4. Manticore Search Fast open source search database for full-text, vector and hybrid search, an Elasticsearch alternative
  5. Apache Lucene A high-performance, full-featured text search engine library written in Java
  6. Tantivy Fast full-text search engine library written in Rust

Compare pg_textsearch with the top 3