milvus-io / milvus-sdk-go

Go SDK for Milvus.
Apache License 2.0
330 stars 105 forks source link

[Bug]: reflectValueCandi array error #734

Open extrame opened 4 months ago

extrame commented 4 months ago

Is there an existing issue for this?

Current Behavior

https://github.com/milvus-io/milvus-sdk-go/blob/626c1fece76114d1d7e6abcfbf759cd1f7bc5d62/entity/rows.go#L552

reflectValueCandi reflect array of wrong length, it trim the last byte.

If I define a struct like:

type PromptTemplate struct {
    Id int64 `xorm:"pk autoincr" json:"id" milvus:"primary_key;name:id"`
    CreatedAt time.Time `json:"created_at" xorm:"created" milvus:"-"`
    ActionType  int32        `json:"action_type" milvus:"name:action_type"`
    ProcessCode string       `json:"process_code" milvus:"name:process_code"`
    Vectors     [384]float32 `milvus:"name:prompt_vector" json:"-" xorm:"-"` //用于存储向量
}

It will reflect Vectors to 383 lengths slice.

remove -1 in https://github.com/milvus-io/milvus-sdk-go/blob/626c1fece76114d1d7e6abcfbf759cd1f7bc5d62/entity/rows.go#L552 will fix the bug

Expected Behavior

It should reflect Vectors to 384 lengths slice.

Steps To Reproduce

Define a type with array like:

type PromptTemplate struct {
    Id int64 `xorm:"pk autoincr" json:"id" milvus:"primary_key;name:id"`
    CreatedAt time.Time `json:"created_at" xorm:"created" milvus:"-"`
    ActionType  int32        `json:"action_type" milvus:"name:action_type"`
    ProcessCode string       `json:"process_code" milvus:"name:process_code"`
    Vectors     [384]float32 `milvus:"name:prompt_vector" json:"-" xorm:"-"` //用于存储向量
}

call InsertRows to insert objects of the test type like:

_, err = mclient.InsertRows(
        context.Background(), // ctx
        "cpzx_rag_prompt",    // CollectionName
        "",                   // partitionName
        interfaces,           // rows
    )
    return err

It will show a error like

the length(383) of float data should divide the dim(384)


### Environment

_No response_

### Anything else?

_No response_
congqixia commented 4 months ago

Thanks for pointing this out! I'll fix this asap