From 3886593ae8b42e124b048a1ae310ae6060600c3d Mon Sep 17 00:00:00 2001 From: Congqi Xia Date: Sun, 26 Jan 2025 19:53:31 +0800 Subject: [PATCH] Update unit tests Signed-off-by: Congqi Xia --- internal/util/indexparamcheck/utils_test.go | 40 ++++++++++++--------- pkg/util/paramtable/autoindex_param.go | 8 ++--- pkg/util/paramtable/autoindex_param_test.go | 2 +- 3 files changed, 29 insertions(+), 21 deletions(-) diff --git a/internal/util/indexparamcheck/utils_test.go b/internal/util/indexparamcheck/utils_test.go index 2135c588958f8..f833005b86647 100644 --- a/internal/util/indexparamcheck/utils_test.go +++ b/internal/util/indexparamcheck/utils_test.go @@ -128,11 +128,12 @@ func Test_CheckAutoIndex(t *testing.T) { mgr.SetConfig("autoIndex.params.build", `{"M": 30,"efConstruction": 360,"index_type": "HNSW"}`) p := ¶mtable.AutoIndexConfig{ IndexParams: paramtable.ParamItem{ - Key: "autoIndex.params.build", + Key: "autoIndex.params.build", + Formatter: paramtable.GetBuildParamFormatter(paramtable.FloatVectorDefaultMetricType, "autoIndex.params.build"), }, } p.IndexParams.Init(mgr) - p.SetDefaultMetricTypeHelper(p.IndexParams.Key, p.IndexParams.GetAsJSONMap(), schemapb.DataType_FloatVector, mgr) + assert.NotPanics(t, func() { CheckAutoIndexHelper(p.IndexParams.Key, p.IndexParams.GetAsJSONMap(), schemapb.DataType_FloatVector) }) @@ -146,11 +147,12 @@ func Test_CheckAutoIndex(t *testing.T) { mgr.SetConfig("autoIndex.params.binary.build", `{"nlist": 1024, "index_type": "BIN_IVF_FLAT"}`) p := ¶mtable.AutoIndexConfig{ BinaryIndexParams: paramtable.ParamItem{ - Key: "autoIndex.params.binary.build", + Key: "autoIndex.params.binary.build", + Formatter: paramtable.GetBuildParamFormatter(paramtable.BinaryVectorDefaultMetricType, "autoIndex.params.binary.build"), }, } p.BinaryIndexParams.Init(mgr) - p.SetDefaultMetricTypeHelper(p.BinaryIndexParams.Key, p.BinaryIndexParams.GetAsJSONMap(), schemapb.DataType_BinaryVector, mgr) + assert.NotPanics(t, func() { CheckAutoIndexHelper(p.BinaryIndexParams.Key, p.BinaryIndexParams.GetAsJSONMap(), schemapb.DataType_BinaryVector) }) @@ -164,11 +166,12 @@ func Test_CheckAutoIndex(t *testing.T) { mgr.SetConfig("autoIndex.params.sparse.build", `{"index_type": "SPARSE_INVERTED_INDEX", "metric_type": "IP"}`) p := ¶mtable.AutoIndexConfig{ SparseIndexParams: paramtable.ParamItem{ - Key: "autoIndex.params.sparse.build", + Key: "autoIndex.params.sparse.build", + Formatter: paramtable.GetBuildParamFormatter(paramtable.SparseFloatVectorDefaultMetricType, "autoIndex.params.sparse.build"), }, } p.SparseIndexParams.Init(mgr) - p.SetDefaultMetricTypeHelper(p.SparseIndexParams.Key, p.SparseIndexParams.GetAsJSONMap(), schemapb.DataType_SparseFloatVector, mgr) + assert.NotPanics(t, func() { CheckAutoIndexHelper(p.SparseIndexParams.Key, p.SparseIndexParams.GetAsJSONMap(), schemapb.DataType_SparseFloatVector) }) @@ -182,11 +185,12 @@ func Test_CheckAutoIndex(t *testing.T) { mgr.SetConfig("autoIndex.params.build", `{"nlist": 30, "index_type": "IVF_FLAT"}`) p := ¶mtable.AutoIndexConfig{ IndexParams: paramtable.ParamItem{ - Key: "autoIndex.params.build", + Key: "autoIndex.params.build", + Formatter: paramtable.GetBuildParamFormatter(paramtable.FloatVectorDefaultMetricType, "autoIndex.params.build"), }, } p.IndexParams.Init(mgr) - p.SetDefaultMetricTypeHelper(p.IndexParams.Key, p.IndexParams.GetAsJSONMap(), schemapb.DataType_FloatVector, mgr) + assert.NotPanics(t, func() { CheckAutoIndexHelper(p.IndexParams.Key, p.IndexParams.GetAsJSONMap(), schemapb.DataType_FloatVector) }) @@ -200,11 +204,12 @@ func Test_CheckAutoIndex(t *testing.T) { mgr.SetConfig("autoIndex.params.build", `{"nlist": 30, "index_type": "IVF_FLAT"}`) p := ¶mtable.AutoIndexConfig{ IndexParams: paramtable.ParamItem{ - Key: "autoIndex.params.build", + Key: "autoIndex.params.build", + Formatter: paramtable.GetBuildParamFormatter(paramtable.FloatVectorDefaultMetricType, "autoIndex.params.build"), }, } p.IndexParams.Init(mgr) - p.SetDefaultMetricTypeHelper(p.IndexParams.Key, p.IndexParams.GetAsJSONMap(), schemapb.DataType_FloatVector, mgr) + assert.NotPanics(t, func() { CheckAutoIndexHelper(p.IndexParams.Key, p.IndexParams.GetAsJSONMap(), schemapb.DataType_FloatVector) }) @@ -218,11 +223,12 @@ func Test_CheckAutoIndex(t *testing.T) { mgr.SetConfig("autoIndex.params.build", `{"index_type": "DISKANN"}`) p := ¶mtable.AutoIndexConfig{ IndexParams: paramtable.ParamItem{ - Key: "autoIndex.params.build", + Key: "autoIndex.params.build", + Formatter: paramtable.GetBuildParamFormatter(paramtable.FloatVectorDefaultMetricType, "autoIndex.params.build"), }, } p.IndexParams.Init(mgr) - p.SetDefaultMetricTypeHelper(p.IndexParams.Key, p.IndexParams.GetAsJSONMap(), schemapb.DataType_FloatVector, mgr) + assert.NotPanics(t, func() { CheckAutoIndexHelper(p.IndexParams.Key, p.IndexParams.GetAsJSONMap(), schemapb.DataType_FloatVector) }) @@ -236,11 +242,12 @@ func Test_CheckAutoIndex(t *testing.T) { mgr.SetConfig("autoIndex.params.build", `{"index_type": "BIN_FLAT"}`) p := ¶mtable.AutoIndexConfig{ IndexParams: paramtable.ParamItem{ - Key: "autoIndex.params.build", + Key: "autoIndex.params.build", + Formatter: paramtable.GetBuildParamFormatter(paramtable.BinaryVectorDefaultMetricType, "autoIndex.params.binary.build"), }, } p.IndexParams.Init(mgr) - p.SetDefaultMetricTypeHelper(p.IndexParams.Key, p.IndexParams.GetAsJSONMap(), schemapb.DataType_BinaryVector, mgr) + assert.NotPanics(t, func() { CheckAutoIndexHelper(p.IndexParams.Key, p.IndexParams.GetAsJSONMap(), schemapb.DataType_BinaryVector) }) @@ -254,11 +261,12 @@ func Test_CheckAutoIndex(t *testing.T) { mgr.SetConfig("autoIndex.params.build", `{"nlist": 30, "index_type": "BIN_IVF_FLAT"}`) p := ¶mtable.AutoIndexConfig{ IndexParams: paramtable.ParamItem{ - Key: "autoIndex.params.build", + Key: "autoIndex.params.build", + Formatter: paramtable.GetBuildParamFormatter(paramtable.BinaryVectorDefaultMetricType, "autoIndex.params.binary.build"), }, } p.IndexParams.Init(mgr) - p.SetDefaultMetricTypeHelper(p.IndexParams.Key, p.IndexParams.GetAsJSONMap(), schemapb.DataType_BinaryVector, mgr) + assert.NotPanics(t, func() { CheckAutoIndexHelper(p.IndexParams.Key, p.IndexParams.GetAsJSONMap(), schemapb.DataType_BinaryVector) }) diff --git a/pkg/util/paramtable/autoindex_param.go b/pkg/util/paramtable/autoindex_param.go index a18da0cd94fe9..83c0334d2ca00 100644 --- a/pkg/util/paramtable/autoindex_param.go +++ b/pkg/util/paramtable/autoindex_param.go @@ -90,7 +90,7 @@ func (p *AutoIndexConfig) init(base *BaseTable) { Key: "autoIndex.params.build", Version: "2.2.0", DefaultValue: `{"M": 18,"efConstruction": 240,"index_type": "HNSW", "metric_type": "COSINE"}`, - Formatter: getBuildParamFormatter(FloatVectorDefaultMetricType, "autoIndex.params.build"), + Formatter: GetBuildParamFormatter(FloatVectorDefaultMetricType, "autoIndex.params.build"), Export: true, } p.IndexParams.Init(base.mgr) @@ -99,7 +99,7 @@ func (p *AutoIndexConfig) init(base *BaseTable) { Key: "autoIndex.params.sparse.build", Version: "2.4.5", DefaultValue: `{"index_type": "SPARSE_INVERTED_INDEX", "metric_type": "IP"}`, - Formatter: getBuildParamFormatter(SparseFloatVectorDefaultMetricType, "autoIndex.params.sparse.build"), + Formatter: GetBuildParamFormatter(SparseFloatVectorDefaultMetricType, "autoIndex.params.sparse.build"), Export: true, } p.SparseIndexParams.Init(base.mgr) @@ -108,7 +108,7 @@ func (p *AutoIndexConfig) init(base *BaseTable) { Key: "autoIndex.params.binary.build", Version: "2.4.5", DefaultValue: `{"nlist": 1024, "index_type": "BIN_IVF_FLAT", "metric_type": "HAMMING"}`, - Formatter: getBuildParamFormatter(BinaryVectorDefaultMetricType, "autoIndex.params.sparse.build"), + Formatter: GetBuildParamFormatter(BinaryVectorDefaultMetricType, "autoIndex.params.sparse.build"), Export: true, } p.BinaryIndexParams.Init(base.mgr) @@ -272,7 +272,7 @@ func SetDefaultMetricTypeIfNotExist(dType schemapb.DataType, params map[string]s } } -func getBuildParamFormatter(defaultMetricsType metric.MetricType, tag string) func(string) string { +func GetBuildParamFormatter(defaultMetricsType metric.MetricType, tag string) func(string) string { return func(originValue string) string { m, err := funcutil.JSONToMap(originValue) if err != nil { diff --git a/pkg/util/paramtable/autoindex_param_test.go b/pkg/util/paramtable/autoindex_param_test.go index b6a0190865fce..c4b217464582c 100644 --- a/pkg/util/paramtable/autoindex_param_test.go +++ b/pkg/util/paramtable/autoindex_param_test.go @@ -135,7 +135,7 @@ func Test_autoIndexConfig_panicIfNotValid(t *testing.T) { p := &AutoIndexConfig{ IndexParams: ParamItem{ Key: "autoIndex.params.build", - Formatter: getBuildParamFormatter(FloatVectorDefaultMetricType, "autoIndex.params.build"), + Formatter: GetBuildParamFormatter(FloatVectorDefaultMetricType, "autoIndex.params.build"), }, } p.IndexParams.Init(mgr)