Postgres hybrid search
Combines BM25 keyword and pgvector semantic search in Postgres, so results match both exact words and meaning.
What we improved
Updated the pg_textsearch status. The original called it prerelease and not for production; its README now lists v1.0.0 as the first generally available release. Corrected the PostgreSQL requirement (the frontmatter said 15+, the extension
Improved by YourAISkill from the original by timescale, under its Apache-2.0 licence. The download includes the author's licence and a CHANGES.md listing every change. Both Claude reviews read the improved version.
Claude's review
8/10 Concrete pg_textsearch plus pgvector hybrid search with correct RRF in client and SQL, ef_search and zero-score traps, reranking and debugging.
We asked Claude the question you would ask: would I be glad I installed this? Two separate reviews, the second blind to the first, must both rate a skill 7 or higher before we sell it.
In detail
Use this skill to implement hybrid search combining BM25 keyword search with semantic vector search using Reciprocal Rank Fusion (RRF). **Trigger when user asks to:** - Combine keyword and semantic search - Implement hybrid search or multi-modal retrieval - Use BM25/pg_textsearch with pgvector together - Implement RRF (Reciprocal Rank Fusion) for search - Build search that handles both exact terms and meaning **Keywords:** hybrid search, BM25, pg_textsearch, RRF, reciprocal rank fusion, keyword search, full-text search, reranking, cross-encoder Covers: pg_textsearch BM25 index setup, parallel query patterns, client-side RRF fusion (Python/TypeScript), weighting strategies, and optional ML reranking.
How you use it
- Add it to your pack, then download your pack (1 credit).
- In Claude, open Customize > Skills and upload the zip. Code execution needs to be on under Settings > Capabilities.
- Ask Claude for the job in your own words. It uses the skill when your request matches what it does. Step by step guide
Safety check
Nothing risky found: no hidden instructions, no download and run, no reading of saved passwords or keys.
An automated scan lowers risk but cannot promise zero risk. How we check skills
Preview
The first lines of SKILL.md
---
name: postgres-hybrid-text-search
description: "Implement hybrid search in PostgreSQL that combines BM25 keyword ranking (the pg_textsearch extension) with pgvector semantic search, merged with Reciprocal Rank Fusion (RRF). Covers installing pg_textsearch (shared_preload_libraries), BM25 and HNSW index setup, parameterized queries with to_bm25query, client-side RRF in Python and TypeScript, a single-query SQL RRF, weighting, optional cross-encoder or API reranking, pgvectorscale for large or label-filtered datasets, and debugging with EXPLAIN. Use when the user wants to combine keyword and semantic search, use BM25 or pg_textsearch together with pgvector, implement RRF or hybrid retrieval for RAG, or build search that handles both exact terms (codes, names, SKUs) and meaning."
license: Apache-2.0
compatibility: Requires PostgreSQL 17 or newer with pgvector 0.7.0+ (for halfvec) and pg_textsearch
metadata:
author: tigerdata
---
<!-- Modified by YourAISkill (youraiskill.com) on 2 December 2026 from the original by timescale. See CHANGES.md. -->
# Hybrid Text Search
Hybrid search combines keyword search (BM25) with semantic search (vector embeddings) to get both exact keyword matching and meaning-based retrieval. Reciprocal Rank Fusion (RRF) merges the two ranked lists into one.
This guide combines [pg_textsearch]() (BM25) with [pgvector](https://github.com/pgvector/pgvector). Both extensions are required.
pg_textsearch is an open-source BM25 extension for PostgreSQL. It ranks with true BM25 (configurable `k1` and `b`), which often gives better relevance than the built-in `ts_rank`. Version 1.0.0 was its first generally available release. It supports PostgreSQL 17 and later (check the README for the current list) and must be preloaded:
```
# postgresql.conf, then restart the server
shared_preload_libraries = 'pg_textsearch' # append to any existing list
```
On a managed database, check whether your provider offers pg_textsearch before designing around it.
## When to Use Hybrid Search
- **Use hybrid** when queries mix specific terms (product names, codes, proper nouns) with conceptual intent.
- **Use semantic only** when meaning matters more than wording ("how to fix slow queries" should match "query optimization").
- **Use keyword only** when exact matches are critical (error codes, SKUs, legal citations).
Hybrid search usually improves recall over either method alone, at the cost of two queries and a fusion step. Measure it on your own queries before and after.
## Data Preparation
Chunk documents into smaller pieces (typically 500 to 1000 tokens) and store each chunk with its embedding. Run BM25 and semantic search over the same chunks so fusion compares like with like. Embed queries with the same model used for the stored chunks.
## Golden Path (Default Setup)
```sql
...From timescale's repository, Apache-2.0 licence.
Related skills
-
Checked
Safe Postgres migrations
Plans Postgres schema changes with the right locks and backfills, so migrations run without downtime.
9/101 credit -
Checked
Reversible database migrations
Writes safe, reversible migrations for Postgres, Prisma, Django and others, so tables change without downtime.
8/101 credit -
Checked
MySQL and MariaDB tuning
Guides MySQL and MariaDB schema, indexes, EXPLAIN plans and replication, so your database runs smoothly.
7/101 credit -
Checked
Prisma schema and queries
Writes Prisma schemas, queries and migrations to current Prisma 7 rules, so your code avoids old habits.
7/101 credit -
Checked
BigQuery migration checks
Validates that tables moved to BigQuery match their source on schema, aggregates and rows, so nothing is lost.
7/101 credit -
Checked
Query driven schema design
Designs tables, keys and indexes from your real query patterns, so your data model stays fast as it grows.
7/101 credit