Skip to content
AI & Vectors

选择你的计算附加组件

Choosing the right Compute Add-on for your vector workload.

你有两种方式来扩展你的向量工作负载:

🌐 You have two options for scaling your vector workload:

  1. 增加你的数据库大小。这份指南会帮你为你的工作负载选择合适的大小。
  2. 将你的工作负载分散到多个数据库上。你可以在《Engineering for Scale》(engineering-for-scale)中找到关于这种方法的更多细节。

维度 #

🌐 Dimensionality

在选择合适的计算插件时,你的嵌入向量维度是最重要的因素。一般来说,维度越低,性能越好。下面我们提供了一些常见嵌入维度的指南。对于每个基准测试,我们使用 Vecs 创建了一个集合,将嵌入上传到单个表中,并为嵌入列创建了 inner-product 距离度量的 IVFFlatHNSW 索引。然后我们运行了一系列查询来衡量不同计算插件的性能:

🌐 The number of dimensions in your embeddings is the most important factor in choosing the right Compute Add-on. In general, the lower the dimensionality the better the performance. We've provided guidance for some of the more common embedding dimensions below. For each benchmark, we used Vecs to create a collection, upload the embeddings to a single table, and create both the IVFFlat and HNSW indexes for inner-product distance measure for the embedding column. We then ran a series of queries to measure the performance of different compute add-ons:

HNSW#

384 维 #

🌐 384 dimensions [#hnsw-384-dimensions]

这个基准测试使用了 dbpedia-entities-openai-1M 数据集,其中包含 1,000,000 个文本向量,已重新生成为 384 维度的向量。每个向量都是使用 gte-small 生成的。

🌐 This benchmark uses the dbpedia-entities-openai-1M dataset containing 1,000,000 embeddings of text, regenerated for 384 dimension embeddings. Each embedding is generated using gte-small.

计算规模向量数m构建ef搜索ef查询每秒 (QPS)平均延迟95%延迟RAM 使用RAM
微型100,0001664605800.017 秒0.024 秒1.2 (交换)1 GB
小型250,0002464604400.022 秒0.033 秒2 GB2 GB
中型500,0002464803500.028 秒0.045 秒4 GB4 GB
大型1,000,00032801002700.073 秒0.108 秒7 GB8 GB
XL1,000,00032801005250.038 秒0.059 秒9 GB16 GB
2XL1,000,00032801007900.025 秒0.037 秒9 GB32 GB
4XL1,000,000328010016500.015 秒0.018 秒11 GB64 GB
8XL1,000,000328010026900.015 秒0.016 秒13 GB128 GB
12XL1,000,000328010039000.014 秒0.016 秒13 GB192 GB
16XL1,000,000328010042000.014 秒0.016 秒20 GB256 GB

基准测试的准确率是0.99。

🌐 Accuracy was 0.99 for benchmarks.

960 维 #

🌐 960 dimensions [#hnsw-960-dimensions]

这个基准使用了 gist-960 数据集,其中包含 1,000,000 个图片的嵌入。每个嵌入有 960 个维度。

🌐 This benchmark uses the gist-960 dataset, which contains 1,000,000 embeddings of images. Each embedding is 960 dimensions.

计算大小向量m构建效率 ef_construction搜索效率 ef_search每秒查询数 QPS平均延迟95百分位延迟内存使用内存
微型30,0001664654300.024 秒0.034 秒1.2 GB(交换)1 GB
100,0003280602600.040 秒0.054 秒2.2 GB(交换)2 GB
中等250,0003280901200.083 秒0.106 秒4 GB4 GB
500,00032801201600.063 秒0.087 秒7 GB8 GB
XL1,000,00032802002000.049 秒0.072 秒13 GB16 GB
2XL1,000,00032802003400.025 秒0.029 秒17 GB32 GB
4XL1,000,00032802006300.031 秒0.050 秒18 GB64 GB
8XL1,000,000328020011000.034 秒0.048 秒19 GB128 GB
12XL1,000,000328020014200.041 秒0.095 秒21 GB192 GB
16XL1,000,000328020016500.037 秒0.081 秒23 GB256 GB

基准测试的准确率是0.99。

🌐 Accuracy was 0.99 for benchmarks.

通过增加mef_construction也可以提高 QPS。这将允许你使用更小的ef_search值,从而提高 QPS。

🌐 QPS can also be improved by increasing m and ef_construction. This will allow you to use a smaller value for ef_search and increase QPS.

1536 维度 #

🌐 1536 dimensions [#hnsw-1536-dimensions]

这个基准使用了 dbpedia-entities-openai-1M 数据集,其中包含 1,000,000 个文本嵌入。同时,对于计算附加组件 large 及以下,还使用了 224,482 个来自 维基百科文章 的嵌入。每个嵌入都是 1536 维,由 OpenAI Embeddings API 创建。

🌐 This benchmark uses the dbpedia-entities-openai-1M dataset, which contains 1,000,000 embeddings of text. And 224,482 embeddings from Wikipedia articles for compute add-ons large and below. Each embedding is 1536 dimensions created with the OpenAI Embeddings API.

计算大小向量m构建效率 ef_construction搜索效率 ef_search每秒查询数 QPS平均延迟95百分位延迟内存使用内存
微型15,0001640404800.011 秒0.016 秒1.2 GB(交换)1 GB
50,00032641001750.031 秒0.051 秒2.2 GB(交换)2 GB
中等100,00032641002400.083 秒0.126 秒4 GB4 GB
224,48232641002800.017 秒0.028 秒8 GB8 GB
XL500,00024561003600.055 秒0.135 秒13 GB16 GB
2XL1,000,00024562505600.036 秒0.058 秒32 GB32 GB
4XL1,000,00024562509500.021 秒0.033 秒39 GB64 GB
8XL1,000,000245625016500.016 秒0.023 秒40 GB128 GB
12XL1,000,000245625019000.015 秒0.021 秒38 GB192 GB
16XL1,000,000245625022000.015 秒0.020 秒40 GB256 GB

基准测试的准确率是0.99。

🌐 Accuracy was 0.99 for benchmarks.

QPS 也可以通过增加 mef_construction 来提升。这将允许你使用更小的 ef_search 值并增加 QPS。例如,将 4XL 的 m 提高到 32,ef_construction 提高到 80,QPS 将增加到 1280。

🌐 QPS can also be improved by increasing m and ef_construction. This will allow you to use a smaller value for ef_search and increase QPS. For example, increasing m to 32 and ef_construction to 80 for 4XL will increase QPS to 1280.

下面的图表比较了在不同嵌入维度下,各种计算规模的 HNSW 每秒查询次数。

🌐 The chart below compares HNSW queries-per-second across compute sizes for different embedding dimensions.

Chart comparing HNSW queries-per-second across Supabase compute sizes for different embedding dimensions.

体外受精平板 #

🌐 IVFFlat

384 维 #

🌐 384 dimensions [#ivfflat-384-dimensions]

这个基准测试使用了 dbpedia-entities-openai-1M 数据集,其中包含 1,000,000 个文本向量,已重新生成为 384 维度的向量。每个向量都是使用 gte-small 生成的。

🌐 This benchmark uses the dbpedia-entities-openai-1M dataset containing 1,000,000 embeddings of text, regenerated for 384 dimension embeddings. Each embedding is generated using gte-small.

计算规模向量列表探针每秒查询数 (QPS)平均延迟95百分位延迟内存使用内存
微型100,000500502050.048 秒0.066 秒1.2 GB (交换)1 GB
小型250,0001000601600.062 秒0.079 秒2 GB2 GB
中型500,0002000801200.082 秒0.104 秒3.2 GB4 GB
大型1,000,0005000150750.269 秒0.375 秒6.5 GB8 GB
超大1,000,00050001501500.131 秒0.178 秒9 GB16 GB
2倍超大1,000,00050001503000.066 秒0.099 秒10 GB32 GB
4倍超大1,000,00050001505700.035 秒0.046 秒10 GB64 GB
8倍超大1,000,000500015014000.023 秒0.028 秒12 GB128 GB
12倍超大1,000,000500015015500.030 秒0.039 秒12 GB192 GB
16倍超大1,000,000500015018000.030 秒0.039 秒16 GB256 GB

960 维 #

🌐 960 dimensions [#ivfflat-960-dimensions]

这个基准使用了 gist-960 数据集,其中包含 1,000,000 个图片的嵌入。每个嵌入有 960 个维度。

🌐 This benchmark uses the gist-960 dataset, which contains 1,000,000 embeddings of images. Each embedding is 960 dimensions.

计算规模向量列表QPS平均延迟延迟 p95内存使用内存
微型30,00030750.065 秒0.088 秒1.1 GB(交换)1 GB
小型100,000100780.064 秒0.092 秒1.8 GB2 GB
中型250,000250580.085 秒0.129 秒3.2 GB4 GB
大型500,000500550.088 秒0.140 秒5 GB8 GB
XL1,000,00010001100.046 秒0.070 秒14 GB16 GB
2XL1,000,00010002350.083 秒0.136 秒10 GB32 GB
4XL1,000,00010004200.071 秒0.106 秒11 GB64 GB
8XL1,000,00010008150.072 秒0.106 秒13 GB128 GB
12XL1,000,000100011500.052 秒0.078 秒15.5 GB192 GB
16XL1,000,000100013450.072 秒0.106 秒17.5 GB256 GB

1536 维度 #

🌐 1536 dimensions [#ivfflat-1536-dimensions]

这个基准测试使用了 dbpedia-entities-openai-1M 数据集,其中包含 1,000,000 个文本向量。每个向量有 1536 个维度,是通过 OpenAI Embeddings API 创建的。

🌐 This benchmark uses the dbpedia-entities-openai-1M dataset, which contains 1,000,000 embeddings of text. Each embedding is 1536 dimensions created with the OpenAI Embeddings API.

计算规模向量数列表数每秒查询数 (QPS)平均延迟95% 延迟内存使用内存总量
微型20,000401350.372 秒0.412 秒1.2 GB(交换)1 GB
小型50,0001001400.357 秒0.398 秒1.8 GB2 GB
中型100,0002001300.383 秒0.446 秒3.7 GB4 GB
大型250,0005001300.378 秒0.434 秒7 GB8 GB
超大 (XL)500,00010002350.213 秒0.271 秒13.5 GB16 GB
双超大 (2XL)1,000,00020003800.133 秒0.236 秒30 GB32 GB
四超大 (4XL)1,000,00020007200.068 秒0.120 秒35 GB64 GB
八超大 (8XL)1,000,000200012500.039 秒0.066 秒38 GB128 GB
十二超大 (12XL)1,000,000200016000.030 秒0.052 秒41 GB192 GB
十六超大 (16XL)1,000,000200017900.029 秒0.051 秒45 GB256 GB

对于 1,000,000 个向量,使用 10 个探针的准确率为 0.91。而对于 500,000 个向量及以下,使用 10 个探针的准确率在 0.95 到 0.99 之间。想要提高准确率,你需要增加探针的数量。

🌐 For 1,000,000 vectors 10 probes results to accuracy of 0.91. And for 500,000 vectors and below 10 probes results to accuracy in the range of 0.95 - 0.99. To increase accuracy, you need to increase the number of probes.

下面的图表绘制了每秒请求数与计算规模的关系。

🌐 The chart below plots requests-per-second against compute size.

Chart plotting requests-per-second against Supabase compute size.

性能小贴士 #

🌐 Performance tips

有很多方法可以提升你的 pgvector 性能。这里有一些小贴士:

🌐 There are various ways to improve your pgvector performance. Here are some tips:

预热你的数据库 #

🌐 Pre-warming your database

在投入生产之前,先执行几千个“热身”查询是很有用的。这有助于 RAM 的使用。这也可以帮助你确定为你的工作负载选择的计算规模是否合适。

🌐 It's useful to execute a few thousand “warm-up” queries before going into production. This helps help with RAM utilization. This can also help to determine that you've selected the right compute size for your workload.

微调索引参数 #

🌐 Fine-tune index parameters

你可以通过增加 mef_constructionlists 来提高每秒请求数。不过这里有个重要提醒:这些参数的值越高,构建索引所需的时间也越长。

🌐 You can increase the Requests per Second by increasing m and ef_construction or lists. This also has an important caveat: building the index takes longer with higher values for these parameters.

下面的图表显示了 HNSW 构建参数 mef_construction 如何影响 dbpedia 数据集上的每秒请求数。

🌐 The chart below shows how the HNSW build parameters m and ef_construction affect requests-per-second on the dbpedia dataset.

Chart showing how HNSW build parameters (m and ef_construction) affect requests-per-second on the dbpedia dataset.

Going to Production for AI applications 查看更多技巧和完整的逐步指南。

🌐 Check out more tips and the complete step-by-step guide in Going to Production for AI applications.

基准方法 #

🌐 Benchmark methodology

我们遵循ANN Benchmarks方法中概述的技术。一个 Python 测试运行器负责上传数据、创建索引以及执行查询。pgvector 引擎是使用 vecs 实现的,这是一个用于 pgvector 的 Python 客户端。

🌐 We follow techniques outlined in the ANN Benchmarks methodology. A Python test runner is responsible for uploading the data, creating the index, and running the queries. The pgvector engine is implemented using vecs, a Python client for pgvector.

Diagram of the vecs benchmark setup: a Python test runner uploads data, builds the index, and runs queries against pgvector.

上图显示了 vecs 基准测试的设置:一个 Python 测试运行器上传数据、构建索引,并对 pgvector 运行查询。

🌐 The diagram above shows the vecs benchmark setup: a Python test runner uploads data, builds the index, and runs queries against pgvector.

每次测试至少运行30-40分钟。测试包括在不同并发级别下进行的一系列实验,以测量引擎在不同负载类型下的性能。然后将结果取平均值。

🌐 Each test is run for a minimum of 30-40 minutes. They include a series of experiments executed at different concurrency levels to measure the engine's performance under different load types. The results are then averaged.

一般建议是,对于大多数工作负载,我们建议使用至少5的并发级别;对于高负载工作负载,则建议使用至少30的并发级别。

🌐 As a general recommendation, we suggest using a concurrency level of 5 or more for most workloads and 30 or more for high-load workloads.