The Failure Mode of Pure Semantic Search

When users search for exact part numbers, invoice identifiers, or medical codes (e.g. "INV-2026-881B"), pure vector embeddings often return generic invoices because high-dimensional vectors prioritize contextual concepts over exact token parity.

Building Hybrid Search Inside PostgreSQL

PostgreSQL 16+ paired with the pgvector extension and native full-text search (TSVector) provides an enterprise-grade hybrid retrieval engine without requiring separate Elasticsearch clusters.

-- Creating the Hybrid Knowledge Schema
CREATE EXTENSION IF NOT EXISTS vector;

CREATE TABLE knowledge_base (
    id BIGSERIAL PRIMARY KEY,
    document_id VARCHAR(64) NOT NULL,
    chunk_content TEXT NOT NULL,
    tsv_content TSVECTOR GENERATED ALWAYS AS (to_tsvector('english', chunk_content)) STORED,
    embedding VECTOR(1536)
);

CREATE INDEX idx_kb_vector ON knowledge_base USING ivfflat (embedding vector_cosine_ops) WITH (lists = 100);
CREATE INDEX idx_kb_tsv ON knowledge_base USING gin (tsv_content);

Reciprocal Rank Fusion (RRF)

Rather than simple linear weighting, modern search pipelines employ Reciprocal Rank Fusion to normalize scores across lexical and semantic candidate sets:

RRF_Score = 1 / (60 + rank_dense) + 1 / (60 + rank_sparse)

Key Takeaways

  • Hybrid search delivers up to 34% higher Recall@5 than pure vector embeddings alone.
  • Running hybrid retrieval directly inside PostgreSQL simplifies infrastructure and guarantees ACID transactional consistency.