pg_rrf

Reciprocal rank fusion functions for hybrid search

Overview

PackageVersionCategoryLicenseLanguage
pg_rrf0.0.3RAGMITRust
IDExtensionBinLibLoadCreateTrustRelocSchema
1845pg_rrfNoYesNoYesNoNo-

manually upgraded PGRX from 0.16.1 to 0.17.0 by Vonng

Version

TypeRepoVersionPG VerPackageDeps
EXTPIGSTY0.0.31817161514pg_rrf-
RPMPIGSTY0.0.31817161514pg_rrf_$v-
DEBPIGSTY0.0.31817161514postgresql-$v-pg-rrf-
OS / PGPG18PG17PG16PG15PG14
el8.x86_64PIGSTY MISS
el8.aarch64PIGSTY MISS
el9.x86_64PIGSTY MISS
el9.aarch64PIGSTY MISS
el10.x86_64PIGSTY MISS
el10.aarch64PIGSTY MISS
d12.x86_64PIGSTY MISS
d12.aarch64PIGSTY MISS
d13.x86_64PIGSTY MISS
d13.aarch64PIGSTY MISS
u22.x86_64PIGSTY MISS
u22.aarch64PIGSTY MISS
PIGSTY 0.0.3
PIGSTY 0.0.3
PIGSTY 0.0.3
PIGSTY 0.0.3
u24.x86_64PIGSTY MISS
u24.aarch64PIGSTY MISS
PIGSTY 0.0.3
PIGSTY 0.0.3
PIGSTY 0.0.3
PIGSTY 0.0.3

Build

You can build the RPM / DEB packages for pg_rrf using pig build:

pig build pkg pg_rrf         # build RPM / DEB packages

Install

You can install pg_rrf directly. First, make sure the PGDG and PIGSTY repositories are added and enabled:

pig repo add pgsql -u          # Add repo and update cache

Install the extension using pig or apt/yum/dnf:

pig install pg_rrf;          # Install for current active PG version
pig ext install -y pg_rrf -v 17  # PG 17
pig ext install -y pg_rrf -v 16  # PG 16
pig ext install -y pg_rrf -v 15  # PG 15
pig ext install -y pg_rrf -v 14  # PG 14
dnf install -y pg_rrf_17       # PG 17
dnf install -y pg_rrf_16       # PG 16
dnf install -y pg_rrf_15       # PG 15
dnf install -y pg_rrf_14       # PG 14
apt install -y postgresql-17-pg-rrf   # PG 17
apt install -y postgresql-16-pg-rrf   # PG 16
apt install -y postgresql-15-pg-rrf   # PG 15
apt install -y postgresql-14-pg-rrf   # PG 14

Create Extension:

CREATE EXTENSION pg_rrf;

Usage

Sources: README, v0.0.3 release

pg_rrf provides Reciprocal Rank Fusion functions for hybrid search score fusion. It is focused on combining ranked candidate lists without hand-written FULL OUTER JOIN / COALESCE plumbing.

Core Functions

  • rrf(rank_a, rank_b, k)
  • rrf3(rank_a, rank_b, rank_c, k)
  • rrf_fuse(ids_a bigint[], ids_b bigint[], k int default 60)
  • rrfn(ranks bigint[], k int)

The v0.0.3 release explicitly adds rrfn while keeping rrf and rrf3 as compatibility wrappers. The README documents the same score behavior:

  • missing ranks are ignored
  • ranks <= 0 are ignored
  • k <= 0 raises an error

Example

CREATE EXTENSION pg_rrf;

SELECT rrf(1, 2, 60) AS rrf_12;
SELECT rrf3(1, 2, 3, 60) AS rrf_123;
SELECT rrfn(ARRAY[1, 2, 3], 60) AS rrfn_123;
SELECT *
FROM rrf_fuse(ARRAY[10, 20, 30], ARRAY[20, 40], 60)
ORDER BY score DESC;

Hybrid Search Pattern

The upstream README shows rrf_fuse as a replacement for a manual fusion query:

WITH fused AS (
  SELECT *
  FROM rrf_fuse(
    ARRAY(SELECT id FROM docs ORDER BY bm25_score DESC LIMIT 100),
    ARRAY(SELECT id FROM docs ORDER BY embedding <=> :qvec LIMIT 100),
    60
  )
)
SELECT d.*, fused.score
FROM fused
JOIN docs d USING (id)
ORDER BY fused.score DESC
LIMIT 20;

Notes

The README targets PostgreSQL 14-17 and documents Docker-based build and test flows. The extension surface remains intentionally small: score helpers plus rrf_fuse for the common two-list hybrid-search pattern.


Last Modified 2026-04-19: update extension stub docs (9f178c3)