测试环境
配置项 | 说明 |
数据库 | RDS PostgreSQL 17 |
pgvector | 0.8.0 |
实例规格 | 16 vCPU / 64 GB |
客户端 | 4 vCPU / 8 GB(同 VPC) |
测试工具 | |
压测模式 | 单线程 |
召回口径 | Recall@100 |
测试数据集
数据集 | 维度 | 向量数 | 距离类型 | 典型场景 |
dbpedia-openai-1M | 1536 | 1,000,000 | Cosine | OpenAI /大模型 Embedding |
NYTimes-256 | 256 | 290,000 | Cosine | 文本相似度检索 |
测试方法
环境准备
1. 安装 ann-benchmarks
git clone https://github.com/erikbern/ann-benchmarks.gitcd ann-benchmarkspip install -r requirements.txt
2. 配置数据库连接
编辑
ann_benchmarks/algorithms/pgvector/module.py,添加连接信息:import osos.environ['ANN_BENCHMARKS_PG_USER'] = '<用户名>'os.environ['ANN_BENCHMARKS_PG_PASSWORD'] = '<密码>'os.environ['ANN_BENCHMARKS_PG_DBNAME'] = '<数据库名>'os.environ['ANN_BENCHMARKS_PG_HOST'] = '<实例内网地址>'os.environ['ANN_BENCHMARKS_PG_PORT'] = '5432'os.environ['ANN_BENCHMARKS_PG_START_SERVICE'] = 'false'
3. 配置测试参数
编辑
ann_benchmarks/algorithms/pgvector/config.yml:float:any:- base_args: ['@metric']constructor: PGVectordisabled: falsedocker_tag: ann-benchmarks-pgvectormodule: ann_benchmarks.algorithms.pgvectorname: pgvectorrun_groups:M-16(200):arg_groups: [{M: 16, efConstruction: 200}]args: {}query_args: [[10, 20, 40, 80, 120, 200, 400, 800]]M-24(200):arg_groups: [{M: 24, efConstruction: 200}]args: {}query_args: [[10, 20, 40, 80, 120, 200, 400, 800]]M-48(256):arg_groups: [{M: 48, efConstruction: 256}]args: {}query_args: [[10, 20, 40, 80, 120, 200, 400, 800]]
4. 构建测试 Docker 镜像
python install.py --algorithm pgvector
执行测试
# dbpedia-openai-1M数据集测试python run.py --dataset dbpedia-openai-1000k-angular -k 100 --algorithm pgvector --runs 1# NYTimes-256 数据集测试python run.py --dataset nytimes-256-angular -k 100 --algorithm pgvector --runs 1
获取结果
# 生成可视化图表python plot.py --dataset dbpedia-openai-1000k-angular --recompute# 导出详细 CSV数据python data_export.py --out results.csv
性能测试结果
dbpedia-openai-1M(1536维 / 100万向量)
场景 | 索引配置 | ef_search | Recall@100 | QPS | P99(ms) |
高召回 | m=24, ef_construction=200 | 120 | 99.2% | 225 | 7.2 |
超高召回 | m=48, ef_construction=256 | 120 | 99.8% | 146 | 12.3 |
NYTimes-256(256维 / 29万向量)
场景 | 索引配置 | ef_search | Recall@100 | QPS | P99(ms) |
高召回 | m=24, ef_construction=200 | 400 | 89.0% | 101 | 12.7 |
超高召回 | m=24, ef_construction=200 | 800 | 93.9% | 52 | 23.6 |