Skip to content

Commit

Permalink
Update unit tests
Browse files Browse the repository at this point in the history
Signed-off-by: Congqi Xia <[email protected]>
  • Loading branch information
congqixia committed Jan 26, 2025
1 parent 3eacac5 commit 3886593
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 21 deletions.
40 changes: 24 additions & 16 deletions internal/util/indexparamcheck/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,12 @@ func Test_CheckAutoIndex(t *testing.T) {
mgr.SetConfig("autoIndex.params.build", `{"M": 30,"efConstruction": 360,"index_type": "HNSW"}`)
p := &paramtable.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)
})
Expand All @@ -146,11 +147,12 @@ func Test_CheckAutoIndex(t *testing.T) {
mgr.SetConfig("autoIndex.params.binary.build", `{"nlist": 1024, "index_type": "BIN_IVF_FLAT"}`)
p := &paramtable.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)
})
Expand All @@ -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 := &paramtable.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)
})
Expand All @@ -182,11 +185,12 @@ func Test_CheckAutoIndex(t *testing.T) {
mgr.SetConfig("autoIndex.params.build", `{"nlist": 30, "index_type": "IVF_FLAT"}`)
p := &paramtable.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)
})
Expand All @@ -200,11 +204,12 @@ func Test_CheckAutoIndex(t *testing.T) {
mgr.SetConfig("autoIndex.params.build", `{"nlist": 30, "index_type": "IVF_FLAT"}`)
p := &paramtable.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)
})
Expand All @@ -218,11 +223,12 @@ func Test_CheckAutoIndex(t *testing.T) {
mgr.SetConfig("autoIndex.params.build", `{"index_type": "DISKANN"}`)
p := &paramtable.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)
})
Expand All @@ -236,11 +242,12 @@ func Test_CheckAutoIndex(t *testing.T) {
mgr.SetConfig("autoIndex.params.build", `{"index_type": "BIN_FLAT"}`)
p := &paramtable.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)
})
Expand All @@ -254,11 +261,12 @@ func Test_CheckAutoIndex(t *testing.T) {
mgr.SetConfig("autoIndex.params.build", `{"nlist": 30, "index_type": "BIN_IVF_FLAT"}`)
p := &paramtable.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)
})
Expand Down
8 changes: 4 additions & 4 deletions pkg/util/paramtable/autoindex_param.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion pkg/util/paramtable/autoindex_param_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 3886593

Please sign in to comment.