向量索引基准测试(Local File)
本文档是 Local File(本地文件系统) 版本,覆盖构建与索引检索。 本轮只测试构建和索引检索,不测试 upsert/增量维护。MinIO 版本见 MinIO 版本。
1. 结论摘要
四个标准 ANN 数据集在 RaBitQ bits=7 下都能达到 recall@100 ≥ 0.97,代价是需要更大的 nprobe。
主要权衡是 bits=7 与 bits=1、缓存大小(尤其 exact 重排)以及接口。
| 数据集 | 配置 | recall | index 单查 QPS | index batch QPS |
|---|---|---|---|---|
| SIFT-128 | nlist=256, bits=7, nprobe=64 | 0.970 | 379.4 | 4128.9 |
| GloVe-200 | nlist=1024, bits=7, nprobe=448 | 0.971 | 178.2 | 1294.3 |
| GIST-960 | nlist=256, bits=7, nprobe=32 | 0.974 | 157.7 | 1709.2 |
| Deep-Image-96 | nlist=1024, bits=7, nprobe=32 | 0.971 | 22.9 | 121.7 |
2. 测试方法
| 项目 | 取值 |
|---|---|
| 存储 | 本地 file store(不是 MinIO/S3) |
| 索引 | IVF + RaBitQ,hash_bucket_num=4 |
| top_k | 100 |
| recall | 对 HDF5 ground truth 的 recall@100 |
| RSS | 构建/查询进程 VmRSS;pgvector 另列服务端 RSS |
| 构建 | 独立 build 进程,不含写表阶段峰值 |
| 清理 | 每个数据集测完 drop 表、删除本地 index/cache |
| 数据集 | Base | Query | GT | dim | 距离 |
|---|---|---|---|---|---|
| SIFT-128 | 1,000,000 | 10,000 | 100-NN | 128 | L2 |
| GloVe-200 | 1,183,514 | 10,000 | 100-NN | 200 | cosine |
| GIST-960 | 1,000,000 | 1,000 | 100-NN | 960 | L2 |
| Deep-Image-96 | 9,990,000 | 10,000 | 100-NN | 96 | cosine |
缓存/接口表中每格格式为 单查 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 越大越稳定但越慢。
机器与实测资源
| 项目 | 取值 |
|---|---|
| CPU | Intel 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. 构建
| 数据集 | nlist | bits | build s | build RSS MB | 写表 s |
|---|---|---|---|---|---|
| SIFT-128 | 256 | 1 | 3.6 | 481 | 3.0 |
| SIFT-128 | 256 | 7 | 4.1 | 542 | 3.0 |
| SIFT-128 | 1024 | 1 | 6.2 | 325 | 3.0 |
| SIFT-128 | 1024 | 7 | 7.2 | 385 | 3.0 |
| GloVe-200 | 256 | 1 | 8.3 | 703 | 7.8 |
| GloVe-200 | 256 | 7 | 9.3 | 767 | 7.8 |
| GloVe-200 | 1024 | 1 | 13.6 | 685 | 7.8 |
| GloVe-200 | 1024 | 7 | 14.0 | 763 | 7.8 |
| GloVe-200 | 2048 | 7 | 24.3 | 770 | 7.8 |
| GIST-960 | 256 | 1 | 34.1 | 791 | 30.1 |
| GIST-960 | 256 | 7 | 37.1 | 1077 | 30.1 |
| GIST-960 | 1024 | 1 | 51.2 | 638 | 30.1 |
| GIST-960 | 1024 | 7 | 54.2 | 804 | 30.1 |
| Deep-Image-96 | 1024 | 1 | 93.9 | 1207 | 31.4 |
| Deep-Image-96 | 1024 | 7 | 97.1 | 1442 | 31.4 |
| Deep-Image-96 | 4096 | 1 | 136.4 | 1038 | 31.4 |
| Deep-Image-96 | 4096 | 7 | 138.5 | 1207 | 31.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。
目标配置
| 数据集 | 配置 | recall | index 单查 | index batch | exact 单查 | exact batch |
|---|---|---|---|---|---|---|
| SIFT-128 | nlist=256, bits=7, nprobe=64 | 0.970 | 379.4 | 4128.9 | 50.1 | 2307.1 |
| GloVe-200 | nlist=1024, bits=7, nprobe=448 | 0.971 | 178.2 | 1294.3 | 23.6 | 915.3 |
| GIST-960 | nlist=256, bits=7, nprobe=32 | 0.974 | 157.7 | 1709.2 | 13.4 | 1019.1 |
| Deep-Image-96 | nlist=1024, bits=7, nprobe=32 | 0.971 | 22.9 | 121.7 | 8.6 | 138.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
| cache | index 单查 | index batch | exact 单查 | exact batch |
|---|---|---|---|---|
| 512m | 332.1 / 3.01 / 381 / 0.970 | 4201.3 / 0.24 / 383 / 0.970 | 43.0 / 23.24 / 731 / 1.000 | 148.3 / 6.74 / 1059 / 1.000 |
| 1g | 326.4 / 3.06 / 381 / 0.970 | 4232.3 / 0.24 / 383 / 0.970 | 46.4 / 21.57 / 818 / 1.000 | 223.1 / 4.48 / 1188 / 1.000 |
| 8g | 379.4 / 2.64 / 380 / 0.970 | 4128.9 / 0.24 / 382 / 0.970 | 50.1 / 19.98 / 887 / 1.000 | 2307.1 / 0.43 / 890 / 1.000 |
| off | 5.4 / 185.91 / 381 / 0.970 | 106.6 / 9.38 / 383 / 0.970 | — | — |
GloVe-200
| cache | index 单查 | index batch | exact 单查 | exact batch |
|---|---|---|---|---|
| 512m | 87.5 / 11.43 / 651 / 0.971 | 1304.9 / 0.77 / 653 / 0.971 | 15.1 / 66.28 / 1019 / 0.988 | 28.0 / 35.72 / 1348 / 0.988 |
| 1g | 156.6 / 6.39 / 558 / 0.971 | 1276.7 / 0.78 / 559 / 0.971 | 22.7 / 44.14 / 1100 / 0.988 | 139.1 / 7.19 / 1429 / 0.988 |
| 8g | 178.2 / 5.61 / 558 / 0.971 | 1294.3 / 0.77 / 559 / 0.971 | 23.6 / 42.32 / 1424 / 0.988 | 915.3 / 1.09 / 1427 / 0.988 |
GIST-960
| cache | index 单查 | index batch | exact 单查 | exact batch |
|---|---|---|---|---|
| 512m | 75.5 / 13.25 / 1117 / 0.974 | 1732.8 / 0.58 / 1118 / 0.974 | 5.2 / 190.49 / 1686 / 0.990 | 13.7 / 73.12 / 1950 / 0.990 |
| 1g | 160.3 / 6.24 / 1115 / 0.974 | 1762.8 / 0.57 / 1117 / 0.974 | 6.7 / 148.45 / 1890 / 0.990 | 58.9 / 16.97 / 2154 / 0.990 |
| 8g | 157.7 / 6.34 / 1113 / 0.974 | 1709.2 / 0.59 / 1115 / 0.974 | 13.4 / 74.68 / 1990 / 0.990 | 1019.1 / 0.98 / 1993 / 0.990 |
| off | 3.1 / 327.81 / 1128 / 0.974 | 31.2 / 32.04 / 1132 / 0.974 | — | — |
Deep-Image-96
| cache | index 单查 | index batch | exact 单查 | exact batch |
|---|---|---|---|---|
| 512m | 20.9 / 47.77 / 967 / 0.971 | 22.8 / 43.85 / 1722 / 0.971 | 8.5 / 118.06 / 1300 / 0.989 | 7.1 / 141.38 / 1991 / 0.989 |
| 1g | 21.0 / 47.56 / 1064 / 0.971 | 127.8 / 7.82 / 1095 / 0.971 | 9.0 / 111.68 / 1556 / 0.989 | 63.3 / 15.79 / 1858 / 0.989 |
| 8g | 22.9 / 43.72 / 1042 / 0.971 | 121.7 / 8.22 / 1052 / 0.971 | 8.6 / 115.94 / 1870 / 0.989 | 138.9 / 7.20 / 1987 / 0.989 |
| off | 21.9 / 45.57 / 540 / 0.971 | 29.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 |
|---|---|---|---|---|
| python | index | 379.4 / 2.64 / 380 / 0.970 | 4128.9 / 0.24 / 382 / 0.970 | — |
| python | exact | 50.1 / 19.98 / 887 / 1.000 | 2307.1 / 0.43 / 890 / 1.000 | — |
| datafusion | index | 450.7 / 2.22 / 381 / 0.970 | 478.6 / 2.09 / 381 / 0.970 | — |
| datafusion | exact | 49.9 / 20.06 / 874 / 1.000 | 396.8 / 2.52 / 874 / 1.000 | — |
| pgvector | index | 390.6 / 2.56 / 64 / 0.970 | 440.2 / 2.27 / 65 / 0.970 | 304 |
| pgvector | exact | 100.0 / 10.00 / 64 / 1.000 | 189.6 / 5.27 / 65 / 1.000 | 853 |
GloVe-200
| 接口 | rerank | 单查 | batch | 服务端 RSS MB |
|---|---|---|---|---|
| python | index | 178.2 / 5.61 / 558 / 0.971 | 1294.3 / 0.77 / 559 / 0.971 | — |
| python | exact | 23.6 / 42.32 / 1424 / 0.988 | 915.3 / 1.09 / 1427 / 0.988 | — |
| datafusion | index | 187.8 / 5.32 / 557 / 0.971 | 214.3 / 4.67 / 557 / 0.971 | — |
| datafusion | exact | 24.9 / 40.14 / 1416 / 0.988 | 203.2 / 4.92 / 1416 / 0.988 | — |
| pgvector | index | 196.0 / 5.10 / 68 / 0.971 | 220.1 / 4.54 / 68 / 0.971 | 476 |
| pgvector | exact | 44.0 / 22.74 / 68 / 0.988 | 99.7 / 10.03 / 68 / 0.988 | 1463 |
GIST-960
| 接口 | rerank | 单查 | batch | 服务端 RSS MB |
|---|---|---|---|---|
| python | index | 157.7 / 6.34 / 1113 / 0.974 | 1709.2 / 0.59 / 1115 / 0.974 | — |
| python | exact | 13.4 / 74.68 / 1990 / 0.990 | 1019.1 / 0.98 / 1993 / 0.990 | — |
| datafusion | index | 170.9 / 5.85 / 1114 / 0.974 | 182.8 / 5.47 / 1115 / 0.974 | — |
| datafusion | exact | 13.6 / 73.80 / 1990 / 0.990 | 159.9 / 6.26 / 1992 / 0.990 | — |
| pgvector | index | 190.5 / 5.25 / 60 / 0.974 | 217.6 / 4.60 / 60 / 0.974 | 1046 |
| pgvector | exact | 4.1 / 243.59 / 60 / 0.990 | 33.6 / 29.73 / 60 / 0.990 | 3949 |
Deep-Image-96
| 接口 | rerank | 单查 | batch | 服务端 RSS MB |
|---|---|---|---|---|
| python | index | 22.9 / 43.72 / 1042 / 0.971 | 121.7 / 8.22 / 1052 / 0.971 | — |
| python | exact | 8.6 / 115.94 / 1870 / 0.989 | 138.9 / 7.20 / 1987 / 0.989 | — |
| datafusion | index | 21.7 / 46.04 / 1053 / 0.971 | 96.6 / 10.36 / 1125 / 0.971 | — |
| datafusion | exact | 8.4 / 119.75 / 1890 / 0.989 | 88.8 / 11.26 / 2200 / 0.989 | — |
| pgvector | index | 22.3 / 44.81 / 63 / 0.971 | 94.0 / 10.64 / 63 / 0.971 | 902 |
| pgvector | exact | 4.2 / 238.81 / 63 / 0.989 | 11.9 / 84.30 / 63 / 0.989 | 3825 |
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:
| parallelism | index 单查 QPS | index batch QPS |
|---|---|---|
| 1 | 378.6 | 4301.7 |
| 2 | 325.4 | 2643.1 |
| 4 | 379.4 | 3190.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 |
| SQL | DataFusion 单查接近 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。