forked from milvus-io/milvus
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ScaNN index param checker (milvus-io#27268)
Signed-off-by: chasingegg <[email protected]>
- Loading branch information
1 parent
206cc14
commit ab2d8dd
Showing
6 changed files
with
216 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package indexparamcheck | ||
|
||
import ( | ||
"fmt" | ||
"strconv" | ||
) | ||
|
||
// scaNNChecker checks if a SCANN index can be built. | ||
type scaNNChecker struct { | ||
ivfBaseChecker | ||
} | ||
|
||
// CheckTrain checks if SCANN index can be built with the specific index parameters. | ||
func (c *scaNNChecker) CheckTrain(params map[string]string) error { | ||
if err := c.ivfBaseChecker.CheckTrain(params); err != nil { | ||
return err | ||
} | ||
|
||
return c.checkScaNNParams(params) | ||
} | ||
|
||
func (c *scaNNChecker) checkScaNNParams(params map[string]string) error { | ||
dimStr, dimensionExist := params[DIM] | ||
if !dimensionExist { | ||
return fmt.Errorf("dimension not found") | ||
} | ||
|
||
dimension, err := strconv.Atoi(dimStr) | ||
if err != nil { // invalid dimension | ||
return fmt.Errorf("invalid dimension: %s", dimStr) | ||
} | ||
|
||
if (dimension % 2) != 0 { | ||
return fmt.Errorf("dimension must be able to be divided by 2, dimension: %d", dimension) | ||
} | ||
return nil | ||
} | ||
|
||
func newScaNNChecker() IndexChecker { | ||
return &scaNNChecker{} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,170 @@ | ||
package indexparamcheck | ||
|
||
import ( | ||
"strconv" | ||
"testing" | ||
|
||
"github.com/milvus-io/milvus-proto/go-api/v2/schemapb" | ||
"github.com/milvus-io/milvus/pkg/util/metric" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func Test_scaNNChecker_CheckTrain(t *testing.T) { | ||
validParams := map[string]string{ | ||
DIM: strconv.Itoa(128), | ||
NLIST: strconv.Itoa(1024), | ||
Metric: metric.L2, | ||
} | ||
|
||
paramsNotMultiplier := map[string]string{ | ||
DIM: strconv.Itoa(127), | ||
NLIST: strconv.Itoa(1024), | ||
Metric: metric.L2, | ||
} | ||
|
||
validParamsWithoutDim := map[string]string{ | ||
NLIST: strconv.Itoa(1024), | ||
Metric: metric.L2, | ||
} | ||
|
||
invalidParamsDim := copyParams(validParams) | ||
invalidParamsDim[DIM] = "NAN" | ||
|
||
p1 := map[string]string{ | ||
DIM: strconv.Itoa(128), | ||
NLIST: strconv.Itoa(1024), | ||
Metric: metric.L2, | ||
} | ||
p2 := map[string]string{ | ||
DIM: strconv.Itoa(128), | ||
NLIST: strconv.Itoa(1024), | ||
Metric: metric.IP, | ||
} | ||
p3 := map[string]string{ | ||
DIM: strconv.Itoa(128), | ||
NLIST: strconv.Itoa(1024), | ||
Metric: metric.COSINE, | ||
} | ||
|
||
p4 := map[string]string{ | ||
DIM: strconv.Itoa(128), | ||
NLIST: strconv.Itoa(1024), | ||
Metric: metric.HAMMING, | ||
} | ||
p5 := map[string]string{ | ||
DIM: strconv.Itoa(128), | ||
NLIST: strconv.Itoa(1024), | ||
Metric: metric.JACCARD, | ||
} | ||
p6 := map[string]string{ | ||
DIM: strconv.Itoa(128), | ||
NLIST: strconv.Itoa(1024), | ||
Metric: metric.SUBSTRUCTURE, | ||
} | ||
p7 := map[string]string{ | ||
DIM: strconv.Itoa(128), | ||
NLIST: strconv.Itoa(1024), | ||
Metric: metric.SUPERSTRUCTURE, | ||
} | ||
|
||
cases := []struct { | ||
params map[string]string | ||
errIsNil bool | ||
}{ | ||
{validParams, true}, | ||
{paramsNotMultiplier, false}, | ||
{invalidIVFParamsMin(), false}, | ||
{invalidIVFParamsMax(), false}, | ||
{validParamsWithoutDim, false}, | ||
{invalidParamsDim, false}, | ||
{p1, true}, | ||
{p2, true}, | ||
{p3, true}, | ||
{p4, false}, | ||
{p5, false}, | ||
{p6, false}, | ||
{p7, false}, | ||
} | ||
|
||
c := newScaNNChecker() | ||
for _, test := range cases { | ||
err := c.CheckTrain(test.params) | ||
if test.errIsNil { | ||
assert.NoError(t, err) | ||
} else { | ||
assert.Error(t, err) | ||
} | ||
} | ||
} | ||
|
||
func Test_scaNNChecker_CheckValidDataType(t *testing.T) { | ||
|
||
cases := []struct { | ||
dType schemapb.DataType | ||
errIsNil bool | ||
}{ | ||
{ | ||
dType: schemapb.DataType_Bool, | ||
errIsNil: false, | ||
}, | ||
{ | ||
dType: schemapb.DataType_Int8, | ||
errIsNil: false, | ||
}, | ||
{ | ||
dType: schemapb.DataType_Int16, | ||
errIsNil: false, | ||
}, | ||
{ | ||
dType: schemapb.DataType_Int32, | ||
errIsNil: false, | ||
}, | ||
{ | ||
dType: schemapb.DataType_Int64, | ||
errIsNil: false, | ||
}, | ||
{ | ||
dType: schemapb.DataType_Float, | ||
errIsNil: false, | ||
}, | ||
{ | ||
dType: schemapb.DataType_Double, | ||
errIsNil: false, | ||
}, | ||
{ | ||
dType: schemapb.DataType_String, | ||
errIsNil: false, | ||
}, | ||
{ | ||
dType: schemapb.DataType_VarChar, | ||
errIsNil: false, | ||
}, | ||
{ | ||
dType: schemapb.DataType_Array, | ||
errIsNil: false, | ||
}, | ||
{ | ||
dType: schemapb.DataType_JSON, | ||
errIsNil: false, | ||
}, | ||
{ | ||
dType: schemapb.DataType_FloatVector, | ||
errIsNil: true, | ||
}, | ||
{ | ||
dType: schemapb.DataType_BinaryVector, | ||
errIsNil: false, | ||
}, | ||
} | ||
|
||
c := newScaNNChecker() | ||
for _, test := range cases { | ||
err := c.CheckValidDataType(test.dType) | ||
if test.errIsNil { | ||
assert.NoError(t, err) | ||
} else { | ||
assert.Error(t, err) | ||
} | ||
} | ||
} |