Fix the crash caused by empty index param (#3803)

* fix crash caused by empty index param

Signed-off-by: shengjun.li <shengjun.li@zilliz.com>

* fix C++ SDK examples

Signed-off-by: shengjun.li <shengjun.li@zilliz.com>
This commit is contained in:
shengjun.li 2020-09-18 16:34:33 +08:00 committed by GitHub
parent 0749b3793c
commit 6bd5dc3feb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 16 additions and 25 deletions

View File

@ -100,7 +100,10 @@ CreateIndexReq::OnExecute() {
}
// validate index parameters
status = ValidateIndexParams(json_params_[engine::PARAM_INDEX_EXTRA_PARAMS], dimension, index_type);
if (json_params_.contains(engine::PARAM_INDEX_EXTRA_PARAMS)) {
index.extra_params_ = json_params_[engine::PARAM_INDEX_EXTRA_PARAMS];
}
status = ValidateIndexParams(index.extra_params_, dimension, index_type);
if (!status.ok()) {
return status;
}
@ -110,9 +113,6 @@ CreateIndexReq::OnExecute() {
index.index_name_ = index_name_;
index.index_type_ = index_type;
index.metric_name_ = metric_type;
if (json_params_.contains(engine::PARAM_INDEX_EXTRA_PARAMS)) {
index.extra_params_ = json_params_[engine::PARAM_INDEX_EXTRA_PARAMS];
}
} else {
index.index_name_ = index_name_;
index.index_type_ = index_type;

View File

@ -63,7 +63,8 @@ TestProcess(std::shared_ptr<milvus::Connection> connection, const milvus::Mappin
{ // create collection
JSON extra_params;
extra_params["segment_row_limit"] = 1024;
extra_params["segment_row_limit"] = 1000000;
extra_params["auto_id"] = false;
stat = connection->CreateCollection(mapping, extra_params.dump());
std::cout << "CreateCollection function call status: " << stat.message() << std::endl;
milvus_sdk::Utils::PrintCollectionParam(mapping);
@ -86,7 +87,6 @@ TestProcess(std::shared_ptr<milvus::Connection> connection, const milvus::Mappin
{ // generate vectors
milvus_sdk::TimeRecorder rc("Build entities No." + std::to_string(i));
BuildBinaryVectors(begin_index, begin_index + BATCH_ENTITY_COUNT, entity_array, entity_ids, DIMENSION);
entity_ids.clear();
}
if (search_entity_array.size() < NQ) {
@ -115,12 +115,12 @@ TestProcess(std::shared_ptr<milvus::Connection> connection, const milvus::Mappin
}
{ // search vectors
// std::string metric_type = "HAMMING";
// std::string metric_type = "JACCARD";
std::string metric_type = "TANIMOTO";
// std::string metric_type = "HAMMING";
std::string metric_type = "JACCARD";
// std::string metric_type = "TANIMOTO";
nlohmann::json dsl_json, vector_param_json;
milvus_sdk::Utils::GenBinaryDSLJson(dsl_json, vector_param_json, metric_type);
milvus_sdk::Utils::GenPureVecDSLJson(dsl_json, vector_param_json, metric_type);
std::vector<milvus::VectorData> temp_entity_array;
for (auto& pair : search_entity_array) {

View File

@ -25,7 +25,6 @@ namespace {
const char* COLLECTION_NAME = milvus_sdk::Utils::GenCollectionName().c_str();
constexpr int64_t COLLECTION_DIMENSION = 512;
constexpr int64_t COLLECTION_INDEX_FILE_SIZE = 1024;
constexpr milvus::MetricType COLLECTION_METRIC_TYPE = milvus::MetricType::L2;
constexpr int64_t BATCH_ENTITY_COUNT = 10000;
constexpr int64_t NQ = 5;
@ -33,8 +32,7 @@ constexpr int64_t TOP_K = 10;
constexpr int64_t NPROBE = 32;
constexpr int64_t SEARCH_TARGET = BATCH_ENTITY_COUNT / 2; // change this value, result is different
constexpr int64_t ADD_ENTITY_LOOP = 10;
constexpr milvus::IndexType INDEX_TYPE = milvus::IndexType::IVFFLAT;
constexpr int32_t NLIST = 16384;
constexpr int32_t NLIST = 1024;
const char* PARTITION_TAG = "part";
const char* DIMENSION = "dim";
const char* METRICTYPE = "metric_type";
@ -114,6 +112,7 @@ ClientTest::CreateCollection(const std::string& collection_name) {
JSON extra_params;
extra_params["segment_row_limit"] = 10000;
extra_params["auto_id"] = false;
milvus::Mapping mapping = {collection_name, {field_ptr1, field_ptr2, field_ptr3, field_ptr4}};
milvus::Status stat = conn_->CreateCollection(mapping, extra_params.dump());
@ -140,7 +139,6 @@ ClientTest::InsertEntities(const std::string& collection_name) {
milvus_sdk::Utils::BuildEntities(begin_index, begin_index + BATCH_ENTITY_COUNT, field_value, entity_ids,
COLLECTION_DIMENSION);
}
entity_ids.clear();
milvus::Status status = conn_->Insert(collection_name, "", field_value, entity_ids);
search_id_array_.emplace_back(entity_ids[10]);
std::cout << "InsertEntities function call status: " << status.message() << std::endl;
@ -335,7 +333,7 @@ ClientTest::Test() {
InsertEntities(collection_name);
Flush(collection_name);
CountEntities(collection_name);
CreateIndex(collection_name, 1024);
CreateIndex(collection_name, NLIST);
GetCollectionInfo(collection_name);
// GetCollectionStats(collection_name);
//
@ -356,5 +354,5 @@ ClientTest::Test() {
// entities
//
// DropIndex(collection_name, "field_vec", "index_3");
// DropCollection(collection_name);
DropCollection(collection_name);
}

View File

@ -371,14 +371,7 @@ Utils::GenDSLJson(nlohmann::json& dsl_json, nlohmann::json& vector_param_json, c
}
void
Utils::GenBinaryDSLJson(nlohmann::json& dsl_json, nlohmann::json& vector_param_json, const std::string metric_type) {
uint64_t row_num = 10000;
std::vector<int64_t> term_value;
term_value.resize(row_num);
for (uint64_t i = 0; i < row_num; ++i) {
term_value[i] = i;
}
Utils::GenPureVecDSLJson(nlohmann::json& dsl_json, nlohmann::json& vector_param_json, const std::string metric_type) {
nlohmann::json bool_json, vector_json;
std::string placeholder = "placeholder_1";
vector_json["vector"] = placeholder;

View File

@ -85,7 +85,7 @@ class Utils {
GenDSLJson(nlohmann::json& dsl_json, nlohmann::json& vector_param_json, const std::string metric_type);
static void
GenBinaryDSLJson(nlohmann::json& dsl_json, nlohmann::json& vector_param_json, const std::string metric_type);
GenPureVecDSLJson(nlohmann::json& dsl_json, nlohmann::json& vector_param_json, const std::string metric_type);
static void
PrintTopKQueryResult(milvus::TopKQueryResult& topk_query_result);