mirror of
https://gitee.com/milvus-io/milvus.git
synced 2024-12-02 20:09:57 +08:00
Unittest for indexparamcheck (#7464)
Signed-off-by: yhmo <yihua.mo@zilliz.com>
This commit is contained in:
parent
acf4354b83
commit
229965a9bb
@ -19,6 +19,32 @@ import (
|
||||
// TODO: add more test cases which `ConfAdapter.CheckTrain` return false,
|
||||
// for example, maybe we can copy test cases from regression test later.
|
||||
|
||||
func invalidIVFParamsMin() map[string]string {
|
||||
invalidIVFParams := map[string]string{
|
||||
DIM: strconv.Itoa(128),
|
||||
NLIST: strconv.Itoa(MinNList - 1),
|
||||
Metric: L2,
|
||||
}
|
||||
return invalidIVFParams
|
||||
}
|
||||
|
||||
func invalidIVFParamsMax() map[string]string {
|
||||
invalidIVFParams := map[string]string{
|
||||
DIM: strconv.Itoa(128),
|
||||
NLIST: strconv.Itoa(MaxNList + 1),
|
||||
Metric: L2,
|
||||
}
|
||||
return invalidIVFParams
|
||||
}
|
||||
|
||||
func copyParams(original map[string]string) map[string]string {
|
||||
result := make(map[string]string)
|
||||
for key, value := range original {
|
||||
result[key] = value
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
func TestBaseConfAdapter_CheckTrain(t *testing.T) {
|
||||
validParams := map[string]string{
|
||||
DIM: strconv.Itoa(128),
|
||||
@ -45,11 +71,14 @@ func TestIVFConfAdapter_CheckTrain(t *testing.T) {
|
||||
NLIST: strconv.Itoa(1024),
|
||||
Metric: L2,
|
||||
}
|
||||
|
||||
cases := []struct {
|
||||
params map[string]string
|
||||
want bool
|
||||
}{
|
||||
{validParams, true},
|
||||
{invalidIVFParamsMin(), false},
|
||||
{invalidIVFParamsMax(), false},
|
||||
}
|
||||
|
||||
adapter := newIVFConfAdapter()
|
||||
@ -68,6 +97,7 @@ func TestIVFPQConfAdapter_CheckTrain(t *testing.T) {
|
||||
NBITS: strconv.Itoa(8),
|
||||
Metric: L2,
|
||||
}
|
||||
|
||||
validParamsWithoutNbits := map[string]string{
|
||||
DIM: strconv.Itoa(128),
|
||||
NLIST: strconv.Itoa(1024),
|
||||
@ -75,12 +105,47 @@ func TestIVFPQConfAdapter_CheckTrain(t *testing.T) {
|
||||
Metric: L2,
|
||||
}
|
||||
|
||||
validParamsWithoutDim := map[string]string{
|
||||
NLIST: strconv.Itoa(1024),
|
||||
IVFM: strconv.Itoa(4),
|
||||
NBITS: strconv.Itoa(8),
|
||||
Metric: L2,
|
||||
}
|
||||
|
||||
invalidParamsDim := copyParams(validParams)
|
||||
invalidParamsDim[DIM] = "NAN"
|
||||
|
||||
invalidParamsNbits := copyParams(validParams)
|
||||
invalidParamsNbits[NBITS] = "NAN"
|
||||
|
||||
invalidParamsWithoutIVF := map[string]string{
|
||||
DIM: strconv.Itoa(128),
|
||||
NLIST: strconv.Itoa(1024),
|
||||
NBITS: strconv.Itoa(8),
|
||||
Metric: L2,
|
||||
}
|
||||
|
||||
invalidParamsIVF := copyParams(validParams)
|
||||
invalidParamsIVF[IVFM] = "NAN"
|
||||
|
||||
invalidParamsM := copyParams(validParams)
|
||||
invalidParamsM[IndexMode] = GPUMode
|
||||
invalidParamsM[DIM] = strconv.Itoa(65536)
|
||||
|
||||
cases := []struct {
|
||||
params map[string]string
|
||||
want bool
|
||||
}{
|
||||
{validParams, true},
|
||||
{validParamsWithoutNbits, true},
|
||||
{invalidIVFParamsMin(), false},
|
||||
{invalidIVFParamsMax(), false},
|
||||
{validParamsWithoutDim, true},
|
||||
{invalidParamsDim, false},
|
||||
{invalidParamsNbits, false},
|
||||
{invalidParamsWithoutIVF, false},
|
||||
{invalidParamsIVF, false},
|
||||
{invalidParamsM, false},
|
||||
}
|
||||
|
||||
adapter := newIVFPQConfAdapter()
|
||||
@ -103,6 +168,8 @@ func TestIVFSQConfAdapter_CheckTrain(t *testing.T) {
|
||||
want bool
|
||||
}{
|
||||
{validParams, true},
|
||||
{invalidIVFParamsMin(), false},
|
||||
{invalidIVFParamsMax(), false},
|
||||
}
|
||||
|
||||
adapter := newIVFSQConfAdapter()
|
||||
@ -141,11 +208,18 @@ func TestBinIVFConfAdapter_CheckTrain(t *testing.T) {
|
||||
NBITS: strconv.Itoa(8),
|
||||
Metric: JACCARD,
|
||||
}
|
||||
|
||||
invalidParams := copyParams(validParams)
|
||||
invalidParams[Metric] = L2
|
||||
|
||||
cases := []struct {
|
||||
params map[string]string
|
||||
want bool
|
||||
}{
|
||||
{validParams, true},
|
||||
{invalidIVFParamsMin(), false},
|
||||
{invalidIVFParamsMax(), false},
|
||||
{invalidParams, false},
|
||||
}
|
||||
|
||||
adapter := newBinIVFConfAdapter()
|
||||
@ -166,11 +240,48 @@ func TestNSGConfAdapter_CheckTrain(t *testing.T) {
|
||||
CANDIDATE: strconv.Itoa(100),
|
||||
Metric: L2,
|
||||
}
|
||||
|
||||
invalidMatricParams := copyParams(validParams)
|
||||
invalidMatricParams[Metric] = JACCARD
|
||||
|
||||
invalidKNNGParamsMin := copyParams(validParams)
|
||||
invalidKNNGParamsMin[KNNG] = strconv.Itoa(MinKNNG - 1)
|
||||
|
||||
invalidKNNGParamsMax := copyParams(validParams)
|
||||
invalidKNNGParamsMax[KNNG] = strconv.Itoa(MaxKNNG + 1)
|
||||
|
||||
invalidLengthParamsMin := copyParams(validParams)
|
||||
invalidLengthParamsMin[SearchLength] = strconv.Itoa(MinSearchLength - 1)
|
||||
|
||||
invalidLengthParamsMax := copyParams(validParams)
|
||||
invalidLengthParamsMax[SearchLength] = strconv.Itoa(MaxSearchLength + 1)
|
||||
|
||||
invalidDegreeParamsMin := copyParams(validParams)
|
||||
invalidDegreeParamsMin[OutDegree] = strconv.Itoa(MinOutDegree - 1)
|
||||
|
||||
invalidDegreeParamsMax := copyParams(validParams)
|
||||
invalidDegreeParamsMax[OutDegree] = strconv.Itoa(MaxOutDegree + 1)
|
||||
|
||||
invalidPoolParamsMin := copyParams(validParams)
|
||||
invalidPoolParamsMin[CANDIDATE] = strconv.Itoa(MinCandidatePoolSize - 1)
|
||||
|
||||
invalidPoolParamsMax := copyParams(validParams)
|
||||
invalidPoolParamsMax[CANDIDATE] = strconv.Itoa(MaxCandidatePoolSize + 1)
|
||||
|
||||
cases := []struct {
|
||||
params map[string]string
|
||||
want bool
|
||||
}{
|
||||
{validParams, true},
|
||||
{invalidMatricParams, false},
|
||||
{invalidKNNGParamsMin, false},
|
||||
{invalidKNNGParamsMax, false},
|
||||
{invalidLengthParamsMin, false},
|
||||
{invalidLengthParamsMax, false},
|
||||
{invalidDegreeParamsMin, false},
|
||||
{invalidDegreeParamsMax, false},
|
||||
{invalidPoolParamsMin, false},
|
||||
{invalidPoolParamsMax, false},
|
||||
}
|
||||
|
||||
adapter := newNSGConfAdapter()
|
||||
@ -188,11 +299,28 @@ func TestHNSWConfAdapter_CheckTrain(t *testing.T) {
|
||||
EFConstruction: strconv.Itoa(200),
|
||||
Metric: L2,
|
||||
}
|
||||
|
||||
invalidEfParamsMin := copyParams(validParams)
|
||||
invalidEfParamsMin[EFConstruction] = strconv.Itoa(HNSWMinEfConstruction - 1)
|
||||
|
||||
invalidEfParamsMax := copyParams(validParams)
|
||||
invalidEfParamsMax[EFConstruction] = strconv.Itoa(HNSWMaxEfConstruction + 1)
|
||||
|
||||
invalidMParamsMin := copyParams(validParams)
|
||||
invalidMParamsMin[HNSWM] = strconv.Itoa(HNSWMinM - 1)
|
||||
|
||||
invalidMParamsMax := copyParams(validParams)
|
||||
invalidMParamsMax[HNSWM] = strconv.Itoa(HNSWMaxM + 1)
|
||||
|
||||
cases := []struct {
|
||||
params map[string]string
|
||||
want bool
|
||||
}{
|
||||
{validParams, true},
|
||||
{invalidEfParamsMin, false},
|
||||
{invalidEfParamsMax, false},
|
||||
{invalidMParamsMin, false},
|
||||
{invalidMParamsMax, false},
|
||||
}
|
||||
|
||||
adapter := newHNSWConfAdapter()
|
||||
@ -209,11 +337,20 @@ func TestANNOYConfAdapter_CheckTrain(t *testing.T) {
|
||||
NTREES: strconv.Itoa(4),
|
||||
Metric: L2,
|
||||
}
|
||||
|
||||
invalidTreeParamsMin := copyParams(validParams)
|
||||
invalidTreeParamsMin[NTREES] = strconv.Itoa(MinNTrees - 1)
|
||||
|
||||
invalidTreeParamsMax := copyParams(validParams)
|
||||
invalidTreeParamsMax[NTREES] = strconv.Itoa(MaxNTrees + 1)
|
||||
|
||||
cases := []struct {
|
||||
params map[string]string
|
||||
want bool
|
||||
}{
|
||||
{validParams, true},
|
||||
{invalidTreeParamsMin, false},
|
||||
{invalidTreeParamsMax, false},
|
||||
}
|
||||
|
||||
adapter := newANNOYConfAdapter()
|
||||
@ -231,11 +368,28 @@ func TestRHNSWFlatConfAdapter_CheckTrain(t *testing.T) {
|
||||
EFConstruction: strconv.Itoa(200),
|
||||
Metric: L2,
|
||||
}
|
||||
|
||||
invalidEfParamsMin := copyParams(validParams)
|
||||
invalidEfParamsMin[EFConstruction] = strconv.Itoa(HNSWMinEfConstruction - 1)
|
||||
|
||||
invalidEfParamsMax := copyParams(validParams)
|
||||
invalidEfParamsMax[EFConstruction] = strconv.Itoa(HNSWMaxEfConstruction + 1)
|
||||
|
||||
invalidMParamsMin := copyParams(validParams)
|
||||
invalidMParamsMin[HNSWM] = strconv.Itoa(HNSWMinM - 1)
|
||||
|
||||
invalidMParamsMax := copyParams(validParams)
|
||||
invalidMParamsMax[HNSWM] = strconv.Itoa(HNSWMaxM + 1)
|
||||
|
||||
cases := []struct {
|
||||
params map[string]string
|
||||
want bool
|
||||
}{
|
||||
{validParams, true},
|
||||
{invalidEfParamsMin, false},
|
||||
{invalidEfParamsMax, false},
|
||||
{invalidMParamsMin, false},
|
||||
{invalidMParamsMax, false},
|
||||
}
|
||||
|
||||
adapter := newRHNSWFlatConfAdapter()
|
||||
@ -254,11 +408,44 @@ func TestRHNSWPQConfAdapter_CheckTrain(t *testing.T) {
|
||||
EFConstruction: strconv.Itoa(200),
|
||||
Metric: L2,
|
||||
}
|
||||
|
||||
invalidMatricParams := copyParams(validParams)
|
||||
invalidMatricParams[Metric] = JACCARD
|
||||
|
||||
invalidEfParamsMin := copyParams(validParams)
|
||||
invalidEfParamsMin[EFConstruction] = strconv.Itoa(HNSWMinEfConstruction - 1)
|
||||
|
||||
invalidEfParamsMax := copyParams(validParams)
|
||||
invalidEfParamsMax[EFConstruction] = strconv.Itoa(HNSWMaxEfConstruction + 1)
|
||||
|
||||
invalidMParamsMin := copyParams(validParams)
|
||||
invalidMParamsMin[HNSWM] = strconv.Itoa(HNSWMinM - 1)
|
||||
|
||||
invalidMParamsMax := copyParams(validParams)
|
||||
invalidMParamsMax[HNSWM] = strconv.Itoa(HNSWMaxM + 1)
|
||||
|
||||
invalidParamsWithoutPQM := map[string]string{
|
||||
DIM: strconv.Itoa(128),
|
||||
HNSWM: strconv.Itoa(16),
|
||||
EFConstruction: strconv.Itoa(200),
|
||||
Metric: L2,
|
||||
}
|
||||
|
||||
invalidParamsPQM := copyParams(validParams)
|
||||
invalidParamsPQM[PQM] = "NAN"
|
||||
|
||||
cases := []struct {
|
||||
params map[string]string
|
||||
want bool
|
||||
}{
|
||||
{validParams, true},
|
||||
{invalidMatricParams, false},
|
||||
{invalidEfParamsMin, false},
|
||||
{invalidEfParamsMax, false},
|
||||
{invalidMParamsMin, false},
|
||||
{invalidMParamsMax, false},
|
||||
{invalidParamsWithoutPQM, false},
|
||||
{invalidParamsPQM, false},
|
||||
}
|
||||
|
||||
adapter := newRHNSWPQConfAdapter()
|
||||
@ -276,11 +463,28 @@ func TestRHNSWSQConfAdapter_CheckTrain(t *testing.T) {
|
||||
EFConstruction: strconv.Itoa(200),
|
||||
Metric: L2,
|
||||
}
|
||||
|
||||
invalidEfParamsMin := copyParams(validParams)
|
||||
invalidEfParamsMin[EFConstruction] = strconv.Itoa(HNSWMinEfConstruction - 1)
|
||||
|
||||
invalidEfParamsMax := copyParams(validParams)
|
||||
invalidEfParamsMax[EFConstruction] = strconv.Itoa(HNSWMaxEfConstruction + 1)
|
||||
|
||||
invalidMParamsMin := copyParams(validParams)
|
||||
invalidMParamsMin[HNSWM] = strconv.Itoa(HNSWMinM - 1)
|
||||
|
||||
invalidMParamsMax := copyParams(validParams)
|
||||
invalidMParamsMax[HNSWM] = strconv.Itoa(HNSWMaxM + 1)
|
||||
|
||||
cases := []struct {
|
||||
params map[string]string
|
||||
want bool
|
||||
}{
|
||||
{validParams, true},
|
||||
{invalidEfParamsMin, false},
|
||||
{invalidEfParamsMax, false},
|
||||
{invalidMParamsMin, false},
|
||||
{invalidMParamsMax, false},
|
||||
}
|
||||
|
||||
adapter := newRHNSWSQConfAdapter()
|
||||
@ -299,11 +503,41 @@ func TestNGTPANNGConfAdapter_CheckTrain(t *testing.T) {
|
||||
SelectivelyPrunedEdgeSize: strconv.Itoa(30),
|
||||
Metric: L2,
|
||||
}
|
||||
|
||||
invalidEdgeSizeParamsMin := copyParams(validParams)
|
||||
invalidEdgeSizeParamsMin[EdgeSize] = strconv.Itoa(NgtMinEdgeSize - 1)
|
||||
|
||||
invalidEdgeSizeParamsMax := copyParams(validParams)
|
||||
invalidEdgeSizeParamsMax[EdgeSize] = strconv.Itoa(NgtMaxEdgeSize + 1)
|
||||
|
||||
invalidFPEdgeSizeParamsMin := copyParams(validParams)
|
||||
invalidFPEdgeSizeParamsMin[ForcedlyPrunedEdgeSize] = strconv.Itoa(NgtMinEdgeSize - 1)
|
||||
|
||||
invalidFPEdgeSizeParamsMax := copyParams(validParams)
|
||||
invalidFPEdgeSizeParamsMax[ForcedlyPrunedEdgeSize] = strconv.Itoa(NgtMaxEdgeSize + 1)
|
||||
|
||||
invalidSPEdgeSizeParamsMin := copyParams(validParams)
|
||||
invalidSPEdgeSizeParamsMin[SelectivelyPrunedEdgeSize] = strconv.Itoa(NgtMinEdgeSize - 1)
|
||||
|
||||
invalidSPEdgeSizeParamsMax := copyParams(validParams)
|
||||
invalidSPEdgeSizeParamsMax[SelectivelyPrunedEdgeSize] = strconv.Itoa(NgtMaxEdgeSize + 1)
|
||||
|
||||
invalidSPFPParams := copyParams(validParams)
|
||||
invalidSPFPParams[SelectivelyPrunedEdgeSize] = strconv.Itoa(60)
|
||||
invalidSPFPParams[ForcedlyPrunedEdgeSize] = strconv.Itoa(30)
|
||||
|
||||
cases := []struct {
|
||||
params map[string]string
|
||||
want bool
|
||||
}{
|
||||
{validParams, true},
|
||||
{invalidEdgeSizeParamsMin, false},
|
||||
{invalidEdgeSizeParamsMax, false},
|
||||
{invalidFPEdgeSizeParamsMin, false},
|
||||
{invalidFPEdgeSizeParamsMax, false},
|
||||
{invalidSPEdgeSizeParamsMin, false},
|
||||
{invalidSPEdgeSizeParamsMax, false},
|
||||
{invalidSPFPParams, false},
|
||||
}
|
||||
|
||||
adapter := newNGTPANNGConfAdapter()
|
||||
@ -322,11 +556,36 @@ func TestNGTONNGConfAdapter_CheckTrain(t *testing.T) {
|
||||
IncomingEdgeSize: strconv.Itoa(40),
|
||||
Metric: L2,
|
||||
}
|
||||
|
||||
invalidEdgeSizeParamsMin := copyParams(validParams)
|
||||
invalidEdgeSizeParamsMin[EdgeSize] = strconv.Itoa(NgtMinEdgeSize - 1)
|
||||
|
||||
invalidEdgeSizeParamsMax := copyParams(validParams)
|
||||
invalidEdgeSizeParamsMax[EdgeSize] = strconv.Itoa(NgtMaxEdgeSize + 1)
|
||||
|
||||
invalidOutEdgeSizeParamsMin := copyParams(validParams)
|
||||
invalidOutEdgeSizeParamsMin[OutgoingEdgeSize] = strconv.Itoa(NgtMinEdgeSize - 1)
|
||||
|
||||
invalidOutEdgeSizeParamsMax := copyParams(validParams)
|
||||
invalidOutEdgeSizeParamsMax[OutgoingEdgeSize] = strconv.Itoa(NgtMaxEdgeSize + 1)
|
||||
|
||||
invalidInEdgeSizeParamsMin := copyParams(validParams)
|
||||
invalidInEdgeSizeParamsMin[IncomingEdgeSize] = strconv.Itoa(NgtMinEdgeSize - 1)
|
||||
|
||||
invalidInEdgeSizeParamsMax := copyParams(validParams)
|
||||
invalidInEdgeSizeParamsMax[IncomingEdgeSize] = strconv.Itoa(NgtMaxEdgeSize + 1)
|
||||
|
||||
cases := []struct {
|
||||
params map[string]string
|
||||
want bool
|
||||
}{
|
||||
{validParams, true},
|
||||
{invalidEdgeSizeParamsMin, false},
|
||||
{invalidEdgeSizeParamsMax, false},
|
||||
{invalidOutEdgeSizeParamsMin, false},
|
||||
{invalidOutEdgeSizeParamsMax, false},
|
||||
{invalidInEdgeSizeParamsMin, false},
|
||||
{invalidInEdgeSizeParamsMax, false},
|
||||
}
|
||||
|
||||
adapter := newNGTONNGConfAdapter()
|
||||
|
Loading…
Reference in New Issue
Block a user