Hey everyone! ๐
Like many Postgres & Supabase developers, I have always hated the architectural complexity of spinning up an external Elasticsearch, OpenSearch, or Algolia cluster just to get good hybrid search (keyword + semantic):
We built and open-sourced PolyVector to turn PostgreSQL into a standalone, enterprise-grade search engine with zero external clusters and zero API fees.
Instead of doing separate queries and slow application-side rank fusion (RRF), PolyVector compiles partial vector searches and length-normalized BM25 full-text search into a single parameterized SQL query:
WHERE field_name = 'title'), keeping indexes compact, cache-hot in RAM, and lightning-fast.ts_rank_cd(fts_doc, query, 32) to eliminate document length bias, matching Elasticsearch BM25 relevance.DISTINCT ON deduplication.bge-small-en-v1.5 384d). Zero third-party API keys, zero rate limits, data never leaves your VPC.Ammar introduces PolyVector, an open-source tool designed to enhance PostgreSQL with enterprise-grade search capabilities, eliminating the need for external search clusters like Elasticsearch. The tool offers faster search performance, reduced RAM usage, and no external API fees by integrating vector and full-text search directly within Postgres. Ammar invites feedback and experiences from the community regarding search workloads on Postgres.
We evaluated PolyVector against Elasticsearch 8.x Hybrid and native Postgres FTS on an un-cached catalog of 100,000 products:
| Metric | PostgreSQL Native FTS | Elasticsearch 8.x (Hybrid) | PolyVector (In-Engine Hybrid) | Advantage |
|---|---|---|---|---|
| Median Latency (p50) | 51.66 ms | 132.07 ms | 40.40 ms | 3.2ร faster than Elasticsearch |
| 95th Percentile (p95) | 67.95 ms | 316.85 ms | 82.29 ms | 3.8ร faster than Elasticsearch |
| RAM Consumed (Engine) | ~256 MB | 2.5 GB โ 4.0 GB (JVM) | ~350 MB | 85% less memory |
| Index Size on Disk | 4.75 MB | 767.01 MB | 298.87 MB | 61% smaller storage footprint |
| Infrastructure Stack | 1 Engine (PostgreSQL) | 2 Engines + Sync Pipeline | 1 Engine (PostgreSQL) | Zero sync lag, full ACID |
| NDCG@10 (Ranking Quality) | 0.6696 | 0.9696 | 0.9253 | Near-parity with ES |
| First Hit Accuracy (MRR) | 0.7143 | 1.0000 | 1.0000 | Perfect first-hit accuracy |
Both libraries have 100% feature parity:
npm install polyvector-search)import { PolyVectorIndex } from "polyvector-search";
import { Pool } from "pg";
const pool = new Pool({ connectionString: process.env.DATABASE_URL });
const index = new PolyVectorIndex({
table: "products",
idColumn: "id",
embeddingsTable: "product_embeddings",
fields: {
name: { weight: 0.50, type: "vector" },
description: { weight: 0.20, type: "vector" },
fts_doc: { weight: 0.30, type: "bm25" }
},
distinctOn: "name",
pool
});
// Setup schema & indexes once
await index.setup();
// Hybrid search
const results = await index.search("waterproof trail runner", {
filters: { price: { lte: 150.0 } },
limit: 10
});
console.log(`Executed in ${results.totalLatencyMs}ms`);
pip install polyvector-search)from polyvector import PolyVectorIndex, ConnectionPool
pool = ConnectionPool(config="postgresql://postgres:postgres@localhost:5432/my_database")
index = PolyVectorIndex(
table="products",
id_column="id",
embeddings_table="product_embeddings",
fields={
"name": {"weight": 0.50, "type": "vector"},
"description": {"weight": 0.20, "type": "vector"},
"fts_doc": {"weight": 0.30, "type": "bm25"}
},
distinct_on="name",
connection_pool=pool
)
results = index.search(query="waterproof trail runner", limit=10)
Would love to hear your thoughts, feedback, and what kind of search workloads you are running on Postgres!