You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/pgvecto_rs/admin/kubernetes.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -94,7 +94,7 @@ spec:
94
94
- "vectors.so"
95
95
```
96
96
97
-
You can install `cnpg` [kubectl plugin](https://cloudnative-pg.io/documentation/1.22/kubectl-plugin/) to manage your PostgreSQL cluster. Now we can check the status of the cluster.
97
+
You can install `cnpg` [kubectl plugin](https://cloudnative-pg.io/docs/1.28/kubectl-plugin) to manage your PostgreSQL cluster. Now we can check the status of the cluster.
Copy file name to clipboardExpand all lines: src/vectorchord/admin/kubernetes.md
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -87,7 +87,7 @@ spec:
87
87
- "vchord"
88
88
```
89
89
90
-
You can install `cnpg` [kubectl plugin](https://cloudnative-pg.io/documentation/1.25/kubectl-plugin/) to manage your PostgreSQL cluster. Now we can check the status of the cluster.
90
+
You can install `cnpg` [kubectl plugin](https://cloudnative-pg.io/docs/1.28/kubectl-plugin) to manage your PostgreSQL cluster. Now we can check the status of the cluster.
91
91
92
92
```shell
93
93
$ sudo kubectl get pod
@@ -170,7 +170,7 @@ For Kubernetes, the [ImageVolume feature](https://kubernetes.io/blog/2024/08/16/
170
170
Based on these two features, we can create lightweight `vectorchord` extension image [vchord-scratch](https://github.com/tensorchord/VectorChord-images/pkgs/container/vchord-scratch).
171
171
172
172
:::tip
173
-
If you want to use [`Image Volume Extensions`](https://cloudnative-pg.io/documentation/current/imagevolume_extensions/), you need to meet the following requirements:
173
+
If you want to use [`Image Volume Extensions`](https://cloudnative-pg.io/docs/1.28/imagevolume_extensions), you need to meet the following requirements:
174
174
- Use Kubernetes version 1.31.0 or above (1.33.0 is recommended), and make sure the `ImageVolume` feature gate is enabled.
175
175
- Use CloudNative-PG helm chart version 0.26.0 or above.
Copy file name to clipboardExpand all lines: src/vectorchord/admin/scalability.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -25,7 +25,7 @@ Therefore, we deploy VectorChord services on AWS EKS with OpenTofu and CloudNati
25
25
26
26
*[CloudNativePG](https://cloudnative-pg.io/): Manage the full lifecycle of a highly available PostgreSQL database cluster with a primary/standby architecture
27
27
28
-
*[PGBouncer](https://www.pgbouncer.org/): Lightweight connection pooler for PostgreSQL, provided by module [Pooler](https://cloudnative-pg.io/documentation/1.25/connection_pooling/) of CloudNativePG
28
+
*[PGBouncer](https://www.pgbouncer.org/): Lightweight connection pooler for PostgreSQL, provided by module [Pooler](https://cloudnative-pg.io/docs/1.28/connection_pooling) of CloudNativePG
The process of building an index involves two steps: partitioning the vector space first, and then inserting rows into the index. The first step, partitioning the vector space, can be sped up using multiple threads.
61
+
The process of building an index involves two steps: clustering the vectors first, and then inserting vectors into the index. The first step, clustering the vectors, can be sped up using multiple threads.
62
62
63
63
```sql
64
64
CREATEINDEXON items USING vchordrq (embedding vector_l2_ops) WITH (options = $$
65
65
[build.internal]
66
66
lists = [1000]
67
67
build_threads =8
68
68
$$);
69
-
70
-
SETvchordrq.probes TO '10';
71
-
SELECT*FROM items ORDER BY embedding <->'[3,1,2]'LIMIT10;
72
69
```
73
70
74
-
The second step, inserting rows, can be parallelized using multiple processes. Refer to [PostgreSQL Tuning](performance-tuning.md).
71
+
The second step, inserting vectors into the index, can be parallelized using the appropriate GUC parameter. Refer to [PostgreSQL Tuning](performance-tuning.md). It's a common practice to set the value of `build.internal.build_threads` and parallel workers of PostgreSQL to the number of CPU cores.
75
72
76
-
For most datasets using cosine similarity, enabling `residual_quantization` and `build.internal.spherical_centroids`improves both QPS and recall.
73
+
For most datasets using cosine similarity, enabling `residual_quantization` and `build.internal.spherical_centroids`may improve both QPS and recall. We recommend validating this on a representative sample of your production data in a staging or offline evaluation environment (for example, via offline recall/latency benchmarks or a controlled A/B test) before enabling it broadly in production.
77
74
78
75
```sql
79
76
CREATEINDEXON items USING vchordrq (embedding vector_cosine_ops) WITH (options = $$
@@ -83,27 +80,59 @@ lists = [1000]
83
80
spherical_centroids = true
84
81
build_threads =8
85
82
$$);
83
+
```
86
84
87
-
SETvchordrq.probes TO '10';
88
-
SELECT*FROM items ORDER BY embedding <=>'[3,1,2]'LIMIT10;
85
+
## Tuning: Handling ultra large vector tables
86
+
87
+
For large tables with more than 50 million rows, the `build.internal` process requires significant time and memory. Let the effective vector dimension used during k-means be $D$, `build.internal.lists[-1]` be $C$, `build.internal.sampling_factor` be $F$, `build.internal.kmeans_iterations` be $L$, and `build.internal.build_threads` be $T$.
88
+
89
+
* The memory consumption is approximately $4DC(F + T + 1)$ bytes, which usually takes more than 128 GB.
90
+
* The build time is approximately $O(FC^2DL)$, which usually takes more than one day.
91
+
92
+
To improve the build speed, you may opt to use more shared memory to accelerate the process by setting `build.pin` to `2`.
93
+
94
+
```sql
95
+
CREATEINDEXON items USING vchordrq (embedding vector_l2_ops) WITH (options = $$
96
+
build.pin=2
97
+
[build.internal]
98
+
lists = [160000]
99
+
build_threads =8
100
+
$$);
89
101
```
90
102
91
-
For large tables, you may opt to use more shared memory to accelerate the process by setting `build.pin` to `2`.
103
+
If the build speed is still unsatisfactory, you can use the hierarchical clustering to accelerate the process at the expense of some accuracy. In our [benchmark](https://blog.vectorchord.ai/how-we-made-100m-vector-indexing-in-20-minutes-possible-on-postgresql#heading-hierarchical-k-means), the hierarchical clustering was 100 times faster than the default algorithm, while query accuracy decreased by less than 1%.
92
104
93
105
```sql
94
106
CREATEINDEXON items USING vchordrq (embedding vector_l2_ops) WITH (options = $$
95
-
residual_quantization = true
96
107
build.pin=2
97
108
[build.internal]
98
-
lists = [1000]
99
-
spherical_centroids = true
109
+
lists = [160000]
100
110
build_threads =8
111
+
kmeans_algorithm.hierarchical= {}
101
112
$$);
102
113
```
103
114
104
-
For large tables, the `build.internal` process costs significant time and memory. Let `build.internal.kmeans_dimension` or the dimension be $D$, `build.internal.lists[-1]` be $C$, `build.internal.sampling_factor` be $F$, and `build.internal.build_threads` be $T$. The memory consumption is approximately $4CD(F + T + 1)$ bytes. You can moderately reduce these options for lower memory usage.
115
+
---
116
+
117
+
If you encounter an Out-of-Memory (OOM) error, reducing $D$, $C$ or $F$ will lower the memory usage. Based on our [experience](https://blog.vectorchord.ai/how-we-made-100m-vector-indexing-in-20-minutes-possible-on-postgresql#heading-dimensionality-reduction), reducing `D` will have the least impact on accuracy, so that could be a good starting point. Decreasing `F` is also plausible. Since `C` is much more sensitive, it should be the last thing you consider.
118
+
119
+
For your reference, this configuration has little impact on query accuracy (less than 1%):
120
+
* Reduce `D` from 768 to 100
121
+
* Reduce `F` from 256 to 64
122
+
123
+
```sql
124
+
CREATEINDEXON items USING vchordrq (embedding vector_l2_ops) WITH (options = $$
125
+
build.pin=2
126
+
[build.internal]
127
+
lists = [160000]
128
+
build_threads =8
129
+
kmeans_algorithm.hierarchical= {}
130
+
kmeans_dimension =100
131
+
sampling_factor =64
132
+
$$);
133
+
```
105
134
106
-
You can also refer to [External Build](external-index-precomputation) to offload the indexing workload to other machines.
135
+
If you have sufficient memory, please do not set `build.internal.kmeans_dimension`, as it will reduce accuracy and may increase build time due to the dimension restoration. If the accuracy is not acceptable, you can also refer to the[External Build](external-index-precomputation) to offload the indexing workload to other machines.
0 commit comments