-
Notifications
You must be signed in to change notification settings - Fork 3k
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
[Bug]: [GoSDK] When inserting rows without primary key data, all the returned IDs are zero #33460
Comments
/assign @congqixia |
Test with following code package main
import (
"context"
"log"
"math/rand"
milvusclient "github.com/milvus-io/milvus/client/v2"
"github.com/milvus-io/milvus/client/v2/row"
)
type Data struct {
ID int64 `milvus:"name:id;primary_key;auto_id"`
Vector []float32 `milvus:"name:vector;dim:128"`
}
const (
milvusAddr = `localhost:19530`
nEntities, dim = 10, 128
collectionName = "hello_milvus"
msgFmt = "==== %s ====\n"
idCol, randomCol, embeddingCol = "id", "random", "vector"
topK = 3
)
func main() {
schema, err := row.ParseSchema(&Data{})
if err != nil {
log.Fatal("failed to parse schema from struct", err.Error())
}
for _, field := range schema.Fields {
log.Printf("Field name: %s, FieldType %s, IsPrimaryKey: %t", field.Name, field.DataType, field.PrimaryKey)
}
schema.WithName(collectionName)
ctx := context.Background()
log.Printf(msgFmt, "start connecting to Milvus")
c, err := milvusclient.New(ctx, &milvusclient.ClientConfig{
Address: milvusAddr,
})
if err != nil {
log.Fatal("failed to connect to milvus, err: ", err.Error())
}
defer c.Close(ctx)
if has, err := c.HasCollection(ctx, milvusclient.NewHasCollectionOption(collectionName)); err != nil {
log.Fatal("failed to check collection exists or not", err.Error())
} else if has {
c.DropCollection(ctx, milvusclient.NewDropCollectionOption(collectionName))
}
err = c.CreateCollection(ctx, milvusclient.NewCreateCollectionOption(collectionName, schema))
if err != nil {
log.Fatal("failed to create collection", err.Error())
}
var rows []any
for i := 0; i < nEntities; i++ {
vec := make([]float32, 0, dim)
for j := 0; j < dim; j++ {
vec = append(vec, rand.Float32())
}
rows = append(rows, &Data{
Vector: vec,
})
}
insertResult, err := c.Insert(ctx, milvusclient.NewRowBasedInsertOption(collectionName, rows...))
if err != nil {
log.Fatal("failed to insert data")
}
log.Println(insertResult.IDs)
} the output was like follow
|
It looks like the schema in your test case does not set auto id of pk field to true |
@congqixia Oh~ I only set schema AutoId to true. In other words, the above test is equivalent to setting AutoID to false. In this case, inserting a row without pk data should also result in an error instead of returning zero IDs. |
@ThreadDao BaseRow has field named |
@congqixia
|
@ThreadDao json |
See also: milvus-io#33460 Signed-off-by: yangxuan <[email protected]>
See also: milvus-io#33460 Signed-off-by: yangxuan <[email protected]>
See also: milvus-io#33460 Signed-off-by: yangxuan <[email protected]>
Related to milvus-io#33460 Signed-off-by: Congqi Xia <[email protected]>
Related to #33460 --------- Signed-off-by: Congqi Xia <[email protected]>
- add log level for go sdk cases - update cases for issue #33460 & #37853 --------- Signed-off-by: ThreadDao <[email protected]>
Is there an existing issue for this?
Environment
Current Behavior
Expected Behavior
No response
Steps To Reproduce
No response
Milvus Log
No response
Anything else?
No response
The text was updated successfully, but these errors were encountered: