Why vector similarity alone fails on enterprise data
Embeddings capture semantic meaning, not exact tokens. When a customer searches for invoice #INV-4092 or a specific medical code, cosine similarity often ranks conceptually similar documents higher than the exact match.
Running full-text search and pgvector HNSW search side by side inside PostgreSQL—and merging both ranked lists with Reciprocal Rank Fusion—gives you exact keyword precision plus semantic recall in a single ACID database.
WITH semantic AS (
SELECT id, ROW_NUMBER() OVER (ORDER BY embedding <=> $1) AS rank
FROM documents WHERE workspace_id = $2 LIMIT 40
),
keyword AS (
SELECT id, ROW_NUMBER() OVER (ORDER BY ts_rank_cd(tsv, plainto_tsquery($3)) DESC) AS rank
FROM documents WHERE workspace_id = $2 AND tsv @@ plainto_tsquery($3) LIMIT 40
)
SELECT COALESCE(s.id, k.id) AS id,
COALESCE(1.0 / (60 + s.rank), 0.0) + COALESCE(1.0 / (60 + k.rank), 0.0) AS rrf_score
FROM semantic s FULL OUTER JOIN keyword k ON s.id = k.id
ORDER BY rrf_score DESC LIMIT 8;