milvus-sdk-cpp icon indicating copy to clipboard operation
milvus-sdk-cpp copied to clipboard

Data validation for Insert()

Open yhmo opened this issue 2 years ago • 0 comments

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:

  1. make sure the insert data is arranged(the sequence of column) by collection schema.
  2. field types should be equal to collection schema.
  3. vector dimensions should be equal to collection schema.
  4. if a primary key is auto_id, no need to input this field.

yhmo avatar Mar 03 '22 10:03 yhmo