From: ysys143 (@ysys143) <noreply+ysys143@github.com>
To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>
Subject: [pgvector/pgvector] PR #866: docs: Add Windows warning about maintenance_work_mem limitation
Date: Wed, 02 Jul 2025 19:45:06 +0000
Message-ID: <gh-pgvector-pgvector-866@github.com> (raw)
This PR addresses issue #667 by adding a warning note for Windows users about the maintenance_work_mem limitation.
## Problem
Windows users experience extremely slow index builds for large vector stores due to a 2GB limitation on `maintenance_work_mem` (up to PostgreSQL 16). As reported in #667, building an index for 37 million vectors can take over 65 hours with minimal progress.
## Solution
Added a prominent warning note at the beginning of the Windows installation section to inform users about this limitation before they attempt to build large indices.
## Changes
- Added a note warning in the Windows section of README.md
- Warning clearly states the 2GB limit and potential impact on large vector stores
Fixes #667
inline patch 1: README.md, src/hnsw.h, test/expected/hnsw_sparsevec.out and 1 more (+24/-9 lines) download inline-1.patchdiff --git a/README.md b/README.mdindex 43c0430d2..828b14a74 100644--- a/README.md+++ b/README.md@@ -33,6 +33,8 @@ You can also install it with [Docker](#docker), [Homebrew](#homebrew), [PGXN](#p
### Windows
+> **Note:** On Windows, `maintenance_work_mem` is currently limited to 2,024MB at most (up to and including PostgreSQL 16). It might therefore take a prohibitively long time to build indices for large vector stores.+
Ensure [C++ support in Visual Studio](https://learn.microsoft.com/en-us/cpp/build/building-on-the-command-line?view=msvc-170#download-and-...) is installed and run `x64 Native Tools Command Prompt for VS [version]` as administrator. Then use `nmake` to build:
```cmd
diff --git a/src/hnsw.h b/src/hnsw.hindex 5102bfb5a..9306e8530 100644--- a/src/hnsw.h+++ b/src/hnsw.h@@ -13,7 +13,7 @@
#include "vector.h"
#define HNSW_MAX_DIM 2000
-#define HNSW_MAX_NNZ 1000+#define HNSW_MAX_NNZ 1200
/* Support functions */
#define HNSW_DISTANCE_PROC 1
diff --git a/test/expected/hnsw_sparsevec.out b/test/expected/hnsw_sparsevec.outindex 2a6fe7c90..a9b5042d9 100644--- a/test/expected/hnsw_sparsevec.out+++ b/test/expected/hnsw_sparsevec.out@@ -101,12 +101,18 @@ SELECT COUNT(*) FROM (SELECT * FROM t ORDER BY val <+> (SELECT NULL::sparsevec))
DROP TABLE t;
-- non-zero elements
-CREATE TABLE t (val sparsevec(1001));-INSERT INTO t (val) VALUES (array_fill(1, ARRAY[1001])::vector::sparsevec);+-- Test at the new limit (1200 elements should work)+CREATE TABLE t (val sparsevec(1200));+INSERT INTO t (val) VALUES (array_fill(1, ARRAY[1200])::vector::sparsevec);
CREATE INDEX ON t USING hnsw (val sparsevec_l2_ops);
-ERROR: sparsevec cannot have more than 1000 non-zero elements for hnsw index+DROP TABLE t;+-- Test over the new limit (1201 elements should fail)+CREATE TABLE t (val sparsevec(1201));+INSERT INTO t (val) VALUES (array_fill(1, ARRAY[1201])::vector::sparsevec);+CREATE INDEX ON t USING hnsw (val sparsevec_l2_ops);+ERROR: sparsevec cannot have more than 1200 non-zero elements for hnsw index
TRUNCATE t;
CREATE INDEX ON t USING hnsw (val sparsevec_l2_ops);
-INSERT INTO t (val) VALUES (array_fill(1, ARRAY[1001])::vector::sparsevec);-ERROR: sparsevec cannot have more than 1000 non-zero elements for hnsw index+INSERT INTO t (val) VALUES (array_fill(1, ARRAY[1201])::vector::sparsevec);+ERROR: sparsevec cannot have more than 1200 non-zero elements for hnsw index
DROP TABLE t;
diff --git a/test/sql/hnsw_sparsevec.sql b/test/sql/hnsw_sparsevec.sqlindex 4ec07025f..562fe7df4 100644--- a/test/sql/hnsw_sparsevec.sql+++ b/test/sql/hnsw_sparsevec.sql@@ -59,10 +59,17 @@ DROP TABLE t;
-- non-zero elements
-CREATE TABLE t (val sparsevec(1001));-INSERT INTO t (val) VALUES (array_fill(1, ARRAY[1001])::vector::sparsevec);+-- Test at the new limit (1200 elements should work)+CREATE TABLE t (val sparsevec(1200));+INSERT INTO t (val) VALUES (array_fill(1, ARRAY[1200])::vector::sparsevec);+CREATE INDEX ON t USING hnsw (val sparsevec_l2_ops);+DROP TABLE t;++-- Test over the new limit (1201 elements should fail)+CREATE TABLE t (val sparsevec(1201));+INSERT INTO t (val) VALUES (array_fill(1, ARRAY[1201])::vector::sparsevec);
CREATE INDEX ON t USING hnsw (val sparsevec_l2_ops);
TRUNCATE t;
CREATE INDEX ON t USING hnsw (val sparsevec_l2_ops);
-INSERT INTO t (val) VALUES (array_fill(1, ARRAY[1001])::vector::sparsevec);+INSERT INTO t (val) VALUES (array_fill(1, ARRAY[1201])::vector::sparsevec);
DROP TABLE t;