From bbf91bfabe0fe2268cef082c701b461792137199 Mon Sep 17 00:00:00 2001 From: Andrew Kane Date: Tue, 1 Dec 2026 21:18:34 -0800 Subject: [PATCH] Added hint to max dimensions error [skip ci] --- src/hnswbuild.c | 12 +++++++++++- src/ivfbuild.c | 12 +++++++++++- test/expected/hnsw_halfvec.out | 1 + test/expected/hnsw_vector.out | 6 ++++++ test/expected/ivfflat_halfvec.out | 1 + test/expected/ivfflat_vector.out | 6 ++++++ test/sql/hnsw_vector.sql | 4 ++++ test/sql/ivfflat_vector.sql | 4 ++++ 8 files changed, 44 insertions(+), 2 deletions(-) diff --git a/src/hnswbuild.c b/src/hnswbuild.c index 28b2b10d..02db6586 100644 --- a/src/hnswbuild.c +++ b/src/hnswbuild.c @@ -705,9 +705,19 @@ InitBuildState(HnswBuildState * buildstate, Relation heap, Relation index, Index errmsg("column does not have dimensions"))); if (buildstate->dimensions > buildstate->typeInfo->maxDimensions) + { + char *hint = NULL; + + if (buildstate->dimensions <= HNSW_MAX_DIM * 2) + hint = "Use halfvec or binary quantization."; + else if (buildstate->dimensions <= HNSW_MAX_DIM * 32) + hint = "Use binary quantization if possible."; + ereport(ERROR, (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED), - errmsg("%s column cannot have more than %d dimensions for hnsw index", buildstate->typeInfo->typeName, buildstate->typeInfo->maxDimensions))); + errmsg("%s column cannot have more than %d dimensions for hnsw index", buildstate->typeInfo->typeName, buildstate->typeInfo->maxDimensions), + (hint != NULL ? errhint("%s", hint) : 0))); + } if (buildstate->efConstruction / 2 < buildstate->m) ereport(ERROR, diff --git a/src/ivfbuild.c b/src/ivfbuild.c index 8f86af29..ab50f787 100644 --- a/src/ivfbuild.c +++ b/src/ivfbuild.c @@ -352,9 +352,19 @@ InitBuildState(IvfflatBuildState * buildstate, Relation heap, Relation index, In errmsg("column does not have dimensions"))); if (buildstate->dimensions > buildstate->typeInfo->maxDimensions) + { + char *hint = NULL; + + if (buildstate->dimensions <= IVFFLAT_MAX_DIM * 2) + hint = "Use halfvec or binary quantization."; + else if (buildstate->dimensions <= IVFFLAT_MAX_DIM * 32) + hint = "Use binary quantization if possible."; + ereport(ERROR, (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED), - errmsg("%s column cannot have more than %d dimensions for ivfflat index", buildstate->typeInfo->typeName, buildstate->typeInfo->maxDimensions))); + errmsg("%s column cannot have more than %d dimensions for ivfflat index", buildstate->typeInfo->typeName, buildstate->typeInfo->maxDimensions), + (hint != NULL ? errhint("%s", hint) : 0))); + } buildstate->reltuples = 0; buildstate->indtuples = 0; diff --git a/test/expected/hnsw_halfvec.out b/test/expected/hnsw_halfvec.out index 1f42346e..139722f5 100644 --- a/test/expected/hnsw_halfvec.out +++ b/test/expected/hnsw_halfvec.out @@ -107,4 +107,5 @@ DROP TABLE t; CREATE TABLE t (val halfvec(4001)); CREATE INDEX ON t USING hnsw (val halfvec_l2_ops); ERROR: halfvec column cannot have more than 4000 dimensions for hnsw index +HINT: Use binary quantization if possible. DROP TABLE t; diff --git a/test/expected/hnsw_vector.out b/test/expected/hnsw_vector.out index 8f909c09..1641f040 100644 --- a/test/expected/hnsw_vector.out +++ b/test/expected/hnsw_vector.out @@ -215,6 +215,12 @@ DROP TABLE t; CREATE TABLE t (val vector(2001)); CREATE INDEX ON t USING hnsw (val vector_l2_ops); ERROR: vector column cannot have more than 2000 dimensions for hnsw index +HINT: Use halfvec or binary quantization. +DROP TABLE t; +CREATE TABLE t (val vector(4001)); +CREATE INDEX ON t USING hnsw (val vector_l2_ops); +ERROR: vector column cannot have more than 2000 dimensions for hnsw index +HINT: Use binary quantization if possible. DROP TABLE t; -- properties SELECT pg_indexam_has_property(oid, 'distance_orderable') FROM pg_am WHERE amname = 'hnsw'; diff --git a/test/expected/ivfflat_halfvec.out b/test/expected/ivfflat_halfvec.out index 60ddb10b..1cbac3cc 100644 --- a/test/expected/ivfflat_halfvec.out +++ b/test/expected/ivfflat_halfvec.out @@ -92,6 +92,7 @@ DROP TABLE t; CREATE TABLE t (val halfvec(4001)); CREATE INDEX ON t USING ivfflat (val halfvec_l2_ops); ERROR: halfvec column cannot have more than 4000 dimensions for ivfflat index +HINT: Use binary quantization if possible. DROP TABLE t; -- memory SET maintenance_work_mem = '1MB'; diff --git a/test/expected/ivfflat_vector.out b/test/expected/ivfflat_vector.out index eae7ace3..796218c1 100644 --- a/test/expected/ivfflat_vector.out +++ b/test/expected/ivfflat_vector.out @@ -191,6 +191,12 @@ DROP TABLE t; CREATE TABLE t (val vector(2001)); CREATE INDEX ON t USING ivfflat (val vector_l2_ops); ERROR: vector column cannot have more than 2000 dimensions for ivfflat index +HINT: Use halfvec or binary quantization. +DROP TABLE t; +CREATE TABLE t (val vector(4001)); +CREATE INDEX ON t USING ivfflat (val vector_l2_ops); +ERROR: vector column cannot have more than 2000 dimensions for ivfflat index +HINT: Use binary quantization if possible. DROP TABLE t; -- memory SET maintenance_work_mem = '1MB'; diff --git a/test/sql/hnsw_vector.sql b/test/sql/hnsw_vector.sql index eb2d192e..d5ce4042 100644 --- a/test/sql/hnsw_vector.sql +++ b/test/sql/hnsw_vector.sql @@ -123,6 +123,10 @@ CREATE TABLE t (val vector(2001)); CREATE INDEX ON t USING hnsw (val vector_l2_ops); DROP TABLE t; +CREATE TABLE t (val vector(4001)); +CREATE INDEX ON t USING hnsw (val vector_l2_ops); +DROP TABLE t; + -- properties SELECT pg_indexam_has_property(oid, 'distance_orderable') FROM pg_am WHERE amname = 'hnsw'; diff --git a/test/sql/ivfflat_vector.sql b/test/sql/ivfflat_vector.sql index 416bc8e8..70e3f5f5 100644 --- a/test/sql/ivfflat_vector.sql +++ b/test/sql/ivfflat_vector.sql @@ -105,6 +105,10 @@ CREATE TABLE t (val vector(2001)); CREATE INDEX ON t USING ivfflat (val vector_l2_ops); DROP TABLE t; +CREATE TABLE t (val vector(4001)); +CREATE INDEX ON t USING ivfflat (val vector_l2_ops); +DROP TABLE t; + -- memory SET maintenance_work_mem = '1MB';