timescale avatar

Postgres Hybrid Text Search

This combines PostgreSQL's BM25 keyword search with pgvector semantic search using Reciprocal Rank Fusion to merge results. You run two queries in parallel (one for exact term matching, one for meaning), then fuse them client-side in Python or TypeScript. It's the right move when your users mix specific terms like product codes with conceptual queries, though it adds complexity over single-method search. The guide uses pg_textsearch for true BM25 ranking, which is currently in prerelease. Includes weighting strategies if you want to favor one method over the other, plus optional ML reranking with cross-encoders for the final candidate set.

skills.sh installs
391
GitHub stars
1.9K
last updated
Aug 21, 2026

Install

$ npx -y skills add timescale/pg-aiguide --skill postgres-hybrid-text-search --agent claude-code

Installs into .claude/skills of the current project.

Files

Hybrid Text Search

Hybrid search combines keyword search (BM25) with semantic search (vector embeddings) to get the best of both: exact keyword matching and meaning-based retrieval. Use Reciprocal Rank Fusion (RRF) to merge results from both methods into a single ranked list.

This guide covers combining pg_textsearch (BM25) with pgvector. Requires both extensions. For high-volume setups, filtering, or advanced pgvector tuning (binary quantization, HNSW parameters), see the pgvector-semantic-search skill.

pg_textsearch is a new BM25 text search extension for PostgreSQL, fully open-source and available hosted on Tiger Cloud as well as for self-managed deployments. It provides true BM25 ranking, which often improves relevance compared to PostgreSQL's built-in ts_rank and can offer better performance at scale. Note: pg_textsearch is currently in prerelease and not yet recommended for production use. pg_textsearch currently supports PostgreSQL 17 and 18.

When to Use Hybrid Search

Sponsors

Details

Repository
github.com/timescale/pg-aiguide
Categories
DevOps & CI/CD, AI & Agent Building, Data Science & ML, Automation & Workflows, Python, Marketing & SEO, Databases
License
Apache-2.0
First seen
Jun 3, 2026

More from timescale/pg-aiguide

All 8
1alirezarezvani avatarbriefalirezarezvani/claude-skills/cs:brief <topic> — Generate a one-page strategy brief from an office-hours intake. First step in the strategic sprint pipeline. Use when a strategic question n390skills.sh installs
2jwynia avatarlist-builderjwynia/agent-skillsBuild comprehensive randomization lists for creative entropy. Use when you need to create or expand lists of story elements (professions, locations, objects, na390skills.sh installs
3comet-ml avatarinstrumentcomet-ml/opik-skillsAdd Opik tracing to an existing codebase. Detects language (Python/TypeScript), identifies LLM frameworks, adds appropriate decorators and integrations, marks e389skills.sh installs
4secondsky avatarcloudflare-agentssecondsky/claude-skillsBuild AI agents on Cloudflare Workers with MCP integration, tool use, and LLM providers.389skills.sh installs
5secondsky avatarcloudflare-mcp-serversecondsky/claude-skillsBuild MCP (Model Context Protocol) servers on Cloudflare Workers with tools, resources, and prompts.388skills.sh installs
6ancoleman avatarcreating-dashboardsancoleman/ai-design-componentsCreates comprehensive dashboard and analytics interfaces that combine data visualization, KPI cards, real-time updates, and interactive layouts. Use this skill 387skills.sh installs