pg_rrf

pg_rrf

pg_rrf : Reciprocal rank fusion functions for hybrid search

Overview

ID Extension Package Version Category License Language
1845
pg_rrf
pg_rrf
0.0.3
RAG
MIT
Rust
Attribute Has Binary Has Library Need Load Has DDL Relocatable Trusted
--s-d--
No
Yes
No
Yes
no
no

manually upgraded PGRX from 0.16.1 to 0.17.0 by Vonng

Packages

Type Repo Version PG Major Compatibility Package Pattern Dependencies
EXT
PIGSTY
0.0.3
18
17
16
15
14
pg_rrf -
RPM
PIGSTY
0.0.3
18
17
16
15
14
pg_rrf_$v -
DEB
PIGSTY
0.0.3
18
17
16
15
14
postgresql-$v-pg-rrf -
Linux / PG PG18 PG17 PG16 PG15 PG14
el8.x86_64
MISS
PIGSTY 0.0.3
PIGSTY 0.0.3
PIGSTY 0.0.3
PIGSTY 0.0.3
el8.aarch64
MISS
PIGSTY 0.0.3
PIGSTY 0.0.3
PIGSTY 0.0.3
PIGSTY 0.0.3
el9.x86_64
MISS
PIGSTY 0.0.3
PIGSTY 0.0.3
PIGSTY 0.0.3
PIGSTY 0.0.3
el9.aarch64
MISS
PIGSTY 0.0.3
PIGSTY 0.0.3
PIGSTY 0.0.3
PIGSTY 0.0.3
el10.x86_64
MISS
PIGSTY 0.0.3
PIGSTY 0.0.3
PIGSTY 0.0.3
PIGSTY 0.0.3
el10.aarch64
MISS
PIGSTY 0.0.3
PIGSTY 0.0.3
PIGSTY 0.0.3
PIGSTY 0.0.3
d12.x86_64
MISS
PIGSTY 0.0.3
PIGSTY 0.0.3
PIGSTY 0.0.3
PIGSTY 0.0.3
d12.aarch64
MISS
PIGSTY 0.0.3
PIGSTY 0.0.3
PIGSTY 0.0.3
PIGSTY 0.0.3
d13.x86_64
MISS
PIGSTY 0.0.3
PIGSTY 0.0.3
PIGSTY 0.0.3
PIGSTY 0.0.3
d13.aarch64
MISS
PIGSTY 0.0.3
PIGSTY 0.0.3
PIGSTY 0.0.3
PIGSTY 0.0.3
u22.x86_64
MISS
PIGSTY 0.0.3
PIGSTY 0.0.3
PIGSTY 0.0.3
PIGSTY 0.0.3
u22.aarch64
MISS
PIGSTY 0.0.3
PIGSTY 0.0.3
PIGSTY 0.0.3
PIGSTY 0.0.3
u24.x86_64
MISS
PIGSTY 0.0.3
PIGSTY 0.0.3
PIGSTY 0.0.3
PIGSTY 0.0.3
u24.aarch64
MISS
PIGSTY 0.0.3
PIGSTY 0.0.3
PIGSTY 0.0.3
PIGSTY 0.0.3
Package Version OS ORG SIZE File URL
pg_rrf_17 0.0.3 el8.x86_64 pigsty 314.3 KiB pg_rrf_17-0.0.3-1PIGSTY.el8.x86_64.rpm
pg_rrf_17 0.0.3 el8.aarch64 pigsty 209.0 KiB pg_rrf_17-0.0.3-1PIGSTY.el8.aarch64.rpm
pg_rrf_17 0.0.3 el9.x86_64 pigsty 329.9 KiB pg_rrf_17-0.0.3-1PIGSTY.el9.x86_64.rpm
pg_rrf_17 0.0.3 el9.aarch64 pigsty 222.9 KiB pg_rrf_17-0.0.3-1PIGSTY.el9.aarch64.rpm
pg_rrf_17 0.0.3 el10.x86_64 pigsty 330.3 KiB pg_rrf_17-0.0.3-1PIGSTY.el10.x86_64.rpm
pg_rrf_17 0.0.3 el10.aarch64 pigsty 222.8 KiB pg_rrf_17-0.0.3-1PIGSTY.el10.aarch64.rpm
postgresql-17-pg-rrf 0.0.3 d12.x86_64 pigsty 256.8 KiB postgresql-17-pg-rrf_0.0.3-1PIGSTY~bookworm_amd64.deb
postgresql-17-pg-rrf 0.0.3 d12.aarch64 pigsty 159.8 KiB postgresql-17-pg-rrf_0.0.3-1PIGSTY~bookworm_arm64.deb
postgresql-17-pg-rrf 0.0.3 d13.x86_64 pigsty 256.5 KiB postgresql-17-pg-rrf_0.0.3-1PIGSTY~trixie_amd64.deb
postgresql-17-pg-rrf 0.0.3 d13.aarch64 pigsty 159.8 KiB postgresql-17-pg-rrf_0.0.3-1PIGSTY~trixie_arm64.deb
postgresql-17-pg-rrf 0.0.3 u22.x86_64 pigsty 290.2 KiB postgresql-17-pg-rrf_0.0.3-1PIGSTY~jammy_amd64.deb
postgresql-17-pg-rrf 0.0.3 u22.aarch64 pigsty 184.9 KiB postgresql-17-pg-rrf_0.0.3-1PIGSTY~jammy_arm64.deb
postgresql-17-pg-rrf 0.0.3 u24.x86_64 pigsty 287.8 KiB postgresql-17-pg-rrf_0.0.3-1PIGSTY~noble_amd64.deb
postgresql-17-pg-rrf 0.0.3 u24.aarch64 pigsty 183.7 KiB postgresql-17-pg-rrf_0.0.3-1PIGSTY~noble_arm64.deb
Package Version OS ORG SIZE File URL
pg_rrf_16 0.0.3 el8.x86_64 pigsty 314.4 KiB pg_rrf_16-0.0.3-1PIGSTY.el8.x86_64.rpm
pg_rrf_16 0.0.3 el8.aarch64 pigsty 208.9 KiB pg_rrf_16-0.0.3-1PIGSTY.el8.aarch64.rpm
pg_rrf_16 0.0.3 el9.x86_64 pigsty 329.8 KiB pg_rrf_16-0.0.3-1PIGSTY.el9.x86_64.rpm
pg_rrf_16 0.0.3 el9.aarch64 pigsty 223.0 KiB pg_rrf_16-0.0.3-1PIGSTY.el9.aarch64.rpm
pg_rrf_16 0.0.3 el10.x86_64 pigsty 330.4 KiB pg_rrf_16-0.0.3-1PIGSTY.el10.x86_64.rpm
pg_rrf_16 0.0.3 el10.aarch64 pigsty 222.9 KiB pg_rrf_16-0.0.3-1PIGSTY.el10.aarch64.rpm
postgresql-16-pg-rrf 0.0.3 d12.x86_64 pigsty 257.1 KiB postgresql-16-pg-rrf_0.0.3-1PIGSTY~bookworm_amd64.deb
postgresql-16-pg-rrf 0.0.3 d12.aarch64 pigsty 159.8 KiB postgresql-16-pg-rrf_0.0.3-1PIGSTY~bookworm_arm64.deb
postgresql-16-pg-rrf 0.0.3 d13.x86_64 pigsty 256.9 KiB postgresql-16-pg-rrf_0.0.3-1PIGSTY~trixie_amd64.deb
postgresql-16-pg-rrf 0.0.3 d13.aarch64 pigsty 159.8 KiB postgresql-16-pg-rrf_0.0.3-1PIGSTY~trixie_arm64.deb
postgresql-16-pg-rrf 0.0.3 u22.x86_64 pigsty 290.2 KiB postgresql-16-pg-rrf_0.0.3-1PIGSTY~jammy_amd64.deb
postgresql-16-pg-rrf 0.0.3 u22.aarch64 pigsty 184.7 KiB postgresql-16-pg-rrf_0.0.3-1PIGSTY~jammy_arm64.deb
postgresql-16-pg-rrf 0.0.3 u24.x86_64 pigsty 287.9 KiB postgresql-16-pg-rrf_0.0.3-1PIGSTY~noble_amd64.deb
postgresql-16-pg-rrf 0.0.3 u24.aarch64 pigsty 183.6 KiB postgresql-16-pg-rrf_0.0.3-1PIGSTY~noble_arm64.deb
Package Version OS ORG SIZE File URL
pg_rrf_15 0.0.3 el8.x86_64 pigsty 314.0 KiB pg_rrf_15-0.0.3-1PIGSTY.el8.x86_64.rpm
pg_rrf_15 0.0.3 el8.aarch64 pigsty 209.0 KiB pg_rrf_15-0.0.3-1PIGSTY.el8.aarch64.rpm
pg_rrf_15 0.0.3 el9.x86_64 pigsty 329.7 KiB pg_rrf_15-0.0.3-1PIGSTY.el9.x86_64.rpm
pg_rrf_15 0.0.3 el9.aarch64 pigsty 222.9 KiB pg_rrf_15-0.0.3-1PIGSTY.el9.aarch64.rpm
pg_rrf_15 0.0.3 el10.x86_64 pigsty 330.2 KiB pg_rrf_15-0.0.3-1PIGSTY.el10.x86_64.rpm
pg_rrf_15 0.0.3 el10.aarch64 pigsty 222.9 KiB pg_rrf_15-0.0.3-1PIGSTY.el10.aarch64.rpm
postgresql-15-pg-rrf 0.0.3 d12.x86_64 pigsty 256.8 KiB postgresql-15-pg-rrf_0.0.3-1PIGSTY~bookworm_amd64.deb
postgresql-15-pg-rrf 0.0.3 d12.aarch64 pigsty 159.8 KiB postgresql-15-pg-rrf_0.0.3-1PIGSTY~bookworm_arm64.deb
postgresql-15-pg-rrf 0.0.3 d13.x86_64 pigsty 256.8 KiB postgresql-15-pg-rrf_0.0.3-1PIGSTY~trixie_amd64.deb
postgresql-15-pg-rrf 0.0.3 d13.aarch64 pigsty 159.9 KiB postgresql-15-pg-rrf_0.0.3-1PIGSTY~trixie_arm64.deb
postgresql-15-pg-rrf 0.0.3 u22.x86_64 pigsty 290.0 KiB postgresql-15-pg-rrf_0.0.3-1PIGSTY~jammy_amd64.deb
postgresql-15-pg-rrf 0.0.3 u22.aarch64 pigsty 184.7 KiB postgresql-15-pg-rrf_0.0.3-1PIGSTY~jammy_arm64.deb
postgresql-15-pg-rrf 0.0.3 u24.x86_64 pigsty 287.7 KiB postgresql-15-pg-rrf_0.0.3-1PIGSTY~noble_amd64.deb
postgresql-15-pg-rrf 0.0.3 u24.aarch64 pigsty 183.7 KiB postgresql-15-pg-rrf_0.0.3-1PIGSTY~noble_arm64.deb
Package Version OS ORG SIZE File URL
pg_rrf_14 0.0.3 el8.x86_64 pigsty 314.1 KiB pg_rrf_14-0.0.3-1PIGSTY.el8.x86_64.rpm
pg_rrf_14 0.0.3 el8.aarch64 pigsty 209.0 KiB pg_rrf_14-0.0.3-1PIGSTY.el8.aarch64.rpm
pg_rrf_14 0.0.3 el9.x86_64 pigsty 329.8 KiB pg_rrf_14-0.0.3-1PIGSTY.el9.x86_64.rpm
pg_rrf_14 0.0.3 el9.aarch64 pigsty 223.1 KiB pg_rrf_14-0.0.3-1PIGSTY.el9.aarch64.rpm
pg_rrf_14 0.0.3 el10.x86_64 pigsty 330.0 KiB pg_rrf_14-0.0.3-1PIGSTY.el10.x86_64.rpm
pg_rrf_14 0.0.3 el10.aarch64 pigsty 223.0 KiB pg_rrf_14-0.0.3-1PIGSTY.el10.aarch64.rpm
postgresql-14-pg-rrf 0.0.3 d12.x86_64 pigsty 256.6 KiB postgresql-14-pg-rrf_0.0.3-1PIGSTY~bookworm_amd64.deb
postgresql-14-pg-rrf 0.0.3 d12.aarch64 pigsty 159.8 KiB postgresql-14-pg-rrf_0.0.3-1PIGSTY~bookworm_arm64.deb
postgresql-14-pg-rrf 0.0.3 d13.x86_64 pigsty 256.8 KiB postgresql-14-pg-rrf_0.0.3-1PIGSTY~trixie_amd64.deb
postgresql-14-pg-rrf 0.0.3 d13.aarch64 pigsty 159.9 KiB postgresql-14-pg-rrf_0.0.3-1PIGSTY~trixie_arm64.deb
postgresql-14-pg-rrf 0.0.3 u22.x86_64 pigsty 289.8 KiB postgresql-14-pg-rrf_0.0.3-1PIGSTY~jammy_amd64.deb
postgresql-14-pg-rrf 0.0.3 u22.aarch64 pigsty 184.7 KiB postgresql-14-pg-rrf_0.0.3-1PIGSTY~jammy_arm64.deb
postgresql-14-pg-rrf 0.0.3 u24.x86_64 pigsty 287.4 KiB postgresql-14-pg-rrf_0.0.3-1PIGSTY~noble_amd64.deb
postgresql-14-pg-rrf 0.0.3 u24.aarch64 pigsty 183.6 KiB postgresql-14-pg-rrf_0.0.3-1PIGSTY~noble_arm64.deb

Source

pig build pkg pg_rrf;		# build rpm/deb

Install

Make sure PGDG and PIGSTY repo available:

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

Install this extension with pig:

pig install pg_rrf;		# install via package name, for the active PG version

pig install pg_rrf -v 17;   # install for PG 17
pig install pg_rrf -v 16;   # install for PG 16
pig install pg_rrf -v 15;   # install for PG 15
pig install pg_rrf -v 14;   # install for PG 14

Create this extension with:

CREATE EXTENSION pg_rrf;

Usage

Sources: README and project repo.

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 README also documents the behavior of the score helpers:

  • 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;

Requirements

  • PostgreSQL 14-17
  • Docker and Docker Compose v2

The README says the build and test flow runs in Docker, so local PostgreSQL and Rust toolchains are not required for the package workflow.

Last updated on