跳到主要内容

向量索引基准测试(Local File)

本文档是 Local File(本地文件系统) 版本,覆盖构建与索引检索。 本轮只测试构建和索引检索,不测试 upsert/增量维护。MinIO 版本见 MinIO 版本。

1. 结论摘要​

四个标准 ANN 数据集在 RaBitQ bits=7 下都能达到 recall@100 ≥ 0.97,代价是需要更大的 nprobe。 主要权衡是 bits=7 与 bits=1、缓存大小(尤其 exact 重排)以及接口。

数据集配置recallindex 单查 QPSindex batch QPS
SIFT-128nlist=256, bits=7, nprobe=640.970379.44128.9
GloVe-200nlist=1024, bits=7, nprobe=4480.971178.21294.3
GIST-960nlist=256, bits=7, nprobe=320.974157.71709.2
Deep-Image-96nlist=1024, bits=7, nprobe=320.97122.9121.7

2. 测试方法​

项目取值
存储本地 file store(不是 MinIO/S3)
索引IVF + RaBitQ,hash_bucket_num=4
top_k100
recall对 HDF5 ground truth 的 recall@100
RSS构建/查询进程 VmRSS;pgvector 另列服务端 RSS
构建独立 build 进程,不含写表阶段峰值
清理每个数据集测完 drop 表、删除本地 index/cache
数据集BaseQueryGTdim距离
SIFT-1281,000,00010,000100-NN128L2
GloVe-2001,183,51410,000100-NN200cosine
GIST-9601,000,0001,000100-NN960L2
Deep-Image-969,990,00010,000100-NN96cosine

缓存/接口表中每格格式为 单查 QPS / 平均 ms / RSS MB / recall。 单查 QPS 是去掉首次查询后的稳定值;batch QPS 是两轮平均。

NQ 的定义:NQ 是每次测量使用的 query 向量数(测试集前 NQ 条), recall 是这些 query 的 top-100 平均,QPS = NQ / 耗时。 NQ 不是并发数,也不是 batch size;本轮 SIFT/GIST/Deep 用 NQ=10, GloVe 用 NQ=20,NQ 越大越稳定但越慢。

机器与实测资源​

项目取值
CPUIntel General Purpose Processor(KVM 虚拟 CPU),1 socket,8 物理核,2 threads/core,16 逻辑 CPU
指令集AVX2、AVX-512(含 AVX-512 VNNI/BF16)
内存60 GiB,无 swap
cgroup 限制未设置 CPU/内存上限
测试存储MinIO 为本机容器;L2 cache 在本地 SSD
并发配置hash_bucket_num=4;native batch parallelism=1;pgvector --worker-threads 4
构建实测SIFT MinIO:平均 237% CPU ≈ 2.4 逻辑核,峰值 RSS 485 MB
查询实测SIFT MinIO index-only,NQ=10:平均 349% CPU ≈ 3.5 逻辑核,峰值 RSS 397 MB

说明:

  • 构建/查询进程没有绑定固定 CPU 核;上面的“用了多少核”是 /usr/bin/time -v 的平均 CPU 百分比换算的逻辑核数,不是 cgroup 配额。
  • 构建尝试使用 hash_bucket_num=4 的 shard 并行;CARGO_BUILD_JOBS=8 只影响编译过程,不影响基准运行时的 CPU 使用。
  • 单查大约使用 3–4 个逻辑核;native batch 的 bucket 线程为 4, merge 线程数取 min(NQ, 可用核数),所以短 batch 的实测平均约 3.5 核。
  • build RSS 范围约 0.5–1.45 GB;query RSS 范围约 0.3–2.2 GB; 机器总内存 60 GiB。

3. 构建​

数据集nlistbitsbuild sbuild RSS MB写表 s
SIFT-12825613.64813.0
SIFT-12825674.15423.0
SIFT-128102416.23253.0
SIFT-128102477.23853.0
GloVe-20025618.37037.8
GloVe-20025679.37677.8
GloVe-2001024113.66857.8
GloVe-2001024714.07637.8
GloVe-2002048724.37707.8
GIST-960256134.179130.1
GIST-960256737.1107730.1
GIST-9601024151.263830.1
GIST-9601024754.280430.1
Deep-Image-961024193.9120731.4
Deep-Image-961024797.1144231.4
Deep-Image-9640961136.4103831.4
Deep-Image-9640967138.5120731.4

构建 RSS 为独立 build 进程。GloVe/Deep 使用逐行归一化向量;SIFT/GIST 使用原始 L2 向量。

build s 的口径:从 build_table_index 调用开始计时,包含读取表数据、 KMeans/量化、index segment 写入和 PG index commit/lease; 不包含前面的 write_arrow 写表时间;写表时间单列为 写表 s。

4. 检索质量与吞吐​

bits=1 体积小,但在这些 nprobe 下达不到 0.97 recall。 bits=7 需要更大的 nprobe 才能达到 0.97。完整扫描见附录 A。

目标配置​

数据集配置recallindex 单查index batchexact 单查exact batch
SIFT-128nlist=256, bits=7, nprobe=640.970379.44128.950.12307.1
GloVe-200nlist=1024, bits=7, nprobe=4480.971178.21294.323.6915.3
GIST-960nlist=256, bits=7, nprobe=320.974157.71709.213.41019.1
Deep-Image-96nlist=1024, bits=7, nprobe=320.97122.9121.78.6138.9

SIFT:nlist=256,bits=7,nprobe=64;GloVe:nlist=1024,bits=7,nprobe=448; GIST:nlist=256,bits=7,nprobe=32;Deep:nlist=1024,bits=7,nprobe=32。 所有配置的 nprobe 都是从 8 开始从小到大扫描;GloVe 在 nprobe=448 首次达到 0.97。

5. 缓存大小​

格式:单查 QPS / 平均 ms / RSS MB / recall;batch 同。 四个数据集均使用上面的目标配置。

SIFT-128​

cacheindex 单查index batchexact 单查exact batch
512m332.1 / 3.01 / 381 / 0.9704201.3 / 0.24 / 383 / 0.97043.0 / 23.24 / 731 / 1.000148.3 / 6.74 / 1059 / 1.000
1g326.4 / 3.06 / 381 / 0.9704232.3 / 0.24 / 383 / 0.97046.4 / 21.57 / 818 / 1.000223.1 / 4.48 / 1188 / 1.000
8g379.4 / 2.64 / 380 / 0.9704128.9 / 0.24 / 382 / 0.97050.1 / 19.98 / 887 / 1.0002307.1 / 0.43 / 890 / 1.000
off5.4 / 185.91 / 381 / 0.970106.6 / 9.38 / 383 / 0.970——

GloVe-200​

cacheindex 单查index batchexact 单查exact batch
512m87.5 / 11.43 / 651 / 0.9711304.9 / 0.77 / 653 / 0.97115.1 / 66.28 / 1019 / 0.98828.0 / 35.72 / 1348 / 0.988
1g156.6 / 6.39 / 558 / 0.9711276.7 / 0.78 / 559 / 0.97122.7 / 44.14 / 1100 / 0.988139.1 / 7.19 / 1429 / 0.988
8g178.2 / 5.61 / 558 / 0.9711294.3 / 0.77 / 559 / 0.97123.6 / 42.32 / 1424 / 0.988915.3 / 1.09 / 1427 / 0.988

GIST-960​

cacheindex 单查index batchexact 单查exact batch
512m75.5 / 13.25 / 1117 / 0.9741732.8 / 0.58 / 1118 / 0.9745.2 / 190.49 / 1686 / 0.99013.7 / 73.12 / 1950 / 0.990
1g160.3 / 6.24 / 1115 / 0.9741762.8 / 0.57 / 1117 / 0.9746.7 / 148.45 / 1890 / 0.99058.9 / 16.97 / 2154 / 0.990
8g157.7 / 6.34 / 1113 / 0.9741709.2 / 0.59 / 1115 / 0.97413.4 / 74.68 / 1990 / 0.9901019.1 / 0.98 / 1993 / 0.990
off3.1 / 327.81 / 1128 / 0.97431.2 / 32.04 / 1132 / 0.974——

Deep-Image-96​

cacheindex 单查index batchexact 单查exact batch
512m20.9 / 47.77 / 967 / 0.97122.8 / 43.85 / 1722 / 0.9718.5 / 118.06 / 1300 / 0.9897.1 / 141.38 / 1991 / 0.989
1g21.0 / 47.56 / 1064 / 0.971127.8 / 7.82 / 1095 / 0.9719.0 / 111.68 / 1556 / 0.98963.3 / 15.79 / 1858 / 0.989
8g22.9 / 43.72 / 1042 / 0.971121.7 / 8.22 / 1052 / 0.9718.6 / 115.94 / 1870 / 0.989138.9 / 7.20 / 1987 / 0.989
off21.9 / 45.57 / 540 / 0.97129.9 / 33.45 / 623 / 0.971——

观察:

  • index-only 对缓存大小不敏感,512MiB 主要增加延迟;
  • exact 重排受 block cache 影响很大:512MiB → 1GiB → 8GiB,batch 提升明显 (SIFT 148 → 223 → 2307 QPS;GIST 14 → 59 → 1019;Deep 7.1 → 63 → 139);
  • 完全关闭缓存时 index-only 仍可工作;exact 单查走 fallback。 native exact batch 现在也可以无缓存回退到普通 reader:SIFT nprobe=64、NQ=5 时 exact batch 约 15.7 QPS、recall 1.0(实现见 pk_locator 的临时 key-index 分支)。

6. 接口​

目标配置,cache 8GiB;格式 单查 QPS / 平均 ms / RSS MB / recall。 DataFusion 的 batch 是 SQL 循环;Python batch 是 native batch 入口。

SIFT-128​

接口rerank单查batch服务端 RSS MB
pythonindex379.4 / 2.64 / 380 / 0.9704128.9 / 0.24 / 382 / 0.970—
pythonexact50.1 / 19.98 / 887 / 1.0002307.1 / 0.43 / 890 / 1.000—
datafusionindex450.7 / 2.22 / 381 / 0.970478.6 / 2.09 / 381 / 0.970—
datafusionexact49.9 / 20.06 / 874 / 1.000396.8 / 2.52 / 874 / 1.000—
pgvectorindex390.6 / 2.56 / 64 / 0.970440.2 / 2.27 / 65 / 0.970304
pgvectorexact100.0 / 10.00 / 64 / 1.000189.6 / 5.27 / 65 / 1.000853

GloVe-200​

接口rerank单查batch服务端 RSS MB
pythonindex178.2 / 5.61 / 558 / 0.9711294.3 / 0.77 / 559 / 0.971—
pythonexact23.6 / 42.32 / 1424 / 0.988915.3 / 1.09 / 1427 / 0.988—
datafusionindex187.8 / 5.32 / 557 / 0.971214.3 / 4.67 / 557 / 0.971—
datafusionexact24.9 / 40.14 / 1416 / 0.988203.2 / 4.92 / 1416 / 0.988—
pgvectorindex196.0 / 5.10 / 68 / 0.971220.1 / 4.54 / 68 / 0.971476
pgvectorexact44.0 / 22.74 / 68 / 0.98899.7 / 10.03 / 68 / 0.9881463

GIST-960​

接口rerank单查batch服务端 RSS MB
pythonindex157.7 / 6.34 / 1113 / 0.9741709.2 / 0.59 / 1115 / 0.974—
pythonexact13.4 / 74.68 / 1990 / 0.9901019.1 / 0.98 / 1993 / 0.990—
datafusionindex170.9 / 5.85 / 1114 / 0.974182.8 / 5.47 / 1115 / 0.974—
datafusionexact13.6 / 73.80 / 1990 / 0.990159.9 / 6.26 / 1992 / 0.990—
pgvectorindex190.5 / 5.25 / 60 / 0.974217.6 / 4.60 / 60 / 0.9741046
pgvectorexact4.1 / 243.59 / 60 / 0.99033.6 / 29.73 / 60 / 0.9903949

Deep-Image-96​

接口rerank单查batch服务端 RSS MB
pythonindex22.9 / 43.72 / 1042 / 0.971121.7 / 8.22 / 1052 / 0.971—
pythonexact8.6 / 115.94 / 1870 / 0.989138.9 / 7.20 / 1987 / 0.989—
datafusionindex21.7 / 46.04 / 1053 / 0.97196.6 / 10.36 / 1125 / 0.971—
datafusionexact8.4 / 119.75 / 1890 / 0.98988.8 / 11.26 / 2200 / 0.989—
pgvectorindex22.3 / 44.81 / 63 / 0.97194.0 / 10.64 / 63 / 0.971902
pgvectorexact4.2 / 238.81 / 63 / 0.98911.9 / 84.30 / 63 / 0.9893825

pgvector 是独立服务进程(postgres-lakesoul,4 worker threads)。 Python/DataFusion 在查询进程内。pgvector exact 重排需要明显更多服务端内存, GIST 约 3.9GB、Deep 约 3.8GB。

7. 并行度与 bucket 数​

SIFT,目标配置,Python native,cache 8GiB,NQ=20:

parallelismindex 单查 QPSindex batch QPS
1378.64301.7
2325.42643.1
4379.43190.7

native batch 已经按 bucket 并行探测;短 batch 再增加 parallelism 会超订阅。 建议让 hash_bucket_num × vector_search.parallelism 接近 CPU 核数。

8. 选型建议​

目标建议
recall/QPS 平衡bits=7,nprobe 取 0.97 拐点,见目标表
最小内存512MiB 缓存:index-only 可用,exact 很慢
exact 重排8GiB L1/L2;512MiB 不适合 batch
Python native用 batch_search;短 batch 设 parallelism=1
SQLDataFusion 单查接近 native;SQL batch 慢于 native batch
pgvector服务化方便,但 exact 昂贵且需要数 GB RSS

9. 限制​

  • 本地 file store,不是 S3/MinIO;绝对 QPS 与远程存储不同。
  • 大多数结果 NQ=10(SIFT 参数扫描 NQ=20);QPS 为稳态值。
  • GloVe 目标配置为 nlist=1024,bits=7,nprobe=448;从 nprobe=8 开始逐步增大, nprobe=448 是首个达到 recall≥0.97 的取值(NQ=20,recall 0.9715)。
  • pgvector 不同缓存大小只在 GloVe 目标配置上测了 512MiB/1GiB/8GiB; 其它 pgvector 接口结果使用 8GiB。
  • 未报告 index_bytes:多配置构建时旧 index generation 仍在磁盘上,构建时间和 RSS 不受影响。
  • 中文和英文页面使用同一批原始数据;如需更新请重新运行基准。

10. 原始结果​

原始 JSONL 不随仓库发布。

附录 A:完整 index-only 参数扫描​

cache 8GiB,Python native;每格为 QPS / recall。

SIFT-128​

nlistbitsnproberecall单查 QPSbatch QPS
256180.517506.87999.1
2561160.531488.07457.1
2561320.524475.86616.4
2561640.524445.35573.8
25611280.524434.64498.9
256780.862457.26445.2
2567160.949409.85508.6
2567320.967395.14849.1
2567640.970391.14214.7
25671280.970359.93308.2
1024180.495508.07490.5
10241160.529509.07217.4
10241320.553438.65931.0
10241640.551437.15993.7
102411280.549441.85520.5
1024780.675467.96185.5
10247160.826430.16102.4
10247320.932430.25361.2
10247640.964379.34702.7
102471280.972355.74203.0

GloVe-200​

nlistbitsnproberecall单查 QPSbatch QPS
256180.404411.46585.8
2561160.442389.85870.8
2561320.451375.85000.8
2561640.455335.93908.0
25611280.452292.52868.2
25612560.448245.11995.2
256780.691343.04220.1
2567160.799316.33258.1
2567320.878267.22478.8
2567640.940229.51827.7
25671280.969185.31337.1
25672560.975146.21016.5
1024180.425391.35869.6
10241160.444389.45658.9
10241320.461380.35164.5
10241640.468371.34678.9
102411280.466334.53903.0
102412560.463311.63022.2
1024780.634334.15011.2
10247160.709338.54309.6
10247320.802290.72586.0
10247640.876283.62760.0
102471280.926239.82142.5
102472560.957192.21550.4
204872560.927228.81868.7
204875120.959187.51358.0
2048710240.973152.91049.6

GIST-960​

nlistbitsnproberecall单查 QPSbatch QPS
10247640.966146.41747.5
102471280.980144.31475.1
102472560.981120.81095.8
102475120.981108.2801.3
1024710240.98191.2587.9
256180.681225.33055.8
2561160.721213.52729.8
2561320.740192.82170.9
2561640.742176.01604.4
25611280.744141.31137.9
256780.827184.32511.4
2567160.932169.92039.0
2567320.974163.51788.7
2567640.980136.31342.3
25671280.981122.61007.9
1024180.588210.32688.7
10241160.681188.82583.1
10241320.735193.92434.3
10241640.758188.52096.3
102411280.764168.31692.0
1024780.635164.02354.8
10247160.790166.62236.9
10247320.905152.61493.4

Deep-Image-96​

nlistbitsnproberecall单查 QPSbatch QPS
1024180.522113.31104.6
10241160.52767.3587.4
10241320.53036.7303.2
10241640.52921.6179.3
1024780.90466.8437.3
10247160.94334.9225.3
10247320.97121.4115.8
10247640.97513.265.3
4096180.51472.01669.1
40961160.53840.11268.6
40961320.55023.2860.0
40961640.55212.5534.7
4096780.80965.51041.4
40967160.89836.3682.9
40967320.95220.3347.3
40967640.96711.2190.1