pg.ddx.io  pgvector/pgvector GitHub issues and pull requests  
help / color / mirror / Atom feed
From: blaifa (@blaifa) <noreply+blaifa@github.com>
To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>
Subject: [pgvector/pgvector] PR #994: Increase HNSW sparsevec non-zero limit to 1,200
Date: Tue, 30 Jun 2026 17:55:07 +0000
Message-ID: <gh-pgvector-pgvector-994@github.com> (raw)

## Summary
- Increase `HNSW_MAX_NNZ` from 1,000 to 1,200 for HNSW indexes on `sparsevec`
- Update regression tests to verify 1,200 succeeds and 1,201 fails (both CREATE INDEX and INSERT paths)
- Update README and CHANGELOG

Fixes #749.

## Motivation
SPLADE sparse embeddings can produce vectors with ~1,100 non-zero elements, which exceed the current HNSW limit while remaining well within the `sparsevec` type limit (16,000).

## Test plan
- [x] `make installcheck REGRESS=hnsw_sparsevec` (requires local Postgres)
- [ ] CI (runs on PR)

inline patch 1: CHANGELOG.md, README.md, src/hnsw.h and 2 more (+20/-10 lines) download inline-1.patchdiff --git a/CHANGELOG.md b/CHANGELOG.md index 00ff83e2a..1e72af353 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ - Fixed `hnsw graph not repaired` error with HNSW vacuuming - Fixed possible error with inserts during HNSW vacuuming +- Increased HNSW index limit for `sparsevec` non-zero elements from 1,000 to 1,200 ## 0.8.3 (2026-06-17) diff --git a/README.md b/README.md index 5331da290..3885ad2b3 100644 --- a/README.md +++ b/README.md @@ -252,7 +252,7 @@ Supported types are: - `vector` - up to 2,000 dimensions - `halfvec` - up to 4,000 dimensions - `bit` - up to 64,000 dimensions -- `sparsevec` - up to 1,000 non-zero elements +- `sparsevec` - up to 1,200 non-zero elements ### Index Options diff --git a/src/hnsw.h b/src/hnsw.h index e8d1423ae..94853259a 100644 --- a/src/hnsw.h +++ b/src/hnsw.h @@ -27,7 +27,7 @@ typedef Pointer Item; #endif #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.out index 2a6fe7c90..bafd74b9d 100644 --- a/test/expected/hnsw_sparsevec.out +++ b/test/expected/hnsw_sparsevec.out @@ -101,12 +101,16 @@ 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); +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; +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.sql index 4ec07025f..518d2b84a 100644 --- a/test/sql/hnsw_sparsevec.sql +++ b/test/sql/hnsw_sparsevec.sql @@ -59,10 +59,15 @@ DROP TABLE t; -- non-zero elements -CREATE TABLE t (val sparsevec(1001)); -INSERT INTO t (val) VALUES (array_fill(1, ARRAY[1001])::vector::sparsevec); +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; + +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;

view thread (3+ messages)  latest in thread

Message-ID: <gh-pgvector-pgvector-994@github.com>
Permalink:  ../gh-pgvector-pgvector-994@github.com/

 ·  · 


This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox