From ed57650b528fb64ec966ac0dd53b1f14ff327644 Mon Sep 17 00:00:00 2001 From: foxspy Date: Wed, 23 Jul 2025 20:22:54 +0800 Subject: [PATCH] fix: remove invalid restrictions on dim for int8 vector (#43469) issue: #43466 Signed-off-by: xianliang.li --- internal/proxy/util.go | 12 +++++++----- internal/proxy/util_test.go | 25 +++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 5 deletions(-) diff --git a/internal/proxy/util.go b/internal/proxy/util.go index a69648ca7d..3f260f87f4 100644 --- a/internal/proxy/util.go +++ b/internal/proxy/util.go @@ -341,6 +341,7 @@ func validateDimension(field *schemapb.FieldSchema) error { break } } + // for sparse vector field, dim should not be specified if typeutil.IsSparseFloatVectorType(field.DataType) { if exist { return fmt.Errorf("dim should not be specified for sparse vector field %s(%d)", field.GetName(), field.FieldID) @@ -355,17 +356,18 @@ func validateDimension(field *schemapb.FieldSchema) error { return fmt.Errorf("invalid dimension: %d. should be in range 2 ~ %d", dim, Params.ProxyCfg.MaxDimension.GetAsInt()) } - if typeutil.IsFloatVectorType(field.DataType) { - if dim > Params.ProxyCfg.MaxDimension.GetAsInt64() { - return fmt.Errorf("invalid dimension: %d of field %s. float vector dimension should be in range 2 ~ %d", dim, field.GetName(), Params.ProxyCfg.MaxDimension.GetAsInt()) - } - } else { + // for dense vector field, dim will be limited by max_dimension + if typeutil.IsBinaryVectorType(field.DataType) { if dim%8 != 0 { return fmt.Errorf("invalid dimension: %d of field %s. binary vector dimension should be multiple of 8. ", dim, field.GetName()) } if dim > Params.ProxyCfg.MaxDimension.GetAsInt64()*8 { return fmt.Errorf("invalid dimension: %d of field %s. binary vector dimension should be in range 2 ~ %d", dim, field.GetName(), Params.ProxyCfg.MaxDimension.GetAsInt()*8) } + } else { + if dim > Params.ProxyCfg.MaxDimension.GetAsInt64() { + return fmt.Errorf("invalid dimension: %d of field %s. float vector dimension should be in range 2 ~ %d", dim, field.GetName(), Params.ProxyCfg.MaxDimension.GetAsInt()) + } } return nil } diff --git a/internal/proxy/util_test.go b/internal/proxy/util_test.go index e0eb78c478..3ca0c1c654 100644 --- a/internal/proxy/util_test.go +++ b/internal/proxy/util_test.go @@ -262,6 +262,31 @@ func TestValidateDimension(t *testing.T) { }, } assert.NotNil(t, validateDimension(fieldSchema)) + + fieldSchema.DataType = schemapb.DataType_Int8Vector + fieldSchema.TypeParams = []*commonpb.KeyValuePair{ + { + Key: common.DimKey, + Value: "200", + }, + } + assert.Nil(t, validateDimension(fieldSchema)) + + fieldSchema.TypeParams = []*commonpb.KeyValuePair{ + { + Key: common.DimKey, + Value: "201", + }, + } + assert.Nil(t, validateDimension(fieldSchema)) + + fieldSchema.TypeParams = []*commonpb.KeyValuePair{ + { + Key: common.DimKey, + Value: strconv.Itoa(int(Params.ProxyCfg.MaxDimension.GetAsInt32() + 1)), + }, + } + assert.NotNil(t, validateDimension(fieldSchema)) } func TestValidateVectorFieldMetricType(t *testing.T) {