Skip to content

Commit

Permalink
test: Optimize sparse vector case (milvus-io#35661)
Browse files Browse the repository at this point in the history
/kind improvement

Signed-off-by: ThreadDao <[email protected]>
  • Loading branch information
ThreadDao authored Aug 26, 2024
1 parent 82743c5 commit a90133c
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 11 deletions.
8 changes: 4 additions & 4 deletions tests/go_client/common/response_checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,12 +151,12 @@ func CheckOutputFields(t *testing.T, expFields []string, actualColumns []column.

// CheckSearchResult check search result, check nq, topk, ids, score
func CheckSearchResult(t *testing.T, actualSearchResults []client.ResultSet, expNq int, expTopK int) {
require.Equal(t, len(actualSearchResults), expNq)
require.Equalf(t, len(actualSearchResults), expNq, fmt.Sprintf("Expected nq=%d, actual SearchResultsLen=%d", expNq, len(actualSearchResults)))
require.Len(t, actualSearchResults, expNq)
for _, actualSearchResult := range actualSearchResults {
require.Equal(t, actualSearchResult.ResultCount, expTopK)
require.Equal(t, actualSearchResult.IDs.Len(), expTopK)
require.Equal(t, len(actualSearchResult.Scores), expTopK)
require.Equalf(t, actualSearchResult.ResultCount, expTopK, fmt.Sprintf("Expected topK=%d, actual ResultCount=%d", expTopK, actualSearchResult.ResultCount))
require.Equalf(t, actualSearchResult.IDs.Len(), expTopK, fmt.Sprintf("Expected topK=%d, actual IDsLen=%d", expTopK, actualSearchResult.IDs.Len()))
require.Equalf(t, len(actualSearchResult.Scores), expTopK, fmt.Sprintf("Expected topK=%d, actual ScoresLen=%d", expTopK, len(actualSearchResult.Scores)))
}
}

Expand Down
20 changes: 20 additions & 0 deletions tests/go_client/testcases/insert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -740,3 +740,23 @@ func TestInsertAutoIDInvalidRow(t *testing.T) {
common.CheckErr(t, err, false, "missing pk data")
}
}

func TestFlushRate(t *testing.T) {
ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout)
mc := createDefaultMilvusClient(ctx, t)
// create collection
cp := hp.NewCreateCollectionParams(hp.Int64Vec)
_, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, cp, hp.TNewFieldsOption().TWithAutoID(true), hp.TNewSchemaOption())

// insert
columnOpt := hp.TNewDataOption().TWithDim(common.DefaultDim)
vecColumn := hp.GenColumnData(common.DefaultNb, entity.FieldTypeFloatVector, *columnOpt)
insertOpt := client.NewColumnBasedInsertOption(schema.CollectionName).WithColumns(vecColumn)
_, err := mc.Insert(ctx, insertOpt)
common.CheckErr(t, err, true)

_, err = mc.Flush(ctx, client.NewFlushOption(schema.CollectionName))
common.CheckErr(t, err, true)
_, err = mc.Flush(ctx, client.NewFlushOption(schema.CollectionName))
common.CheckErr(t, err, false, "request is rejected by grpc RateLimiter middleware, please retry later: rate limit exceeded[rate=0.1]")
}
19 changes: 12 additions & 7 deletions tests/go_client/testcases/search_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ func TestSearchInvalidCollectionPartitionName(t *testing.T) {

// test search empty collection -> return empty
func TestSearchEmptyCollection(t *testing.T) {
t.Skip("https://github.com/milvus-io/milvus/issues/33952")
t.Parallel()
ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout)
mc := createDefaultMilvusClient(ctx, t)
Expand All @@ -104,13 +105,13 @@ func TestSearchEmptyCollection(t *testing.T) {
resSearch, errSearch := mc.Search(ctx, client.NewSearchOption(schema.CollectionName, common.DefaultLimit, _mNameVec.queryVec).
WithConsistencyLevel(entity.ClStrong).WithANNSField(_mNameVec.fieldName))
common.CheckErr(t, errSearch, true)
t.Log("https://github.com/milvus-io/milvus/issues/33952")
common.CheckSearchResult(t, resSearch, 0, 0)
common.CheckSearchResult(t, resSearch, common.DefaultNq, 0)
}
}
}

func TestSearchEmptySparseCollection(t *testing.T) {
t.Skip("https://github.com/milvus-io/milvus/issues/33952")
ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout)
mc := createDefaultMilvusClient(ctx, t)

Expand All @@ -124,8 +125,7 @@ func TestSearchEmptySparseCollection(t *testing.T) {
resSearch, errSearch := mc.Search(ctx, client.NewSearchOption(schema.CollectionName, common.DefaultLimit, vectors).
WithConsistencyLevel(entity.ClStrong).WithANNSField(common.DefaultSparseVecFieldName))
common.CheckErr(t, errSearch, true)
t.Log("https://github.com/milvus-io/milvus/issues/33952")
common.CheckSearchResult(t, resSearch, 0, 0)
common.CheckSearchResult(t, resSearch, common.DefaultNq, 0)
}

// test search with partition names []string{}, specify partitions
Expand Down Expand Up @@ -976,14 +976,17 @@ func TestSearchWithEmptySparseVector(t *testing.T) {

// test search from empty sparse vectors collection
func TestSearchFromEmptySparseVector(t *testing.T) {
t.Parallel()
t.Skip("https://github.com/milvus-io/milvus/issues/33952")
t.Skip("https://github.com/zilliztech/knowhere/issues/774")
idxInverted := index.NewSparseInvertedIndex(entity.IP, 0.1)
ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout*2)
mc := createDefaultMilvusClient(ctx, t)

for _, idx := range []index.Index{idxInverted} {
prepare, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, hp.NewCreateCollectionParams(hp.Int64VarcharSparseVec), hp.TNewFieldsOption(), hp.TNewSchemaOption().
TWithEnableDynamicField(true))
prepare.InsertData(ctx, t, mc, hp.NewInsertParams(schema), hp.TNewDataOption().TWithSparseMaxLen(128).TWithStart(common.DefaultNb))
prepare.FlushData(ctx, t, mc, schema.CollectionName)
prepare.CreateIndex(ctx, t, mc, hp.TNewIndexParams(schema).TWithFieldIndex(map[string]index.Index{common.DefaultSparseVecFieldName: idx}))
prepare.Load(ctx, t, mc, hp.NewLoadParams(schema.CollectionName))

Expand All @@ -1009,10 +1012,12 @@ func TestSearchFromEmptySparseVector(t *testing.T) {
vector1, _ := entity.NewSliceSparseEmbedding([]uint32{}, []float32{})
vector2, _ := entity.NewSliceSparseEmbedding([]uint32{0, 2, 5, 10, 100}, []float32{rand.Float32(), rand.Float32(), rand.Float32(), rand.Float32(), rand.Float32()})

for _, vector := range []entity.Vector{vector1, vector2} {
// search from sparse collection: part normal sparse vectors, part empty sparse
// excepted: The empty vector is not related to any other vector, so it will not be returned,and alsopty obtained as the search vector.
for limit, vector := range map[int]entity.Vector{0: vector1, common.DefaultLimit: vector2} {
searchRes, errSearch1 := mc.Search(ctx, client.NewSearchOption(schema.CollectionName, common.DefaultLimit, []entity.Vector{vector}).WithConsistencyLevel(entity.ClStrong))
common.CheckErr(t, errSearch1, true)
common.CheckSearchResult(t, searchRes, 1, 0)
common.CheckSearchResult(t, searchRes, 1, limit)
}
}
}
Expand Down

0 comments on commit a90133c

Please sign in to comment.