diff --git a/internal/core/src/indexbuilder/init_c.cpp b/internal/core/src/indexbuilder/init_c.cpp index 42ef166363..7753005aed 100644 --- a/internal/core/src/indexbuilder/init_c.cpp +++ b/internal/core/src/indexbuilder/init_c.cpp @@ -31,4 +31,4 @@ IndexBuilderSetSimdType(const char* value) { void IndexBuilderInitGPU(const int32_t gpu_id, const int32_t res_num) { milvus::config::KnowhereInitGPU(gpu_id, res_num); -} \ No newline at end of file +} diff --git a/internal/proxy/task_insert.go b/internal/proxy/task_insert.go index 05d527bc1d..3d6c6d1851 100644 --- a/internal/proxy/task_insert.go +++ b/internal/proxy/task_insert.go @@ -82,6 +82,9 @@ func (it *insertTask) OnEnqueue() error { } func (it *insertTask) checkVectorFieldData() error { + // error won't happen here. + helper, _ := typeutil.CreateSchemaHelper(it.schema) + fields := it.insertMsg.GetFieldsData() for _, field := range fields { if field.GetType() != schemapb.DataType_FloatVector { @@ -90,14 +93,21 @@ func (it *insertTask) checkVectorFieldData() error { vectorField := field.GetVectors() if vectorField == nil || vectorField.GetFloatVector() == nil { - log.Error("float vector field is illegal, array type mismatch", zap.String("field name", field.GetFieldName())) return fmt.Errorf("float vector field '%v' is illegal, array type mismatch", field.GetFieldName()) } + // error won't happen here. + f, _ := helper.GetFieldFromName(field.GetFieldName()) + dim, _ := typeutil.GetDim(f) + floatArray := vectorField.GetFloatVector() - err := typeutil.VerifyFloats32(floatArray.GetData()) - if err != nil { - log.Error("float vector field data is illegal", zap.String("field name", field.GetFieldName()), zap.Error(err)) + + // TODO: `NumRows` passed by client may be not trustable. + if uint64(len(floatArray.GetData())) != uint64(dim)*it.insertMsg.GetNumRows() { + return fmt.Errorf("length of inserted vector (%d) not match dim (%d)", len(floatArray.GetData()), dim) + } + + if err := typeutil.VerifyFloats32(floatArray.GetData()); err != nil { return fmt.Errorf("float vector field data is illegal, error: %w", err) } } diff --git a/internal/proxy/task_insert_test.go b/internal/proxy/task_insert_test.go index 91f96f73a2..2099ab606a 100644 --- a/internal/proxy/task_insert_test.go +++ b/internal/proxy/task_insert_test.go @@ -2,6 +2,7 @@ package proxy import ( "math" + "strconv" "testing" "github.com/stretchr/testify/assert" @@ -245,6 +246,7 @@ func TestInsertTask_CheckVectorFieldData(t *testing.T) { IsPrimaryKey: false, AutoID: false, DataType: schemapb.DataType_FloatVector, + TypeParams: []*commonpb.KeyValuePair{{Key: "dim", Value: strconv.Itoa(dim)}}, }, }, }, @@ -300,4 +302,11 @@ func TestInsertTask_CheckVectorFieldData(t *testing.T) { } err = task.checkVectorFieldData() assert.Error(t, err) + + // vector dim not match + task.insertMsg.FieldsData = []*schemapb.FieldData{ + newFloatVectorFieldData(fieldName, numRows, dim+1), + } + err = task.checkVectorFieldData() + assert.Error(t, err) }