Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: add go-sdk cases for hybrid search #39579

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions tests/go_client/base/milvus_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -316,3 +316,9 @@ func (mc *MilvusClient) Get(ctx context.Context, option client.QueryOption, call
resultSet, err := mc.mClient.Get(ctx, option, callOptions...)
return resultSet, err
}

// HybridSearch hybrid search from collection
func (mc *MilvusClient) HybridSearch(ctx context.Context, option client.HybridSearchOption, callOptions ...grpc.CallOption) ([]client.ResultSet, error) {
resultSets, err := mc.mClient.HybridSearch(ctx, option, callOptions...)
return resultSets, err
}
6 changes: 1 addition & 5 deletions tests/go_client/testcases/database_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,8 @@ func TestDatabase(t *testing.T) {
common.CheckErr(t, errList, true)
require.Containsf(t, dbs, dbName1, fmt.Sprintf("%s db not in dbs: %v", dbName1, dbs))

// new client with db1 -> using db
// new client with db1
clientDB1 := createMilvusClient(ctx, t, &client.ClientConfig{Address: *addr, DBName: dbName1})
t.Log("https://github.com/milvus-io/milvus/issues/34137")
err = clientDB1.UseDatabase(ctx, client.NewUseDatabaseOption(dbName1))
common.CheckErr(t, err, true)

// create collections -> verify collections contains
_, db1Col1 := hp.CollPrepare.CreateCollection(ctx, t, clientDB1, hp.NewCreateCollectionParams(hp.Int64Vec), hp.TNewFieldsOption(), hp.TNewSchemaOption())
Expand Down Expand Up @@ -223,7 +220,6 @@ func TestUsingDb(t *testing.T) {
}

func TestClientWithDb(t *testing.T) {
t.Skip("https://github.com/milvus-io/milvus/issues/34137")
teardownSuite := teardownTest(t)
defer teardownSuite(t)

Expand Down
52 changes: 51 additions & 1 deletion tests/go_client/testcases/delete_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,6 @@ func TestDeleteComplexExpr(t *testing.T) {
expr string
count int
}
capacity := common.TestCapacity
exprLimits := []exprCount{
{expr: fmt.Sprintf("%s >= 1000 || %s > 2000", common.DefaultInt64FieldName, common.DefaultInt64FieldName), count: 2000},

Expand All @@ -462,7 +461,58 @@ func TestDeleteComplexExpr(t *testing.T) {

// data type not match and no error
{expr: fmt.Sprintf("%s['number'] == '0' ", common.DefaultJSONFieldName), count: 0},
}
ch := make(chan struct{}, 5)
wg := sync.WaitGroup{}
testFunc := func(exprLimit exprCount) {
defer func() {
wg.Done()
<-ch
}()
ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout*2)
mc := createDefaultMilvusClient(ctx, t)

// create collection and a partition
cp := hp.NewCreateCollectionParams(hp.Int64VecAllScalar)
prepare, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, cp, hp.TNewFieldsOption(), hp.TNewSchemaOption().TWithEnableDynamicField(true))

// insert [0, 3000) into default
prepare.InsertData(ctx, t, mc, hp.NewInsertParams(schema), hp.TNewDataOption().TWithMaxCapacity(common.TestCapacity))
prepare.FlushData(ctx, t, mc, schema.CollectionName)

// index and load
prepare.CreateIndex(ctx, t, mc, hp.TNewIndexParams(schema))
prepare.Load(ctx, t, mc, hp.NewLoadParams(schema.CollectionName))

log.Debug("TestDeleteComplexExpr", zap.Any("expr", exprLimit.expr))

resDe, err := mc.Delete(ctx, client.NewDeleteOption(schema.CollectionName).WithExpr(exprLimit.expr))
common.CheckErr(t, err, true)
log.Debug("delete count", zap.Bool("equal", int64(exprLimit.count) == resDe.DeleteCount))
// require.Equal(t, int64(exprLimit.count), resDe.DeleteCount)

resQuery, err := mc.Query(ctx, client.NewQueryOption(schema.CollectionName).WithFilter(exprLimit.expr).WithConsistencyLevel(entity.ClStrong))
common.CheckErr(t, err, true)
require.Zero(t, resQuery.ResultCount)
}

for _, exprLimit := range exprLimits {
exprLimit := exprLimit
ch <- struct{}{}
wg.Add(1)
go testFunc(exprLimit)
}
wg.Wait()
}

// test delete json expr
func TestDeleteComplexExprJson(t *testing.T) {
type exprCount struct {
expr string
count int
}
capacity := common.TestCapacity
exprLimits := []exprCount{
// json field
{expr: fmt.Sprintf("%s > 1499.5", common.DefaultJSONFieldName), count: 1500 / 2}, // json >= 1500.0
{expr: fmt.Sprintf("%s like '21%%'", common.DefaultJSONFieldName), count: 100 / 4}, // json like '21%'
Expand Down
Loading
Loading