milvus-io / milvus-sdk-go

Go SDK for Milvus.
Apache License 2.0
353 stars 110 forks source link

[Bug]: Search / query with invalid expr that has not existed field didn't return error #777

Closed ThreadDao closed 5 months ago

ThreadDao commented 5 months ago

Is there an existing issue for this?

Current Behavior

  1. collection fields: int64 + float + floatVec + json
  2. search/query with invalid expr: id in [0] and no error is returned.
  3. pymilvus can return error

    pymilvus.exceptions.MilvusException: <MilvusException: (code=1100, message=failed to create query plan: cannot parse expression: field in [1, 2], error: field field not exist: invalid parameter)>
    func TestSearchInvalidDebug(t *testing.T) {
    t.Parallel()
    
    ctx := createContext(t, time.Second*common.DefaultTimeout)
    // connect
    mc := createMilvusClient(ctx, t)
    
    // create collection
    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}
    _, _ = insertData(ctx, t, mc, dp)
    
    idx, _ := entity.NewIndexHNSW(entity.L2, 8, 96)
    _ = mc.CreateIndex(ctx, collName, common.DefaultFloatVecFieldName, idx, false)
    
    // Load collection
    errLoad := mc.LoadCollection(ctx, collName, false)
    common.CheckErr(t, errLoad, true)
    
    // search with invalid expr
    sp, _ := entity.NewIndexHNSWSearchParam(74)
    res, errSearchEmpty := mc.Search(
        ctx, collName,
        []string{},
        "id in [0]",
        []string{common.DefaultIntFieldName},
        common.GenSearchVectors(common.DefaultNq, common.DefaultDim, entity.FieldTypeFloatVector),
        common.DefaultFloatVecFieldName,
        entity.L2,
        common.DefaultTopK,
        sp,
    )
    common.CheckErr(t, errSearchEmpty, true)
    for _, r := range res {
        log.Println(r.ResultCount)
        log.Println(r.IDs.FieldData())
    }
    }
    2024/06/20 16:09:53 milvus_client.go:14: (ApiRequest): func [Search], args: [context.Background.WithDeadline(2024-06-20 16:11:53.011591535 +0800 CST m=+120.003312625 [1m59.158522667s]) zjtQ [] id in [0] [int64] nq=5 floatVec L2 10 0xc00078aed0 []]
    2024/06/20 16:09:53 milvus_client.go:21: (ApiResponse): func [Search], results: [[{0 <nil> 0xc000485830 [] [] FieldData type not matched} {0 <nil> 0xc000485860 [] [] FieldData type not matched} {0 <nil> 0xc000485890 [] [] FieldData type not matched} {0 <nil> 0xc0004858c0 [] [] FieldData type not matched} {0 <nil> 0xc0004858f0 [] [] FieldData type not matched}]]
    2024/06/20 16:09:53 search_test.go:1074: 0
    2024/06/20 16:09:53 search_test.go:1075: type:Int64 field_name:"int64" scalars:<long_data:<> > 
    2024/06/20 16:09:53 search_test.go:1074: 0
    2024/06/20 16:09:53 search_test.go:1075: type:Int64 field_name:"int64" scalars:<long_data:<> > 
    2024/06/20 16:09:53 search_test.go:1074: 0
    2024/06/20 16:09:53 search_test.go:1075: type:Int64 field_name:"int64" scalars:<long_data:<> > 
    2024/06/20 16:09:53 search_test.go:1074: 0
    2024/06/20 16:09:53 search_test.go:1075: type:Int64 field_name:"int64" scalars:<long_data:<> > 
    2024/06/20 16:09:53 search_test.go:1074: 0
    2024/06/20 16:09:53 search_test.go:1075: type:Int64 field_name:"int64" scalars:<long_data:<> > 

Expected Behavior

No response

Steps To Reproduce

pods:

zong-go-master-etcd-0                                         1/1     Running     0              2d1h    10.104.25.21    4am-node30   <none>           <none>
zong-go-master-milvus-standalone-5cc75d965b-t46jr             1/1     Running     0              2d1h    10.104.19.69    4am-node28   <none>           <none>
zong-go-master-minio-55956b966c-s48rt                         1/1     Running     0              2d1h    10.104.34.72    4am-node37   <none>           <none>


### Environment

_No response_

### Anything else?

_No response_
ThreadDao commented 5 months ago

Oh the reason is dynamic field is enabled. If disable dynamic field, an error is returned