pg_rrf
混合检索的倒数排序融合函数
概览
| 扩展包名 | 版本 | 分类 | 许可证 | 语言 |
|---|---|---|---|---|
pg_rrf | 0.0.3 | RAG | MIT | Rust |
| ID | 扩展名 | Bin | Lib | Load | Create | Trust | Reloc | 模式 |
|---|---|---|---|---|---|---|---|---|
| 1845 | pg_rrf | 否 | 是 | 否 | 是 | 否 | 否 | - |
manually upgraded PGRX from 0.16.1 to 0.17.0 by Vonng
版本
| 类型 | 仓库 | 版本 | PG 大版本 | 包名 | 依赖 |
|---|---|---|---|---|---|
| EXT | PIGSTY | 0.0.3 | 1817161514 | pg_rrf | - |
| RPM | PIGSTY | 0.0.3 | 1817161514 | pg_rrf_$v | - |
| DEB | PIGSTY | 0.0.3 | 1817161514 | postgresql-$v-pg-rrf | - |
| OS / PG | PG18 | PG17 | PG16 | PG15 | PG14 |
|---|---|---|---|---|---|
| el8.x86_64 | PIGSTY MISS | PIGSTY 0.0.3 el8.x86_64.pg17 : pg_rrf_17 pg_rrf_17-0.0.3-1PIGSTY.el8.x86_64.rpm
| PIGSTY 0.0.3 el8.x86_64.pg16 : pg_rrf_16 pg_rrf_16-0.0.3-1PIGSTY.el8.x86_64.rpm
| PIGSTY 0.0.3 el8.x86_64.pg15 : pg_rrf_15 pg_rrf_15-0.0.3-1PIGSTY.el8.x86_64.rpm
| PIGSTY 0.0.3 el8.x86_64.pg14 : pg_rrf_14 pg_rrf_14-0.0.3-1PIGSTY.el8.x86_64.rpm
|
| el8.aarch64 | PIGSTY MISS | PIGSTY 0.0.3 el8.aarch64.pg17 : pg_rrf_17 pg_rrf_17-0.0.3-1PIGSTY.el8.aarch64.rpm
| PIGSTY 0.0.3 el8.aarch64.pg16 : pg_rrf_16 pg_rrf_16-0.0.3-1PIGSTY.el8.aarch64.rpm
| PIGSTY 0.0.3 el8.aarch64.pg15 : pg_rrf_15 pg_rrf_15-0.0.3-1PIGSTY.el8.aarch64.rpm
| PIGSTY 0.0.3 el8.aarch64.pg14 : pg_rrf_14 pg_rrf_14-0.0.3-1PIGSTY.el8.aarch64.rpm
|
| el9.x86_64 | PIGSTY MISS | PIGSTY 0.0.3 el9.x86_64.pg17 : pg_rrf_17 pg_rrf_17-0.0.3-1PIGSTY.el9.x86_64.rpm
| PIGSTY 0.0.3 el9.x86_64.pg16 : pg_rrf_16 pg_rrf_16-0.0.3-1PIGSTY.el9.x86_64.rpm
| PIGSTY 0.0.3 el9.x86_64.pg15 : pg_rrf_15 pg_rrf_15-0.0.3-1PIGSTY.el9.x86_64.rpm
| PIGSTY 0.0.3 el9.x86_64.pg14 : pg_rrf_14 pg_rrf_14-0.0.3-1PIGSTY.el9.x86_64.rpm
|
| el9.aarch64 | PIGSTY MISS | PIGSTY 0.0.3 el9.aarch64.pg17 : pg_rrf_17 pg_rrf_17-0.0.3-1PIGSTY.el9.aarch64.rpm
| PIGSTY 0.0.3 el9.aarch64.pg16 : pg_rrf_16 pg_rrf_16-0.0.3-1PIGSTY.el9.aarch64.rpm
| PIGSTY 0.0.3 el9.aarch64.pg15 : pg_rrf_15 pg_rrf_15-0.0.3-1PIGSTY.el9.aarch64.rpm
| PIGSTY 0.0.3 el9.aarch64.pg14 : pg_rrf_14 pg_rrf_14-0.0.3-1PIGSTY.el9.aarch64.rpm
|
| el10.x86_64 | PIGSTY MISS | PIGSTY 0.0.3 el10.x86_64.pg17 : pg_rrf_17 pg_rrf_17-0.0.3-1PIGSTY.el10.x86_64.rpm
| PIGSTY 0.0.3 el10.x86_64.pg16 : pg_rrf_16 pg_rrf_16-0.0.3-1PIGSTY.el10.x86_64.rpm
| PIGSTY 0.0.3 el10.x86_64.pg15 : pg_rrf_15 pg_rrf_15-0.0.3-1PIGSTY.el10.x86_64.rpm
| PIGSTY 0.0.3 el10.x86_64.pg14 : pg_rrf_14 pg_rrf_14-0.0.3-1PIGSTY.el10.x86_64.rpm
|
| el10.aarch64 | PIGSTY MISS | PIGSTY 0.0.3 el10.aarch64.pg17 : pg_rrf_17 pg_rrf_17-0.0.3-1PIGSTY.el10.aarch64.rpm
| PIGSTY 0.0.3 el10.aarch64.pg16 : pg_rrf_16 pg_rrf_16-0.0.3-1PIGSTY.el10.aarch64.rpm
| PIGSTY 0.0.3 el10.aarch64.pg15 : pg_rrf_15 pg_rrf_15-0.0.3-1PIGSTY.el10.aarch64.rpm
| PIGSTY 0.0.3 el10.aarch64.pg14 : pg_rrf_14 pg_rrf_14-0.0.3-1PIGSTY.el10.aarch64.rpm
|
| d12.x86_64 | PIGSTY MISS | PIGSTY 0.0.3 d12.x86_64.pg17 : postgresql-17-pg-rrf postgresql-17-pg-rrf_0.0.3-1PIGSTY~bookworm_amd64.deb
| PIGSTY 0.0.3 d12.x86_64.pg16 : postgresql-16-pg-rrf postgresql-16-pg-rrf_0.0.3-1PIGSTY~bookworm_amd64.deb
| PIGSTY 0.0.3 d12.x86_64.pg15 : postgresql-15-pg-rrf postgresql-15-pg-rrf_0.0.3-1PIGSTY~bookworm_amd64.deb
| PIGSTY 0.0.3 d12.x86_64.pg14 : postgresql-14-pg-rrf postgresql-14-pg-rrf_0.0.3-1PIGSTY~bookworm_amd64.deb
|
| d12.aarch64 | PIGSTY MISS | PIGSTY 0.0.3 d12.aarch64.pg17 : postgresql-17-pg-rrf postgresql-17-pg-rrf_0.0.3-1PIGSTY~bookworm_arm64.deb
| PIGSTY 0.0.3 d12.aarch64.pg16 : postgresql-16-pg-rrf postgresql-16-pg-rrf_0.0.3-1PIGSTY~bookworm_arm64.deb
| PIGSTY 0.0.3 d12.aarch64.pg15 : postgresql-15-pg-rrf postgresql-15-pg-rrf_0.0.3-1PIGSTY~bookworm_arm64.deb
| PIGSTY 0.0.3 d12.aarch64.pg14 : postgresql-14-pg-rrf postgresql-14-pg-rrf_0.0.3-1PIGSTY~bookworm_arm64.deb
|
| d13.x86_64 | PIGSTY MISS | PIGSTY 0.0.3 d13.x86_64.pg17 : postgresql-17-pg-rrf postgresql-17-pg-rrf_0.0.3-1PIGSTY~trixie_amd64.deb
| PIGSTY 0.0.3 d13.x86_64.pg16 : postgresql-16-pg-rrf postgresql-16-pg-rrf_0.0.3-1PIGSTY~trixie_amd64.deb
| PIGSTY 0.0.3 d13.x86_64.pg15 : postgresql-15-pg-rrf postgresql-15-pg-rrf_0.0.3-1PIGSTY~trixie_amd64.deb
| PIGSTY 0.0.3 d13.x86_64.pg14 : postgresql-14-pg-rrf postgresql-14-pg-rrf_0.0.3-1PIGSTY~trixie_amd64.deb
|
| d13.aarch64 | PIGSTY MISS | PIGSTY 0.0.3 d13.aarch64.pg17 : postgresql-17-pg-rrf postgresql-17-pg-rrf_0.0.3-1PIGSTY~trixie_arm64.deb
| PIGSTY 0.0.3 d13.aarch64.pg16 : postgresql-16-pg-rrf postgresql-16-pg-rrf_0.0.3-1PIGSTY~trixie_arm64.deb
| PIGSTY 0.0.3 d13.aarch64.pg15 : postgresql-15-pg-rrf postgresql-15-pg-rrf_0.0.3-1PIGSTY~trixie_arm64.deb
| PIGSTY 0.0.3 d13.aarch64.pg14 : postgresql-14-pg-rrf postgresql-14-pg-rrf_0.0.3-1PIGSTY~trixie_arm64.deb
|
| u22.x86_64 | PIGSTY MISS | PIGSTY 0.0.3 u22.x86_64.pg17 : postgresql-17-pg-rrf postgresql-17-pg-rrf_0.0.3-1PIGSTY~jammy_amd64.deb
| PIGSTY 0.0.3 u22.x86_64.pg16 : postgresql-16-pg-rrf postgresql-16-pg-rrf_0.0.3-1PIGSTY~jammy_amd64.deb
| PIGSTY 0.0.3 u22.x86_64.pg15 : postgresql-15-pg-rrf postgresql-15-pg-rrf_0.0.3-1PIGSTY~jammy_amd64.deb
| PIGSTY 0.0.3 u22.x86_64.pg14 : postgresql-14-pg-rrf postgresql-14-pg-rrf_0.0.3-1PIGSTY~jammy_amd64.deb
|
| u22.aarch64 | PIGSTY MISS | PIGSTY 0.0.3 u22.aarch64.pg17 : postgresql-17-pg-rrf postgresql-17-pg-rrf_0.0.3-1PIGSTY~jammy_arm64.deb
| PIGSTY 0.0.3 u22.aarch64.pg16 : postgresql-16-pg-rrf postgresql-16-pg-rrf_0.0.3-1PIGSTY~jammy_arm64.deb
| PIGSTY 0.0.3 u22.aarch64.pg15 : postgresql-15-pg-rrf postgresql-15-pg-rrf_0.0.3-1PIGSTY~jammy_arm64.deb
| PIGSTY 0.0.3 u22.aarch64.pg14 : postgresql-14-pg-rrf postgresql-14-pg-rrf_0.0.3-1PIGSTY~jammy_arm64.deb
|
| u24.x86_64 | PIGSTY MISS | PIGSTY 0.0.3 u24.x86_64.pg17 : postgresql-17-pg-rrf postgresql-17-pg-rrf_0.0.3-1PIGSTY~noble_amd64.deb
| PIGSTY 0.0.3 u24.x86_64.pg16 : postgresql-16-pg-rrf postgresql-16-pg-rrf_0.0.3-1PIGSTY~noble_amd64.deb
| PIGSTY 0.0.3 u24.x86_64.pg15 : postgresql-15-pg-rrf postgresql-15-pg-rrf_0.0.3-1PIGSTY~noble_amd64.deb
| PIGSTY 0.0.3 u24.x86_64.pg14 : postgresql-14-pg-rrf postgresql-14-pg-rrf_0.0.3-1PIGSTY~noble_amd64.deb
|
| u24.aarch64 | PIGSTY MISS | PIGSTY 0.0.3 u24.aarch64.pg17 : postgresql-17-pg-rrf postgresql-17-pg-rrf_0.0.3-1PIGSTY~noble_arm64.deb
| PIGSTY 0.0.3 u24.aarch64.pg16 : postgresql-16-pg-rrf postgresql-16-pg-rrf_0.0.3-1PIGSTY~noble_arm64.deb
| PIGSTY 0.0.3 u24.aarch64.pg15 : postgresql-15-pg-rrf postgresql-15-pg-rrf_0.0.3-1PIGSTY~noble_arm64.deb
| PIGSTY 0.0.3 u24.aarch64.pg14 : postgresql-14-pg-rrf postgresql-14-pg-rrf_0.0.3-1PIGSTY~noble_arm64.deb
|
| u26.x86_64 | PIGSTY MISS | PIGSTY MISS | PIGSTY MISS | PIGSTY MISS | PIGSTY MISS |
| u26.aarch64 | PIGSTY MISS | PIGSTY MISS | PIGSTY MISS | PIGSTY MISS | PIGSTY MISS |
构建
您可以使用 pig build 命令构建 pg_rrf 扩展的 RPM / DEB 包:
pig build pkg pg_rrf # 构建 RPM / DEB 包
安装
您可以直接安装 pg_rrf 扩展包的预置二进制包,首先确保 PGDG 和 PIGSTY 仓库已经添加并启用:
pig repo add pgsql -u # 添加仓库并更新缓存
使用 pig 或者是 apt/yum/dnf 安装扩展:
pig install pg_rrf; # 当前活跃 PG 版本安装
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 pg_rrf;
用法
来源:README, v0.0.3 release
pg_rrf 提供用于混合检索分数融合的 Reciprocal Rank Fusion 函数。它的目标是把多个有序候选列表合并起来,而不需要手写 FULL OUTER JOIN / COALESCE 这类拼接逻辑。
核心函数
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)
v0.0.3 release 明确新增了 rrfn,同时保留 rrf 和 rrf3 作为兼容包装器。README 记录的分数行为也很直接:
- 缺失排名会被忽略
<= 0的排名会被忽略k <= 0会报错
示例
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;
混合检索模式
上游 README 把 rrf_fuse 作为手工融合查询的替代方案:
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;
说明
README 目标版本是 PostgreSQL 14-17,并记录了基于 Docker 的构建与测试流程。扩展接口刻意保持很小:核心是分数辅助函数,以及覆盖常见双列表混合检索场景的 rrf_fuse。