milvus-sdk-cpp
milvus-sdk-cpp copied to clipboard
Data validation for Insert()
The milvus server requires the insert data arranged by collection schema. For example, a collection has two fields "id" and "vectors"
milvus::CollectionSchema collection_schema(collection_name);
collection_schema.AddField({"id", milvus::DataType::INT64, "user id", true, false});
collection_schema.AddField(milvus::FieldSchema("vectors", milvus::DataType::FLOAT_VECTOR, "face signature")
.WithDimension(dimension));
If we construct the data in this way:
std::vector<milvus::FieldDataPtr> fields_data{
std::make_shared<milvus::FloatVecFieldData>("vectors", insert_vectors),
std::make_shared<milvus::Int64FieldData>("id", insert_ids)};
milvus::DmlResults dml_results;
status = client->Insert(collection_name, partition_name, fields_data, dml_results);
The Insert() return Ok, but in face the data is cracked.
There Insert() should validate the insert data by these rules:
- make sure the insert data is arranged(the sequence of column) by collection schema.
- field types should be equal to collection schema.
- vector dimensions should be equal to collection schema.
- if a primary key is auto_id, no need to input this field.