milvus-io / milvus-sdk-go

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

[Bug]: Create AUTOINDEX on scalar field successfully #702

Closed ThreadDao closed 7 months ago

ThreadDao commented 7 months ago

Is there an existing issue for this?

Current Behavior

The AUTOINDEX creation on the scalar field was successful. The configured AUTOINDEX index is HNSW, and an error is expected to be returned.

func TestCreateAutoIndexScalarFields(t *testing.T) {
    ctx := createContext(t, time.Second*common.DefaultTimeout)
    //connect
    mc := createMilvusClient(ctx, t)

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

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

    // create index for all vector fields
    indexAuto, _ := entity.NewIndexAUTOINDEX(entity.L2)
    coll, _ := mc.DescribeCollection(ctx, collName)
    for _, field := range coll.Schema.Fields {
        if supportScalarIndexFieldType(field.DataType) {
            log.Println(field.Name, field.DataType)
            err := mc.CreateIndex(ctx, collName, field.Name, indexAuto, false, client.WithIndexName(field.Name))
            common.CheckErr(t, err, false, "HNSW only support float vector data type")
        }
    }
}
2024/04/09 10:35:50 index_test.go:661: int64 int64
2024/04/09 10:35:50 milvus_client.go:14: (ApiRequest): func [CreateIndex], args: [context.Background.WithDeadline(2024-04-09 10:37:47.844614217 +0800 CST m=+120.003653175 [1m56.875537048s]) zUDv int64 false 0xc01c900440 [0xa6f780]]
2024/04/09 10:35:52 milvus_client.go:21: (ApiResponse): func [CreateIndex], results: []
2024/04/09 10:35:52 milvus_client.go:14: (ApiRequest): func [DescribeIndex], args: [context.Background.WithDeadline(2024-04-09 10:37:47.844614217 +0800 CST m=+120.003653175 [1m55.102393824s]) zUDv int64 []]
2024/04/09 10:35:52 milvus_client.go:21: (ApiResponse): func [DescribeIndex], results: [[{{AUTOINDEX int64} map[index_type:AUTOINDEX metric_type:L2 params:{}]}]]

Expected Behavior

No response

Steps To Reproduce

No response

Environment

No response

Anything else?

No response

ThreadDao commented 7 months ago

/assign @congqixia

ThreadDao commented 7 months ago

birdwatcher shows that the actual index is: inverted

Milvus(zong-go-master-2) > show index --collection 449162955906704142
*************2.1.x***************
*************2.2.x***************
==================================================================
Index ID: 449162955906704177    Index Name: int64   CollectionID: 449162955906704142    FieldID: 100
Create Time: 2024-04-19 12:09:26.831 +0800  Deleted: false
Index Type: INVERTED    Metric Type: L2
Index Params: {}
metric_type:L2index_type:INVERTED==================================================================
==================================================================
Index ID: 449162955906704194    Index Name: bool    CollectionID: 449162955906704142    FieldID: 101
Create Time: 2024-04-19 12:09:28.832 +0800  Deleted: false
Index Type: INVERTED    Metric Type: L2
Index Params: {}
metric_type:L2index_type:INVERTED==================================================================
==================================================================
Index ID: 449162955906704211    Index Name: int8    CollectionID: 449162955906704142    FieldID: 102
Create Time: 2024-04-19 12:09:30.832 +0800  Deleted: false
Index Type: INVERTED    Metric Type: L2
Index Params: {}
index_type:INVERTEDmetric_type:L2==================================================================
==================================================================
Index ID: 449162955906704228    Index Name: int16   CollectionID: 449162955906704142    FieldID: 103
Create Time: 2024-04-19 12:09:32.782 +0800  Deleted: false
Index Type: INVERTED    Metric Type: L2
Index Params: {}
metric_type:L2index_type:INVERTED==================================================================
==================================================================
Index ID: 449162955906704245    Index Name: int32   CollectionID: 449162955906704142    FieldID: 104
Create Time: 2024-04-19 12:09:34.781 +0800  Deleted: false
Index Type: INVERTED    Metric Type: L2
Index Params: {}
index_type:INVERTEDmetric_type:L2==================================================================
==================================================================
Index ID: 449162955906704262    Index Name: float   CollectionID: 449162955906704142    FieldID: 105
Create Time: 2024-04-19 12:09:36.882 +0800  Deleted: false
Index Type: INVERTED    Metric Type: L2
Index Params: {}
index_type:INVERTEDmetric_type:L2==================================================================
==================================================================
Index ID: 449162955906704279    Index Name: double  CollectionID: 449162955906704142    FieldID: 106
Create Time: 2024-04-19 12:09:38.782 +0800  Deleted: false
Index Type: INVERTED    Metric Type: L2
Index Params: {}
index_type:INVERTEDmetric_type:L2==================================================================
==================================================================
Index ID: 449162955906704297    Index Name: varchar CollectionID: 449162955906704142    FieldID: 107
Create Time: 2024-04-19 12:09:40.782 +0800  Deleted: false
Index Type: INVERTED    Metric Type: L2
Index Params: {}
index_type:INVERTEDmetric_type:L2==================================================================