0
Challenge · 75Services

Search: full-text, pgvector & hybrid (RRF)

AIused in ~55% of apps

"postgres tip" should find a post titled "Tips for indexing Postgres," and "why is my database slow" should find that same post even though it never uses the word "slow." The first is full-text search — matching words. The second is semantic search — matching meaning, via pgvector. DevLog needs both, and the two are combined with a technique called RRF that doesn't compare their scores at all — because a tsvector rank and a cosine distance aren't even the same unit.

Core idea. Full-text search tokenizes text into a `tsvector`, indexes it with GIN, and matches with `@@`; it is fast, exact-on-words, and free. Semantic search embeds text into a vector and finds nearby vectors with an ANN index (HNSW); it understands meaning but needs a model and, like any RPC, must default to `SECURITY INVOKER` or it silently bypasses RLS. Hybrid search fuses the two rankings with Reciprocal Rank Fusion (RRF) — summing `1/(k + rank)` from each list — because ranks, unlike raw scores, are always comparable.
Playground, this isn't a screenshot
query: "postgres tips" · rrf_k
documentFTS #vector #RRF score
1PostgreSQL performance tuning checklist330.0377
2Why Postgres feels slow, and how to fix it610.0375
3Tips for indexing Postgres for speed190.0366
4A guide to cooking pasta12120.0323
score(doc) = 1/(k + fts_rank) + 1/(k + vector_rank)

At k = 1, a #1 finish on either signal dominates the sum — "Why Postgres feels slow" wins on the strength of its #1 vector rank alone, even though it barely matches the literal words. At k = 50 the gaps between 1/(51), 1/(56), 1/(59)… are all tiny, so a document that is merely solidly good on both signals(rank 3 + rank 3) overtakes documents that are brilliant on one signal and weak on the other. That smoothing — not chasing a single spiky #1 — is why Supabase's default is rrf_k = 50, not 1.

↑ play a little first, then dig in