# Postgres hybrid text search

> Postgres hybrid text search is an open-source agent skill for knowledge and memory. Guides building hybrid BM25 and vector search in PostgreSQL with RRF fusion. It is available on Claude Code, Codex, Cursor, Gemini CLI, GitHub Copilot, Windsurf and Goose.

- **Kind:** Skill
- **Pricing:** Open source
- **Platforms:** Claude Code, Codex, Cursor, Gemini CLI, GitHub Copilot, Windsurf, Goose
- **Website:** https://github.com/timescale/pg-aiguide/tree/main/skills/postgres-hybrid-text-search
- **Repository:** https://github.com/timescale/pg-aiguide
- **GitHub stars:** 1,892
- **License:** Apache-2.0
- **Skill name:** postgres-hybrid-text-search
- **Collection:** https://github.com/timescale/pg-aiguide
- **Categories:** [knowledge and memory](https://ai-powered.com/categories/knowledge-and-memory)
- **Listing updated:** 2026-12-04

## About

This skill walks an agent through combining BM25 keyword ranking from pg_textsearch with semantic nearest-neighbour search from pgvector inside one PostgreSQL database. It supplies a default schema with a BM25 index on text and an HNSW index on halfvec embeddings, plus the operator patterns for each search type.

The core technique is client-side Reciprocal Rank Fusion. The agent runs the keyword and semantic queries in parallel, then merges the two ranked lists with a rank-based score, and the skill includes Python and TypeScript fusion functions. It also covers weighting one method above the other, tuning candidate pool sizes, and an optional cross-encoder or hosted reranker pass over a larger candidate set. Guidance on pgvectorscale's DiskANN index with label filtering is included for large or filtered datasets.

The skill expects PostgreSQL 15 or newer with the pgvector and pg_textsearch extensions, and chunked documents stored with their embeddings. It also includes EXPLAIN checks and a short troubleshooting table for missing exact matches and skewed results. The source notes that pg_textsearch is in prerelease and not yet recommended for production.

## When your agent uses it

> 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.

## What it can access

From a static check of the files on GitHub; nothing was run.

- [Instructions only, no scripts](https://github.com/timescale/pg-aiguide/tree/HEAD/skills/postgres-hybrid-text-search)
- [License: Apache-2.0](https://github.com/timescale/pg-aiguide/tree/HEAD/skills/postgres-hybrid-text-search)

## Features

- **BM25 index setup:** Creates a keyword index on text content with a configurable language and BM25 tuning options.
- **Parallel keyword and vector queries:** Runs BM25 and pgvector searches as separate queries that can be issued concurrently from the client.
- **RRF fusion code:** Provides Python and TypeScript functions that merge two ranked result lists using reciprocal rank scores.
- **Weighting strategies:** Shows how to favour keyword or semantic results by scaling each method's contribution.
- **Optional reranking step:** Describes adding a cross-encoder or hosted reranker over a larger fused candidate set.
- **Filtered vector search:** Covers pgvectorscale DiskANN indexes with smallint label arrays for filtered semantic queries.
- **Index verification and troubleshooting:** Explains how to confirm index use with EXPLAIN and fix common relevance and latency problems.

## Good for

- Add hybrid keyword and semantic search to a PostgreSQL-backed document store
- Fuse BM25 and pgvector results into one ranked list with RRF
- Make product code or SKU lookups work alongside meaning-based queries
- Tune the balance between keyword and semantic results in a search API
- Add a reranking stage over search candidates

## Install

### Claude Code

This skill ships in the `pg` plugin. In Claude Code, add the marketplace and install the plugin (it may include other skills too):

```sh
/plugin marketplace add timescale/pg-aiguide
/plugin install pg@aiguide
```

Or copy only this skill to `~/.claude/skills/postgres-hybrid-text-search`:

```sh
tmp=$(mktemp -d) &&
git clone --depth 1 https://github.com/timescale/pg-aiguide.git "$tmp" &&
mkdir -p ~/.claude/skills &&
rm -rf ~/.claude/skills/postgres-hybrid-text-search &&
cp -R "$tmp/skills/postgres-hybrid-text-search" ~/.claude/skills/postgres-hybrid-text-search &&
rm -rf "$tmp"
```

For one project only, put the folder in `.claude/skills/postgres-hybrid-text-search` inside it instead.

### Codex

Copy the skill folder to `~/.agents/skills/postgres-hybrid-text-search` to use it in every repository:

```sh
tmp=$(mktemp -d) &&
git clone --depth 1 https://github.com/timescale/pg-aiguide.git "$tmp" &&
mkdir -p ~/.agents/skills &&
rm -rf ~/.agents/skills/postgres-hybrid-text-search &&
cp -R "$tmp/skills/postgres-hybrid-text-search" ~/.agents/skills/postgres-hybrid-text-search &&
rm -rf "$tmp"
```

For one repository only, put the folder in `.agents/skills/postgres-hybrid-text-search` inside it instead.

### Cursor

Copy the skill folder to `~/.cursor/skills/postgres-hybrid-text-search` to use it in every project:

```sh
tmp=$(mktemp -d) &&
git clone --depth 1 https://github.com/timescale/pg-aiguide.git "$tmp" &&
mkdir -p ~/.cursor/skills &&
rm -rf ~/.cursor/skills/postgres-hybrid-text-search &&
cp -R "$tmp/skills/postgres-hybrid-text-search" ~/.cursor/skills/postgres-hybrid-text-search &&
rm -rf "$tmp"
```

For one project only, put the folder in `.cursor/skills/postgres-hybrid-text-search` inside it instead.

### Gemini CLI

Run in a terminal (add `--scope workspace` to install it for the current workspace only):

```sh
gemini skills install https://github.com/timescale/pg-aiguide.git --path skills/postgres-hybrid-text-search
```

Or copy the folder to `~/.gemini/skills/postgres-hybrid-text-search` yourself.

### VS Code

For GitHub Copilot in VS Code, copy the skill folder to `~/.copilot/skills/postgres-hybrid-text-search`:

```sh
tmp=$(mktemp -d) &&
git clone --depth 1 https://github.com/timescale/pg-aiguide.git "$tmp" &&
mkdir -p ~/.copilot/skills &&
rm -rf ~/.copilot/skills/postgres-hybrid-text-search &&
cp -R "$tmp/skills/postgres-hybrid-text-search" ~/.copilot/skills/postgres-hybrid-text-search &&
rm -rf "$tmp"
```

For one project only, put the folder in `.github/skills/postgres-hybrid-text-search` inside it instead.

### Other agents

Get the folder:

```sh
git clone --depth 1 https://github.com/timescale/pg-aiguide.git
```

Then copy `pg-aiguide/skills/postgres-hybrid-text-search` into your agent's skills folder as `postgres-hybrid-text-search`. Agents that support SKILL.md read one folder per skill.

## FAQ

### What does the skill need to run?

It requires PostgreSQL 15 or newer with the pgvector and pg_textsearch extensions. The guide notes that pg_textsearch currently supports PostgreSQL 17 and 18.

### Does Postgres hybrid text search change my database?

The guidance includes SQL to create extensions, tables and indexes, but the skill itself only instructs the agent on how to build the setup.

### Is pg_textsearch ready for production?

The skill states that pg_textsearch is in prerelease and not yet recommended for production use.

### Which languages are covered for the fusion code?

The skill includes client-side RRF examples in Python and TypeScript.

### Is reranking required?

No. The skill describes reranking as optional, and says RRF alone already improves on single-method search.

### How do I install Postgres hybrid text search in Claude Code?

Copy the skill folder from GitHub to ~/.claude/skills/postgres-hybrid-text-search to use it in all your projects, or to .claude/skills/postgres-hybrid-text-search in one project. Or install the pg plugin, which includes it: /plugin marketplace add timescale/pg-aiguide, then /plugin install pg@aiguide.

### Does Postgres hybrid text search run scripts?

No. It is instructions only, with no scripts. This comes from a static check of the files on GitHub; nothing was run. Read the files before you install it.

### Which AI agents can use Postgres hybrid text search?

Claude Code, Codex, Cursor, Gemini CLI, GitHub Copilot, Windsurf and Goose. Each reads skills in the SKILL.md format from its own folder; the install steps on this page list them.

### What are the best alternatives to Postgres hybrid text search?

The closest alternatives to Postgres hybrid text search are Pgvector semantic search, Qdrant hybrid search, Qdrant hybrid search prefetches, Qdrant hybrid search combining and Qdrant edge.

## Where this comes from

- Description: from the skill's own SKILL.md.

## Alternatives

- [Pgvector semantic search](https://ai-powered.com/skills/pgvector-semantic-search): Pgvector semantic search is an open-source agent skill for databases.
- [Qdrant hybrid search](https://ai-powered.com/skills/qdrant-hybrid-search): Qdrant hybrid search is an open-source agent skill for knowledge and memory.
- [Qdrant hybrid search prefetches](https://ai-powered.com/skills/qdrant-hybrid-search-prefetches): Qdrant hybrid search prefetches is an open-source agent skill for knowledge and memory.
- [Qdrant hybrid search combining](https://ai-powered.com/skills/qdrant-hybrid-search-combining): Qdrant hybrid search combining is an open-source agent skill for knowledge and memory.
- [Qdrant edge](https://ai-powered.com/skills/qdrant-edge): Qdrant edge is an open-source agent skill for knowledge and memory.
- [Qdrant search strategies](https://ai-powered.com/skills/qdrant-search-strategies): Qdrant search strategies is an open-source agent skill for knowledge and memory.
- [Pinecone rag](https://ai-powered.com/skills/pinecone-rag): Pinecone rag is an open-source agent skill for knowledge and memory.
- [Qdrant search strategies](https://ai-powered.com/skills/qdrant-search-strategies-qdrant): Qdrant search strategies is an open-source agent skill for knowledge and memory.

---
Source: https://ai-powered.com/skills/postgres-hybrid-text-search
