Skip to content

Commit

Permalink
Add case for scann index and range search (#599)
Browse files Browse the repository at this point in the history
Signed-off-by: ThreadDao <[email protected]>
  • Loading branch information
ThreadDao authored Oct 17, 2023
1 parent 7c1baef commit 29a4e1d
Show file tree
Hide file tree
Showing 5 changed files with 387 additions and 142 deletions.
2 changes: 2 additions & 0 deletions test/common/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -706,6 +706,7 @@ func GenAllFloatIndex(metricType entity.MetricType) []entity.Index {
idxIvfSq8, _ := entity.NewIndexIvfSQ8(metricType, nlist)
idxIvfPq, _ := entity.NewIndexIvfPQ(metricType, nlist, 16, 8)
idxHnsw, _ := entity.NewIndexHNSW(metricType, 8, 96)
idxScann, _ := entity.NewIndexSCANN(metricType, 16, false)
idxDiskAnn, _ := entity.NewIndexDISKANN(metricType)

allFloatIndex := []entity.Index{
Expand All @@ -714,6 +715,7 @@ func GenAllFloatIndex(metricType entity.MetricType) []entity.Index {
idxIvfSq8,
idxIvfPq,
idxHnsw,
idxScann,
idxDiskAnn,
}
return allFloatIndex
Expand Down
30 changes: 22 additions & 8 deletions test/testcases/index_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -297,10 +297,14 @@ func TestCreateIndexNotSupportedField(t *testing.T) {
idx, _ := entity.NewIndexHNSW(entity.L2, 8, 96)
err := mc.CreateIndex(ctx, collName, common.DefaultFloatFieldName, idx, false)
common.CheckErr(t, err, false, "index type not match")

// create scann index
indexScann, _ := entity.NewIndexSCANN(entity.L2, 8, true)
err = mc.CreateIndex(ctx, collName, common.DefaultFloatFieldName, indexScann, false)
common.CheckErr(t, err, false, "index type not match")
}

// test create index with invalid params
// https://github.com/milvus-io/milvus-sdk-go/issues/357
func TestCreateIndexInvalidParams(t *testing.T) {
ctx := createContext(t, time.Second*common.DefaultTimeout)
// connect
Expand Down Expand Up @@ -346,13 +350,23 @@ func TestCreateIndexInvalidParams(t *testing.T) {
_, errHnswEf2 := entity.NewIndexHNSW(entity.L2, 8, 515)
common.CheckErr(t, errHnswEf2, false, "efConstruction has to be in range [8, 512]")

// invalid flat metric type jaccard
// TODO unclear error message
// See also https://github.com/milvus-io/milvus/issues/24080
/*
idx, _ := entity.NewIndexFlat(entity.JACCARD)
errMetricType := mc.CreateIndex(ctx, collName, common.DefaultFloatVecFieldName, idx, false)
common.CheckErr(t, errMetricType, false, "invalid index params")*/
// invalid Scann nlist [1, 65536], with_raw_data [true, false], no default
for _, nlist := range []int{0, 65536 + 1} {
_, errScann := entity.NewIndexSCANN(entity.L2, nlist, true)
log.Println(errScann)
common.CheckErr(t, errScann, false, "nlist has to be in range [1, 65536]")
}
for _, mt := range []entity.MetricType{entity.HAMMING, entity.JACCARD, entity.SUBSTRUCTURE, entity.SUPERSTRUCTURE} {
idxScann, errScann2 := entity.NewIndexSCANN(mt, 64, true)
common.CheckErr(t, errScann2, true)
err := mc.CreateIndex(ctx, collName, common.DefaultFloatVecFieldName, idxScann, false)
common.CheckErr(t, err, false, "metric type not found or not supported, supported: [L2 IP COSINE]")
}

// invalid flat metric type jaccard for flat index
idx, _ := entity.NewIndexFlat(entity.JACCARD)
errMetricType := mc.CreateIndex(ctx, collName, common.DefaultFloatVecFieldName, idx, false)
common.CheckErr(t, errMetricType, false, "metric type not found or not supported, supported: [L2 IP COSINE]")
}

// test create index with nil index
Expand Down
4 changes: 4 additions & 0 deletions test/testcases/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,10 @@ func createCollection(ctx context.Context, t *testing.T, mc *base.MilvusClient,
err := mc.CreateCollection(ctx, schema, cp.ShardsNum, opts...)
common.CheckErr(t, err, true)

t.Cleanup(func() {
_ = mc.DropCollection(ctx, collName)
})

return collName
}

Expand Down
41 changes: 8 additions & 33 deletions test/testcases/query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -451,25 +451,13 @@ func TestQueryJsonDynamicField(t *testing.T) {

for _, dynamicField := range []bool{true, false} {
// create collection
cp := CollectionParams{
CollectionFieldsType: Int64FloatVecJSON,
AutoID: false,
EnableDynamicField: dynamicField,
ShardsNum: common.DefaultShards,
Dim: common.DefaultDim,
}
cp := CollectionParams{CollectionFieldsType: Int64FloatVecJSON, AutoID: false, EnableDynamicField: dynamicField,
ShardsNum: common.DefaultShards, Dim: common.DefaultDim}
collName := createCollection(ctx, t, mc, cp)

// insert
dp := DataParams{
CollectionName: collName,
PartitionName: "",
CollectionFieldsType: Int64FloatVecJSON,
start: 0,
nb: common.DefaultNb,
dim: common.DefaultDim,
EnableDynamicField: dynamicField,
}
dp := DataParams{CollectionName: collName, PartitionName: "", CollectionFieldsType: Int64FloatVecJSON,
start: 0, nb: common.DefaultNb, dim: common.DefaultDim, EnableDynamicField: dynamicField}
_, _ = insertData(ctx, t, mc, dp)

idx, _ := entity.NewIndexHNSW(entity.L2, 8, 96)
Expand Down Expand Up @@ -689,26 +677,13 @@ func TestQueryJsonDynamicFieldRows(t *testing.T) {
mc := createMilvusClient(ctx, t)

// create collection
cp := CollectionParams{
CollectionFieldsType: Int64FloatVecJSON,
AutoID: false,
EnableDynamicField: true,
ShardsNum: common.DefaultShards,
Dim: common.DefaultDim,
}
cp := CollectionParams{CollectionFieldsType: Int64FloatVecJSON, AutoID: false, EnableDynamicField: true,
ShardsNum: common.DefaultShards, Dim: common.DefaultDim}
collName := createCollection(ctx, t, mc, cp)

// insert
dp := DataParams{
CollectionName: collName,
PartitionName: "",
CollectionFieldsType: Int64FloatVecJSON,
start: 0,
nb: common.DefaultNb,
dim: common.DefaultDim,
EnableDynamicField: true,
WithRows: true,
}
dp := DataParams{CollectionName: collName, PartitionName: "", CollectionFieldsType: Int64FloatVecJSON,
start: 0, nb: common.DefaultNb, dim: common.DefaultDim, EnableDynamicField: true, WithRows: true}
_, _ = insertData(ctx, t, mc, dp)

idx, _ := entity.NewIndexHNSW(entity.L2, 8, 96)
Expand Down
Loading

0 comments on commit 29a4e1d

Please sign in to comment.