CtrlK
BlogDocsLog inGet started
Tessl Logo

g14wxz/hybrid-search-rrf-pattern

Fuses semantic vector search with lexical full-text search using Reciprocal Rank Fusion in a PL/pgSQL RPC.

100

Quality

100%

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

SecuritybySnyk

Passed

No known issues

Overview
Quality
Evals
Security
Files

Hybrid Search RRF Pattern

Fuses semantic vector search with lexical full-text search using Reciprocal Rank Fusion in a PL/pgSQL RPC.

Overview

This tile produces a single PL/pgSQL RPC that combines pgvector cosine-distance results with PostgreSQL tsvector full-text results. Reciprocal Rank Fusion (RRF) merges the two ranked lists into one unified score using the formula score = 1/(k + rank), where k defaults to 60. The fused score surfaces rows that rank well in either or both retrieval methods.

Reference

RRF Formula

semantic_score  = 1.0 / (k + semantic_rank)
fulltext_score  = 1.0 / (k + fulltext_rank)
combined_score  = semantic_score + fulltext_score

Required Extensions

ExtensionPurpose
vectorpgvector cosine similarity

Required Indexes

TypeColumnIndex Kind
VectorembeddingHNSW
TextftsGIN

RPC Signature

hybrid_search(
  query_embedding vector,
  query_text      text,
  match_count     int DEFAULT 20,
  k               int DEFAULT 60
) RETURNS TABLE (id, combined_score, semantic_score, fulltext_score)

Dependencies

  • pgvector-hnsw-index-selection — MUST be installed to guarantee correct HNSW index configuration before this tile operates.

Incompatibilities

  • supabase/ivfflat-index — IVFFlat indexes on the same column conflict with the HNSW requirement. NEVER install both on the same vector column.

Composition Position

This tile executes after pgvector-hnsw-index-selection has confirmed the HNSW index exists. It produces a callable RPC that downstream tiles or application code invoke for search. It does not manage index creation itself.

Workspace
g14wxz
Visibility
Public
Created
Last updated
Publish Source
CLI
Badge
g14wxz/hybrid-search-rrf-pattern badge