diff --git a/examples/src/v2/add_field.cpp b/examples/src/v2/add_field.cpp index f80c42c5..41f253b2 100644 --- a/examples/src/v2/add_field.cpp +++ b/examples/src/v2/add_field.cpp @@ -43,9 +43,9 @@ CreateCollection(milvus::MilvusClientV2Ptr& client) { milvus::CreateCollectionRequest().WithCollectionName(collection_name).WithCollectionSchema(collection_schema)); util::CheckStatus("create collection: " + collection_name, status); - milvus::IndexDesc index_vector(field_vector, "", milvus::IndexType::FLAT, milvus::MetricType::COSINE); + milvus::IndexParam index_vector(field_vector, "", milvus::IndexType::FLAT, milvus::MetricType::COSINE); status = client->CreateIndex( - milvus::CreateIndexRequest().WithCollectionName(collection_name).AddIndex(std::move(index_vector))); + milvus::CreateIndexRequest().WithCollectionName(collection_name).AddIndexParam(std::move(index_vector))); util::CheckStatus("create index on vector field", status); status = client->LoadCollection(milvus::LoadCollectionRequest().WithCollectionName(collection_name)); diff --git a/examples/src/v2/array.cpp b/examples/src/v2/array.cpp index 62320b71..d1e89dd3 100644 --- a/examples/src/v2/array.cpp +++ b/examples/src/v2/array.cpp @@ -83,9 +83,9 @@ main(int argc, char* argv[]) { util::CheckStatus("create collection: " + collection_name, status); // create index - milvus::IndexDesc index_vector(field_vector, "", milvus::IndexType::FLAT, milvus::MetricType::COSINE); + milvus::IndexParam index_vector(field_vector, "", milvus::IndexType::FLAT, milvus::MetricType::COSINE); status = client->CreateIndex( - milvus::CreateIndexRequest().WithCollectionName(collection_name).AddIndex(std::move(index_vector))); + milvus::CreateIndexRequest().WithCollectionName(collection_name).AddIndexParam(std::move(index_vector))); util::CheckStatus("create index on vector field", status); // tell server prepare to load collection diff --git a/examples/src/v2/db.cpp b/examples/src/v2/db.cpp index 711eface..7ce47323 100644 --- a/examples/src/v2/db.cpp +++ b/examples/src/v2/db.cpp @@ -86,14 +86,14 @@ main(int argc, char* argv[]) { util::CheckStatus("create collection: " + collection_name, status); // create indexes - milvus::IndexDesc index_vector(field_face, "", milvus::IndexType::FLAT, milvus::MetricType::COSINE); - milvus::IndexDesc index_varchar(field_name, "", milvus::IndexType::TRIE); - milvus::IndexDesc index_sort(field_age, "", milvus::IndexType::STL_SORT); + milvus::IndexParam index_vector(field_face, "", milvus::IndexType::FLAT, milvus::MetricType::COSINE); + milvus::IndexParam index_varchar(field_name, "", milvus::IndexType::TRIE); + milvus::IndexParam index_sort(field_age, "", milvus::IndexType::STL_SORT); status = client->CreateIndex(milvus::CreateIndexRequest() .WithCollectionName(collection_name) - .AddIndex(std::move(index_vector)) - .AddIndex(std::move(index_varchar)) - .AddIndex(std::move(index_sort))); + .AddIndexParam(std::move(index_vector)) + .AddIndexParam(std::move(index_varchar)) + .AddIndexParam(std::move(index_sort))); util::CheckStatus("create indexes on collection", status); // create a partition diff --git a/examples/src/v2/default_value.cpp b/examples/src/v2/default_value.cpp index b6f2cd6f..282e1790 100644 --- a/examples/src/v2/default_value.cpp +++ b/examples/src/v2/default_value.cpp @@ -65,9 +65,9 @@ main(int argc, char* argv[]) { util::CheckStatus("create partition: " + partition_2, status); // create index - milvus::IndexDesc index_vector(field_vector, "", milvus::IndexType::HNSW, milvus::MetricType::L2); + milvus::IndexParam index_vector(field_vector, "", milvus::IndexType::HNSW, milvus::MetricType::L2); status = client->CreateIndex( - milvus::CreateIndexRequest().WithCollectionName(collection_name).AddIndex(std::move(index_vector))); + milvus::CreateIndexRequest().WithCollectionName(collection_name).AddIndexParam(std::move(index_vector))); util::CheckStatus("create index on vector field", status); // tell server prepare to load collection diff --git a/examples/src/v2/dml.cpp b/examples/src/v2/dml.cpp index bce9188f..08841d1a 100644 --- a/examples/src/v2/dml.cpp +++ b/examples/src/v2/dml.cpp @@ -56,14 +56,14 @@ buildCollection(milvus::MilvusClientV2Ptr& client, bool auto_id) { util::CheckStatus("create collection: " + std::string(collection_name), status); // create index - milvus::IndexDesc index_vector(field_vector, "", milvus::IndexType::HNSW, milvus::MetricType::L2); + milvus::IndexParam index_vector(field_vector, "", milvus::IndexType::HNSW, milvus::MetricType::L2); index_vector.AddExtraParam("M", "64"); index_vector.AddExtraParam("efConstruction", "200"); - milvus::IndexDesc index_text(field_text, "", milvus::IndexType::INVERTED); + milvus::IndexParam index_text(field_text, "", milvus::IndexType::INVERTED); status = client->CreateIndex(milvus::CreateIndexRequest() .WithCollectionName(collection_name) - .AddIndex(std::move(index_vector)) - .AddIndex(std::move(index_text))); + .AddIndexParam(std::move(index_vector)) + .AddIndexParam(std::move(index_text))); util::CheckStatus("create indexes on collection", status); // load collection diff --git a/examples/src/v2/dynamic_field.cpp b/examples/src/v2/dynamic_field.cpp index 205ece80..16b0ea4f 100644 --- a/examples/src/v2/dynamic_field.cpp +++ b/examples/src/v2/dynamic_field.cpp @@ -51,9 +51,9 @@ main(int argc, char* argv[]) { util::CheckStatus("create collection: " + collection_name, status); // create index - milvus::IndexDesc index_vector(field_vector, "", milvus::IndexType::IVF_SQ8, milvus::MetricType::IP); + milvus::IndexParam index_vector(field_vector, "", milvus::IndexType::IVF_SQ8, milvus::MetricType::IP); status = client->CreateIndex( - milvus::CreateIndexRequest().WithCollectionName(collection_name).AddIndex(std::move(index_vector))); + milvus::CreateIndexRequest().WithCollectionName(collection_name).AddIndexParam(std::move(index_vector))); util::CheckStatus("create index on vector field", status); // tell server prepare to load collection diff --git a/examples/src/v2/external_table.cpp b/examples/src/v2/external_table.cpp index 1d3b4f47..08bdfd90 100644 --- a/examples/src/v2/external_table.cpp +++ b/examples/src/v2/external_table.cpp @@ -99,7 +99,7 @@ verifyData(milvus::MilvusClientV2Ptr& client) { auto status = client->CreateIndex( milvus::CreateIndexRequest() .WithCollectionName(collection_name) - .AddIndex(milvus::IndexDesc(field_vector, "", milvus::IndexType::FLAT, milvus::MetricType::L2))); + .AddIndexParam(milvus::IndexParam(field_vector, "", milvus::IndexType::FLAT, milvus::MetricType::L2))); util::CheckStatus("create index on vector field", status); status = client->LoadCollection(milvus::LoadCollectionRequest().WithCollectionName(collection_name)); diff --git a/examples/src/v2/filter_template.cpp b/examples/src/v2/filter_template.cpp index bdc6bd85..33a65d8f 100644 --- a/examples/src/v2/filter_template.cpp +++ b/examples/src/v2/filter_template.cpp @@ -50,9 +50,9 @@ main(int argc, char* argv[]) { util::CheckStatus("create collection: " + collection_name, status); // create index - milvus::IndexDesc index_vector(field_vector, "", milvus::IndexType::FLAT, milvus::MetricType::L2); + milvus::IndexParam index_vector(field_vector, "", milvus::IndexType::FLAT, milvus::MetricType::L2); status = client->CreateIndex( - milvus::CreateIndexRequest().WithCollectionName(collection_name).AddIndex(std::move(index_vector))); + milvus::CreateIndexRequest().WithCollectionName(collection_name).AddIndexParam(std::move(index_vector))); util::CheckStatus("create index on vector field", status); // tell server prepare to load collection diff --git a/examples/src/v2/full_text_match.cpp b/examples/src/v2/full_text_match.cpp index 5251daae..f3d69980 100644 --- a/examples/src/v2/full_text_match.cpp +++ b/examples/src/v2/full_text_match.cpp @@ -49,10 +49,10 @@ buildCollection(milvus::MilvusClientV2Ptr& client) { util::CheckStatus(std::string("create collection: ") + collection_name, status); // create index - milvus::IndexDesc index_vector(field_vector, "", milvus::IndexType::SPARSE_INVERTED_INDEX, + milvus::IndexParam index_vector(field_vector, "", milvus::IndexType::SPARSE_INVERTED_INDEX, milvus::MetricType::BM25); status = client->CreateIndex( - milvus::CreateIndexRequest().WithCollectionName(collection_name).AddIndex(std::move(index_vector))); + milvus::CreateIndexRequest().WithCollectionName(collection_name).AddIndexParam(std::move(index_vector))); util::CheckStatus("create index on vector field", status); // tell server prepare to load collection diff --git a/examples/src/v2/function_chain.cpp b/examples/src/v2/function_chain.cpp index 46ce1e55..850d3b96 100644 --- a/examples/src/v2/function_chain.cpp +++ b/examples/src/v2/function_chain.cpp @@ -40,9 +40,9 @@ buildCollection(milvus::MilvusClientV2Ptr& client) { util::CheckStatus(std::string("create collection: ") + collection_name, status); // create index - milvus::IndexDesc index_vector(field_vector, "", milvus::IndexType::FLAT, milvus::MetricType::COSINE); + milvus::IndexParam index_vector(field_vector, "", milvus::IndexType::FLAT, milvus::MetricType::COSINE); status = client->CreateIndex( - milvus::CreateIndexRequest().WithCollectionName(collection_name).AddIndex(std::move(index_vector))); + milvus::CreateIndexRequest().WithCollectionName(collection_name).AddIndexParam(std::move(index_vector))); util::CheckStatus("create index on vector field", status); // tell server prepare to load collection diff --git a/examples/src/v2/general.cpp b/examples/src/v2/general.cpp index faf7fca2..9d44a26c 100644 --- a/examples/src/v2/general.cpp +++ b/examples/src/v2/general.cpp @@ -133,10 +133,10 @@ main(int argc, char* argv[]) { milvus::FieldSchema(field_face, milvus::DataType::FLOAT_VECTOR, "face signature").WithDimension(dimension)); // define indexes - milvus::IndexDesc index_vector(field_face, "", milvus::IndexType::IVF_FLAT, milvus::MetricType::COSINE); + milvus::IndexParam index_vector(field_face, "", milvus::IndexType::IVF_FLAT, milvus::MetricType::COSINE); index_vector.AddExtraParam(milvus::NLIST, "100"); - milvus::IndexDesc index_sort(field_age, "", milvus::IndexType::STL_SORT); - milvus::IndexDesc index_varchar(field_name, "", milvus::IndexType::TRIE); + milvus::IndexParam index_sort(field_age, "", milvus::IndexType::STL_SORT); + milvus::IndexParam index_varchar(field_name, "", milvus::IndexType::TRIE); // drop collection if it exists, the CreateCollectionRequest with indexes will automatically create indexes // for this collection and load the collection @@ -149,9 +149,9 @@ main(int argc, char* argv[]) { .WithDescription("my collection") .WithNumShards(1) .WithCollectionSchema(collection_schema) - .AddIndex(std::move(index_vector)) - .AddIndex(std::move(index_sort)) - .AddIndex(std::move(index_varchar)) + .AddIndexParam(std::move(index_vector)) + .AddIndexParam(std::move(index_sort)) + .AddIndexParam(std::move(index_varchar)) .AddProperty("my_prop", "dummy") // add a customized property .AddProperty(milvus::COLLECTION_TTL_SECONDS, "60") // configure a built-in property .WithConsistencyLevel(milvus::ConsistencyLevel::STRONG)); @@ -404,7 +404,7 @@ main(int argc, char* argv[]) { // create index again { - milvus::IndexDesc index_vector(field_face, "vector_index_name", milvus::IndexType::HNSW, + milvus::IndexParam index_vector(field_face, "vector_index_name", milvus::IndexType::HNSW, milvus::MetricType::L2); index_vector.AddExtraParam("M", "32"); index_vector.AddExtraParam("efConstruction", "100"); @@ -412,7 +412,7 @@ main(int argc, char* argv[]) { status = client->CreateIndex(milvus::CreateIndexRequest() .WithCollectionName(collection_name) .WithSync(true) - .AddIndex(std::move(index_vector))); + .AddIndexParam(std::move(index_vector))); util::CheckStatus("rebuild index for field: " + field_face, status); status = client->AlterIndexProperties(milvus::AlterIndexPropertiesRequest() diff --git a/examples/src/v2/geometry_field.cpp b/examples/src/v2/geometry_field.cpp index e95353c7..12810de1 100644 --- a/examples/src/v2/geometry_field.cpp +++ b/examples/src/v2/geometry_field.cpp @@ -130,9 +130,9 @@ main(int argc, char* argv[]) { util::CheckStatus("create collection: " + std::string(collection_name), status); // create index - milvus::IndexDesc index_vector(field_vector, "", milvus::IndexType::HNSW, milvus::MetricType::L2); + milvus::IndexParam index_vector(field_vector, "", milvus::IndexType::HNSW, milvus::MetricType::L2); status = client->CreateIndex( - milvus::CreateIndexRequest().WithCollectionName(collection_name).AddIndex(std::move(index_vector))); + milvus::CreateIndexRequest().WithCollectionName(collection_name).AddIndexParam(std::move(index_vector))); util::CheckStatus("create index on vector field", status); // tell server prepare to load collection diff --git a/examples/src/v2/group_by.cpp b/examples/src/v2/group_by.cpp index 5261d1b0..ed1c6929 100644 --- a/examples/src/v2/group_by.cpp +++ b/examples/src/v2/group_by.cpp @@ -96,9 +96,9 @@ main(int argc, char* argv[]) { util::CheckStatus("create collection: " + collection_name, status); // create index - milvus::IndexDesc index_vector(field_vector, "", milvus::IndexType::FLAT, milvus::MetricType::COSINE); + milvus::IndexParam index_vector(field_vector, "", milvus::IndexType::FLAT, milvus::MetricType::COSINE); status = client->CreateIndex( - milvus::CreateIndexRequest().WithCollectionName(collection_name).AddIndex(std::move(index_vector))); + milvus::CreateIndexRequest().WithCollectionName(collection_name).AddIndexParam(std::move(index_vector))); util::CheckStatus("create index on vector field", status); // tell server prepare to load collection diff --git a/examples/src/v2/highlighter.cpp b/examples/src/v2/highlighter.cpp index ed4b289f..c78c30e1 100644 --- a/examples/src/v2/highlighter.cpp +++ b/examples/src/v2/highlighter.cpp @@ -83,12 +83,12 @@ createCollection(milvus::MilvusClientV2Ptr& client) { collection_schema->AddFunction(function); auto status = client->DropCollection(milvus::DropCollectionRequest().WithCollectionName(collection_name)); - milvus::IndexDesc index_vector(field_vector, "", milvus::IndexType::SPARSE_INVERTED_INDEX, - milvus::MetricType::BM25); + milvus::IndexParam index_vector(field_vector, "", milvus::IndexType::SPARSE_INVERTED_INDEX, + milvus::MetricType::BM25); status = client->CreateCollection(milvus::CreateCollectionRequest() .WithCollectionName(collection_name) .WithCollectionSchema(collection_schema) - .AddIndex(std::move(index_vector)) + .AddIndexParam(std::move(index_vector)) .WithConsistencyLevel(milvus::ConsistencyLevel::BOUNDED)); util::CheckStatus(std::string("create collection: ") + collection_name, status); diff --git a/examples/src/v2/hybrid_search.cpp b/examples/src/v2/hybrid_search.cpp index 3a23a6b5..61c56667 100644 --- a/examples/src/v2/hybrid_search.cpp +++ b/examples/src/v2/hybrid_search.cpp @@ -55,11 +55,11 @@ main(int argc, char* argv[]) { util::CheckStatus("create collection: " + collection_name, status); // create index - std::vector indexes = { - milvus::IndexDesc(field_dense, "", milvus::IndexType::DISKANN, milvus::MetricType::COSINE), - milvus::IndexDesc(field_sparse, "", milvus::IndexType::SPARSE_INVERTED_INDEX, milvus::MetricType::IP)}; + std::vector indexes = { + milvus::IndexParam(field_dense, "", milvus::IndexType::DISKANN, milvus::MetricType::COSINE), + milvus::IndexParam(field_sparse, "", milvus::IndexType::SPARSE_INVERTED_INDEX, milvus::MetricType::IP)}; status = client->CreateIndex( - milvus::CreateIndexRequest().WithCollectionName(collection_name).WithIndexes(std::move(indexes))); + milvus::CreateIndexRequest().WithCollectionName(collection_name).WithIndexParams(std::move(indexes))); util::CheckStatus("create indexes on collection", status); // tell server prepare to load collection diff --git a/examples/src/v2/iterator_query.cpp b/examples/src/v2/iterator_query.cpp index 4eed2585..57a84734 100644 --- a/examples/src/v2/iterator_query.cpp +++ b/examples/src/v2/iterator_query.cpp @@ -53,9 +53,9 @@ main(int argc, char* argv[]) { util::CheckStatus("create collection: " + collection_name, status); // create index - milvus::IndexDesc index_vector(field_face, "", milvus::IndexType::AUTOINDEX, milvus::MetricType::L2); + milvus::IndexParam index_vector(field_face, "", milvus::IndexType::AUTOINDEX, milvus::MetricType::L2); status = client->CreateIndex( - milvus::CreateIndexRequest().WithCollectionName(collection_name).AddIndex(std::move(index_vector))); + milvus::CreateIndexRequest().WithCollectionName(collection_name).AddIndexParam(std::move(index_vector))); util::CheckStatus("create index on vector field", status); // tell server prepare to load collection diff --git a/examples/src/v2/iterator_search.cpp b/examples/src/v2/iterator_search.cpp index 4bf5442c..2fa16074 100644 --- a/examples/src/v2/iterator_search.cpp +++ b/examples/src/v2/iterator_search.cpp @@ -60,9 +60,9 @@ buildCollection(milvus::MilvusClientV2Ptr& client, milvus::MetricType index_metr // create index // Note that we use FLAT here, because other indexes cannot ensure that all entities can be featched by iterator - milvus::IndexDesc index_vector(field_face, "", milvus::IndexType::FLAT, index_metric); + milvus::IndexParam index_vector(field_face, "", milvus::IndexType::FLAT, index_metric); status = client->CreateIndex( - milvus::CreateIndexRequest().WithCollectionName(collection_name).AddIndex(std::move(index_vector))); + milvus::CreateIndexRequest().WithCollectionName(collection_name).AddIndexParam(std::move(index_vector))); util::CheckStatus("create index on vector field", status); // tell server prepare to load collection diff --git a/examples/src/v2/json.cpp b/examples/src/v2/json.cpp index 4abc8653..734d7adb 100644 --- a/examples/src/v2/json.cpp +++ b/examples/src/v2/json.cpp @@ -50,9 +50,9 @@ main(int argc, char* argv[]) { util::CheckStatus("create collection: " + collection_name, status); // create index - milvus::IndexDesc index_vector(field_vector, "", milvus::IndexType::FLAT, milvus::MetricType::COSINE); + milvus::IndexParam index_vector(field_vector, "", milvus::IndexType::FLAT, milvus::MetricType::COSINE); status = client->CreateIndex( - milvus::CreateIndexRequest().WithCollectionName(collection_name).AddIndex(std::move(index_vector))); + milvus::CreateIndexRequest().WithCollectionName(collection_name).AddIndexParam(std::move(index_vector))); util::CheckStatus("create index on vector field", status); // tell server prepare to load collection diff --git a/examples/src/v2/minhash_function.cpp b/examples/src/v2/minhash_function.cpp index 4056b4f9..4fff006b 100644 --- a/examples/src/v2/minhash_function.cpp +++ b/examples/src/v2/minhash_function.cpp @@ -55,11 +55,11 @@ createDedupCollection(milvus::MilvusClientV2Ptr& client) { milvus::CreateCollectionRequest().WithCollectionName(collection_name).WithCollectionSchema(schema)); util::CheckStatus(std::string("create collection: ") + collection_name, status); - milvus::IndexDesc index(signature_field, "", milvus::IndexType::MINHASH_LSH, milvus::MetricType::MHJACCARD); + milvus::IndexParam index(signature_field, "", milvus::IndexType::MINHASH_LSH, milvus::MetricType::MHJACCARD); index.AddExtraParam("mh_lsh_band", "8"); index.AddExtraParam("with_raw_data", "true"); status = client->CreateIndex( - milvus::CreateIndexRequest().WithCollectionName(collection_name).AddIndex(std::move(index))); + milvus::CreateIndexRequest().WithCollectionName(collection_name).AddIndexParam(std::move(index))); util::CheckStatus("create index on MinHash signature field", status); status = client->LoadCollection(milvus::LoadCollectionRequest().WithCollectionName(collection_name)); diff --git a/examples/src/v2/multi_analyzer.cpp b/examples/src/v2/multi_analyzer.cpp index 461f2c6e..45920ebe 100644 --- a/examples/src/v2/multi_analyzer.cpp +++ b/examples/src/v2/multi_analyzer.cpp @@ -74,10 +74,10 @@ buildCollection(milvus::MilvusClientV2Ptr& client) { util::CheckStatus(std::string("create collection: ") + collection_name, status); // create index - milvus::IndexDesc index_vector(field_vector, "", milvus::IndexType::SPARSE_INVERTED_INDEX, + milvus::IndexParam index_vector(field_vector, "", milvus::IndexType::SPARSE_INVERTED_INDEX, milvus::MetricType::BM25); status = client->CreateIndex( - milvus::CreateIndexRequest().WithCollectionName(collection_name).AddIndex(std::move(index_vector))); + milvus::CreateIndexRequest().WithCollectionName(collection_name).AddIndexParam(std::move(index_vector))); util::CheckStatus("create index on vector field", status); // tell server prepare to load collection diff --git a/examples/src/v2/nullable_field.cpp b/examples/src/v2/nullable_field.cpp index 4d34430d..e2ad4d60 100644 --- a/examples/src/v2/nullable_field.cpp +++ b/examples/src/v2/nullable_field.cpp @@ -70,9 +70,9 @@ main(int argc, char* argv[]) { util::CheckStatus("create partition: " + partition_2, status); // create index - milvus::IndexDesc index_vector(field_vector, "", milvus::IndexType::HNSW, milvus::MetricType::L2); + milvus::IndexParam index_vector(field_vector, "", milvus::IndexType::HNSW, milvus::MetricType::L2); status = client->CreateIndex( - milvus::CreateIndexRequest().WithCollectionName(collection_name).AddIndex(std::move(index_vector))); + milvus::CreateIndexRequest().WithCollectionName(collection_name).AddIndexParam(std::move(index_vector))); util::CheckStatus("create index on vector field", status); // tell server prepare to load collection diff --git a/examples/src/v2/nullable_vector.cpp b/examples/src/v2/nullable_vector.cpp index d159242a..bfe3b9b0 100644 --- a/examples/src/v2/nullable_vector.cpp +++ b/examples/src/v2/nullable_vector.cpp @@ -47,7 +47,7 @@ InsertNullVectors(const milvus::MilvusClientV2Ptr& client) { status = client->CreateIndex( milvus::CreateIndexRequest() .WithCollectionName(collection_name) - .AddIndex(milvus::IndexDesc(field_vector, "", milvus::IndexType::FLAT, milvus::MetricType::L2))); + .AddIndexParam(milvus::IndexParam(field_vector, "", milvus::IndexType::FLAT, milvus::MetricType::L2))); util::CheckStatus("create index", status); status = client->LoadCollection(milvus::LoadCollectionRequest().WithCollectionName(collection_name)); @@ -144,7 +144,7 @@ AddNullableVectorField(const milvus::MilvusClientV2Ptr& client) { status = client->CreateIndex( milvus::CreateIndexRequest() .WithCollectionName(collection_name) - .AddIndex(milvus::IndexDesc(field_vector_v1, "", milvus::IndexType::FLAT, milvus::MetricType::L2))); + .AddIndexParam(milvus::IndexParam(field_vector_v1, "", milvus::IndexType::FLAT, milvus::MetricType::L2))); util::CheckStatus("create initial index", status); status = client->LoadCollection(milvus::LoadCollectionRequest().WithCollectionName(collection_name)); @@ -174,7 +174,7 @@ AddNullableVectorField(const milvus::MilvusClientV2Ptr& client) { status = client->CreateIndex( milvus::CreateIndexRequest() .WithCollectionName(collection_name) - .AddIndex(milvus::IndexDesc(field_vector_v2, "", milvus::IndexType::FLAT, milvus::MetricType::L2))); + .AddIndexParam(milvus::IndexParam(field_vector_v2, "", milvus::IndexType::FLAT, milvus::MetricType::L2))); util::CheckStatus("create index for added field", status); status = client->LoadCollection(milvus::LoadCollectionRequest().WithCollectionName(collection_name)); diff --git a/examples/src/v2/optimize.cpp b/examples/src/v2/optimize.cpp index 77dfc355..ea082699 100644 --- a/examples/src/v2/optimize.cpp +++ b/examples/src/v2/optimize.cpp @@ -101,11 +101,11 @@ main(int argc, char* argv[]) { std::cout << "Total inserted: " << total_inserted << " rows" << std::endl; std::cout << "========== Step 3: Create IVF_FLAT index ==========" << std::endl; - milvus::IndexDesc index(vector_field, "", milvus::IndexType::IVF_FLAT, milvus::MetricType::L2); + milvus::IndexParam index(vector_field, "", milvus::IndexType::IVF_FLAT, milvus::MetricType::L2); index.AddExtraParam("nlist", "32"); status = client->CreateIndex(milvus::CreateIndexRequest() .WithCollectionName(collection_name) - .AddIndex(std::move(index)) + .AddIndexParam(std::move(index)) .WithTimeoutMs(100000)); util::CheckStatus("create IVF_FLAT index", status); diff --git a/examples/src/v2/order_by.cpp b/examples/src/v2/order_by.cpp index 4228dd5e..9ae9872f 100644 --- a/examples/src/v2/order_by.cpp +++ b/examples/src/v2/order_by.cpp @@ -103,13 +103,13 @@ prepareCollection(milvus::MilvusClientV2Ptr& client) { schema->AddField({metadata_field, milvus::DataType::JSON}); schema->AddField(milvus::FieldSchema(vector_field, milvus::DataType::FLOAT_VECTOR).WithDimension(dimension)); - milvus::IndexDesc index(vector_field, "", milvus::IndexType::IVF_FLAT, milvus::MetricType::L2); + milvus::IndexParam index(vector_field, "", milvus::IndexType::IVF_FLAT, milvus::MetricType::L2); index.AddExtraParam("nlist", "128"); auto request = milvus::CreateCollectionRequest() .WithCollectionName(collection_name) .WithCollectionSchema(schema) .WithConsistencyLevel(milvus::ConsistencyLevel::BOUNDED) - .AddIndex(std::move(index)); + .AddIndexParam(std::move(index)); auto status = client->CreateCollection(request); util::CheckStatus(std::string("create collection: ") + collection_name, status); diff --git a/examples/src/v2/partition_key.cpp b/examples/src/v2/partition_key.cpp index cc42baf6..2b5cf361 100644 --- a/examples/src/v2/partition_key.cpp +++ b/examples/src/v2/partition_key.cpp @@ -55,11 +55,11 @@ main(int argc, char* argv[]) { util::CheckStatus("create collection: " + collection_name, status); // create index (required after 2.2.0) - milvus::IndexDesc index_vector(field_vector, "", milvus::IndexType::HNSW, milvus::MetricType::IP); + milvus::IndexParam index_vector(field_vector, "", milvus::IndexType::HNSW, milvus::MetricType::IP); index_vector.AddExtraParam("M", "64"); index_vector.AddExtraParam("efConstruction", "100"); status = client->CreateIndex( - milvus::CreateIndexRequest().WithCollectionName(collection_name).AddIndex(std::move(index_vector))); + milvus::CreateIndexRequest().WithCollectionName(collection_name).AddIndexParam(std::move(index_vector))); util::CheckStatus("create index on vector field", status); // tell server prepare to load collection diff --git a/examples/src/v2/rbac.cpp b/examples/src/v2/rbac.cpp index 5fa181de..0327d518 100644 --- a/examples/src/v2/rbac.cpp +++ b/examples/src/v2/rbac.cpp @@ -92,9 +92,9 @@ main(int argc, char* argv[]) { milvus::CreateCollectionRequest().WithCollectionName(collection_name).WithCollectionSchema(collection_schema)); util::CheckStatus("create collection: " + collection_name, status); - milvus::IndexDesc index_vector("vector", "", milvus::IndexType::AUTOINDEX, milvus::MetricType::L2); + milvus::IndexParam index_vector("vector", "", milvus::IndexType::AUTOINDEX, milvus::MetricType::L2); status = client->CreateIndex( - milvus::CreateIndexRequest().WithCollectionName(collection_name).AddIndex(std::move(index_vector))); + milvus::CreateIndexRequest().WithCollectionName(collection_name).AddIndexParam(std::move(index_vector))); util::CheckStatus("create index on vector field", status); status = client->LoadCollection(milvus::LoadCollectionRequest().WithCollectionName(collection_name)); diff --git a/examples/src/v2/rerank_function.cpp b/examples/src/v2/rerank_function.cpp index 79980591..31e9979d 100644 --- a/examples/src/v2/rerank_function.cpp +++ b/examples/src/v2/rerank_function.cpp @@ -43,9 +43,9 @@ buildCollection(milvus::MilvusClientV2Ptr& client) { util::CheckStatus(std::string("create collection: ") + collection_name, status); // create index - milvus::IndexDesc index_vector(field_vector, "", milvus::IndexType::FLAT, milvus::MetricType::COSINE); + milvus::IndexParam index_vector(field_vector, "", milvus::IndexType::FLAT, milvus::MetricType::COSINE); status = client->CreateIndex( - milvus::CreateIndexRequest().WithCollectionName(collection_name).AddIndex(std::move(index_vector))); + milvus::CreateIndexRequest().WithCollectionName(collection_name).AddIndexParam(std::move(index_vector))); util::CheckStatus("create index on vector field", status); // tell server prepare to load collection diff --git a/examples/src/v2/search_aggregation.cpp b/examples/src/v2/search_aggregation.cpp index 817b6f6f..2504c46f 100644 --- a/examples/src/v2/search_aggregation.cpp +++ b/examples/src/v2/search_aggregation.cpp @@ -165,13 +165,13 @@ buildCollection(milvus::MilvusClientV2Ptr& client) { schema->AddField({field_meta, milvus::DataType::JSON}); schema->AddField(milvus::FieldSchema(field_embedding, milvus::DataType::FLOAT_VECTOR).WithDimension(dimension)); - milvus::IndexDesc vector_index(field_embedding, "", milvus::IndexType::IVF_FLAT, milvus::MetricType::L2); + milvus::IndexParam vector_index(field_embedding, "", milvus::IndexType::IVF_FLAT, milvus::MetricType::L2); vector_index.AddExtraParam("nlist", "128"); auto create_request = milvus::CreateCollectionRequest() .WithCollectionName(collection_name) .WithCollectionSchema(schema) .WithConsistencyLevel(milvus::ConsistencyLevel::BOUNDED) - .AddIndex(std::move(vector_index)); + .AddIndexParam(std::move(vector_index)); auto status = client->CreateCollection(create_request); util::CheckStatus("create collection: " + std::string(collection_name), status); diff --git a/examples/src/v2/struct_field.cpp b/examples/src/v2/struct_field.cpp index aaad791d..8f032139 100644 --- a/examples/src/v2/struct_field.cpp +++ b/examples/src/v2/struct_field.cpp @@ -91,28 +91,28 @@ createCollection(milvus::MilvusClientV2Ptr& client) { milvus::CreateCollectionRequest().WithCollectionName(collection_name).WithCollectionSchema(collection_schema)); util::CheckStatus("create collection: " + std::string(collection_name), status); - milvus::IndexDesc index_struct_float(combineStructName(field_struct, field_struct_vector), "index_float", + milvus::IndexParam index_struct_float(combineStructName(field_struct, field_struct_vector), "index_float", milvus::IndexType::HNSW, milvus::MetricType::MAX_SIM_IP); - milvus::IndexDesc index_struct_binary(combineStructName(field_struct, field_struct_binary_vector), "index_binary", + milvus::IndexParam index_struct_binary(combineStructName(field_struct, field_struct_binary_vector), "index_binary", milvus::IndexType::HNSW, milvus::MetricType::MAX_SIM_HAMMING); - milvus::IndexDesc index_struct_fp16(combineStructName(field_struct, field_struct_fp16_vector), "index_float16", + milvus::IndexParam index_struct_fp16(combineStructName(field_struct, field_struct_fp16_vector), "index_float16", milvus::IndexType::IVF_FLAT, milvus::MetricType::MAX_SIM_COSINE); index_struct_fp16.AddExtraParam(milvus::NLIST, "64"); - milvus::IndexDesc index_struct_bf16(combineStructName(field_struct, field_struct_bf16_vector), "index_bfloat16", + milvus::IndexParam index_struct_bf16(combineStructName(field_struct, field_struct_bf16_vector), "index_bfloat16", milvus::IndexType::IVF_FLAT, milvus::MetricType::MAX_SIM_COSINE); index_struct_bf16.AddExtraParam(milvus::NLIST, "64"); - milvus::IndexDesc index_struct_int8(combineStructName(field_struct, field_struct_int8_vector), "index_int8", + milvus::IndexParam index_struct_int8(combineStructName(field_struct, field_struct_int8_vector), "index_int8", milvus::IndexType::HNSW, milvus::MetricType::MAX_SIM_L2); - milvus::IndexDesc index_simplify(combineStructName(field_simplify_struct, field_struct_vector), "index_simplify", + milvus::IndexParam index_simplify(combineStructName(field_simplify_struct, field_struct_vector), "index_simplify", milvus::IndexType::HNSW, milvus::MetricType::L2); status = client->CreateIndex(milvus::CreateIndexRequest() .WithCollectionName(collection_name) - .AddIndex(std::move(index_struct_float)) - .AddIndex(std::move(index_struct_binary)) - .AddIndex(std::move(index_struct_fp16)) - .AddIndex(std::move(index_struct_bf16)) - .AddIndex(std::move(index_struct_int8)) - .AddIndex(std::move(index_simplify))); + .AddIndexParam(std::move(index_struct_float)) + .AddIndexParam(std::move(index_struct_binary)) + .AddIndexParam(std::move(index_struct_fp16)) + .AddIndexParam(std::move(index_struct_bf16)) + .AddIndexParam(std::move(index_struct_int8)) + .AddIndexParam(std::move(index_simplify))); util::CheckStatus("create index on struct vector fields", status); status = client->LoadCollection(milvus::LoadCollectionRequest().WithCollectionName(collection_name)); diff --git a/examples/src/v2/text_field.cpp b/examples/src/v2/text_field.cpp index 7bb062b4..f8615e50 100644 --- a/examples/src/v2/text_field.cpp +++ b/examples/src/v2/text_field.cpp @@ -114,9 +114,9 @@ main(int argc, char* argv[]) { util::CheckStatus("create collection: " + std::string(collection_name), status); // create index - milvus::IndexDesc index_vector(field_vector, "", milvus::IndexType::FLAT, milvus::MetricType::L2); + milvus::IndexParam index_vector(field_vector, "", milvus::IndexType::FLAT, milvus::MetricType::L2); status = client->CreateIndex( - milvus::CreateIndexRequest().WithCollectionName(collection_name).AddIndex(std::move(index_vector))); + milvus::CreateIndexRequest().WithCollectionName(collection_name).AddIndexParam(std::move(index_vector))); util::CheckStatus("create index on vector field", status); // tell server prepare to load collection diff --git a/examples/src/v2/text_match.cpp b/examples/src/v2/text_match.cpp index 0b2eb8ee..057fbe1d 100644 --- a/examples/src/v2/text_match.cpp +++ b/examples/src/v2/text_match.cpp @@ -54,9 +54,9 @@ buildCollection(milvus::MilvusClientV2Ptr& client) { util::CheckStatus(std::string("create collection: ") + collection_name, status); // create index - milvus::IndexDesc index_vector(field_vector, "", milvus::IndexType::IVF_FLAT, milvus::MetricType::COSINE); + milvus::IndexParam index_vector(field_vector, "", milvus::IndexType::IVF_FLAT, milvus::MetricType::COSINE); status = client->CreateIndex( - milvus::CreateIndexRequest().WithCollectionName(collection_name).AddIndex(std::move(index_vector))); + milvus::CreateIndexRequest().WithCollectionName(collection_name).AddIndexParam(std::move(index_vector))); util::CheckStatus("create index on vector field", status); // tell server prepare to load collection diff --git a/examples/src/v2/timestamptz_field.cpp b/examples/src/v2/timestamptz_field.cpp index 2350772c..22c21dee 100644 --- a/examples/src/v2/timestamptz_field.cpp +++ b/examples/src/v2/timestamptz_field.cpp @@ -194,9 +194,9 @@ main(int argc, char* argv[]) { util::CheckStatus("create collection: " + std::string(collection_name), status); // create index - milvus::IndexDesc index_vector(field_vector, "", milvus::IndexType::HNSW, milvus::MetricType::L2); + milvus::IndexParam index_vector(field_vector, "", milvus::IndexType::HNSW, milvus::MetricType::L2); status = client->CreateIndex( - milvus::CreateIndexRequest().WithCollectionName(collection_name).AddIndex(std::move(index_vector))); + milvus::CreateIndexRequest().WithCollectionName(collection_name).AddIndexParam(std::move(index_vector))); util::CheckStatus("create index on vector field", status); // tell server prepare to load collection diff --git a/examples/src/v2/vector_binary.cpp b/examples/src/v2/vector_binary.cpp index 09107b65..584c4a38 100644 --- a/examples/src/v2/vector_binary.cpp +++ b/examples/src/v2/vector_binary.cpp @@ -90,10 +90,10 @@ main(int argc, char* argv[]) { util::CheckStatus("create collection: " + collection_name, status); // create index - milvus::IndexDesc index_vector(field_vector, "", milvus::IndexType::BIN_IVF_FLAT, milvus::MetricType::HAMMING); + milvus::IndexParam index_vector(field_vector, "", milvus::IndexType::BIN_IVF_FLAT, milvus::MetricType::HAMMING); index_vector.AddExtraParam(milvus::NLIST, "5"); status = client->CreateIndex( - milvus::CreateIndexRequest().WithCollectionName(collection_name).AddIndex(std::move(index_vector))); + milvus::CreateIndexRequest().WithCollectionName(collection_name).AddIndexParam(std::move(index_vector))); util::CheckStatus("create index on vector field", status); // tell server prepare to load collection diff --git a/examples/src/v2/vector_fp16.cpp b/examples/src/v2/vector_fp16.cpp index 82f8602e..8ef888a7 100644 --- a/examples/src/v2/vector_fp16.cpp +++ b/examples/src/v2/vector_fp16.cpp @@ -53,12 +53,12 @@ main(int argc, char* argv[]) { util::CheckStatus("create collection: " + collection_name, status); // create index - milvus::IndexDesc index_vector_fp16(field_vec_fp16, "", milvus::IndexType::AUTOINDEX, milvus::MetricType::COSINE); - milvus::IndexDesc index_vector_bf16(field_vec_bf16, "", milvus::IndexType::AUTOINDEX, milvus::MetricType::COSINE); + milvus::IndexParam index_vector_fp16(field_vec_fp16, "", milvus::IndexType::AUTOINDEX, milvus::MetricType::COSINE); + milvus::IndexParam index_vector_bf16(field_vec_bf16, "", milvus::IndexType::AUTOINDEX, milvus::MetricType::COSINE); status = client->CreateIndex(milvus::CreateIndexRequest() .WithCollectionName(collection_name) - .AddIndex(std::move(index_vector_fp16)) - .AddIndex(std::move(index_vector_bf16))); + .AddIndexParam(std::move(index_vector_fp16)) + .AddIndexParam(std::move(index_vector_bf16))); util::CheckStatus("create indexes on collection", status); // insert some rows diff --git a/examples/src/v2/vector_int8.cpp b/examples/src/v2/vector_int8.cpp index a19fd8c5..04a65141 100644 --- a/examples/src/v2/vector_int8.cpp +++ b/examples/src/v2/vector_int8.cpp @@ -60,9 +60,9 @@ main(int argc, char* argv[]) { util::CheckStatus("create collection: " + collection_name, status); // create index - milvus::IndexDesc index_vector(field_vector, "", milvus::IndexType::HNSW, milvus::MetricType::L2); + milvus::IndexParam index_vector(field_vector, "", milvus::IndexType::HNSW, milvus::MetricType::L2); status = client->CreateIndex( - milvus::CreateIndexRequest().WithCollectionName(collection_name).AddIndex(std::move(index_vector))); + milvus::CreateIndexRequest().WithCollectionName(collection_name).AddIndexParam(std::move(index_vector))); util::CheckStatus("create index on vector field", status); // tell server prepare to load collection diff --git a/examples/src/v2/vector_sparse.cpp b/examples/src/v2/vector_sparse.cpp index 8cf98005..a46bf8e9 100644 --- a/examples/src/v2/vector_sparse.cpp +++ b/examples/src/v2/vector_sparse.cpp @@ -48,9 +48,9 @@ main(int argc, char* argv[]) { util::CheckStatus("create collection: " + collection_name, status); // create index - milvus::IndexDesc index_vector(field_vector, "", milvus::IndexType::SPARSE_INVERTED_INDEX, milvus::MetricType::IP); + milvus::IndexParam index_vector(field_vector, "", milvus::IndexType::SPARSE_INVERTED_INDEX, milvus::MetricType::IP); status = client->CreateIndex( - milvus::CreateIndexRequest().WithCollectionName(collection_name).AddIndex(std::move(index_vector))); + milvus::CreateIndexRequest().WithCollectionName(collection_name).AddIndexParam(std::move(index_vector))); util::CheckStatus("create index on vector field", status); // tell server prepare to load collection diff --git a/src/impl/MilvusClientV2Impl.cpp b/src/impl/MilvusClientV2Impl.cpp index 60541825..b18b7f39 100644 --- a/src/impl/MilvusClientV2Impl.cpp +++ b/src/impl/MilvusClientV2Impl.cpp @@ -227,15 +227,15 @@ MilvusClientV2Impl::CreateCollection(const CreateCollectionRequest& request) { // collection was created or the existing collection was kept. SchemaCache::GetInstance().Invalidate(endpoint, database_name, request.CollectionName()); - if (request.Indexes().empty()) { + if (request.IndexParams().empty()) { return Status::OK(); } // if user has defined indexes, create indexes immediately after collection is created. // note that Sync is false since the new collection empty, no need to wait index. - const auto& descs = request.Indexes(); - for (const auto& desc : descs) { - auto status = createIndex(request.DatabaseName(), schema.Name(), desc, false, 0); + const auto& index_params = request.IndexParams(); + for (const auto& index_param : index_params) { + auto status = createIndex(request.DatabaseName(), schema.Name(), index_param, false, 0); if (!status.IsOk()) { return status; } @@ -273,14 +273,14 @@ MilvusClientV2Impl::CreateCollection(const CreateSimpleCollectionRequest& reques collection_schema->AddField(std::move(vector_field)); collection_schema->SetEnableDynamicField(request.EnableDynamicField()); - milvus::IndexDesc index_vector(request.VectorFieldName(), "", milvus::IndexType::AUTOINDEX, request.MetricType()); + milvus::IndexParam index_vector(request.VectorFieldName(), "", milvus::IndexType::AUTOINDEX, request.MetricType()); CreateCollectionRequest actual_request = CreateCollectionRequest() .WithCollectionName(request.CollectionName()) .WithDatabaseName(request.DatabaseName()) .WithCollectionSchema(collection_schema) .WithConsistencyLevel(request.ConsistencyLevel()) - .AddIndex(std::move(index_vector)); + .AddIndexParam(std::move(index_vector)); return CreateCollection(actual_request); } @@ -1577,13 +1577,14 @@ MilvusClientV2Impl::DescribeDatabase(const DescribeDatabaseRequest& request, Des Status MilvusClientV2Impl::CreateIndex(const CreateIndexRequest& request) { - const auto& descs = request.Indexes(); - if (descs.empty()) { + const auto& index_params = request.IndexParams(); + if (index_params.empty()) { return Status{StatusCode::INVALID_ARGUMENT, "IndexParams is empty, no index can be created"}; } - for (const auto& desc : descs) { + for (const auto& index_param : index_params) { auto status = - createIndex(request.DatabaseName(), request.CollectionName(), desc, request.Sync(), request.TimeoutMs()); + createIndex(request.DatabaseName(), request.CollectionName(), index_param, request.Sync(), + request.TimeoutMs()); if (!status.IsOk()) { return status; } @@ -4157,28 +4158,39 @@ MilvusClientV2Impl::RemovePrivilegesFromGroup(const RemovePrivilegesFromGroupReq /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // internal used methods Status -MilvusClientV2Impl::createIndex(const std::string& db_name, const std::string& collection_name, const IndexDesc& desc, - bool sync, int64_t timeout_ms) { - auto pre = [&db_name, &collection_name, &desc](proto::milvus::CreateIndexRequest& rpc_request) { +MilvusClientV2Impl::createIndex(const std::string& db_name, const std::string& collection_name, + const IndexParam& index_param, bool sync, int64_t timeout_ms) { + return createIndex(db_name, collection_name, index_param.FieldName(), index_param.IndexName(), + index_param.IndexType(), index_param.MetricType(), index_param.ExtraParams(), sync, timeout_ms); +} + +Status +MilvusClientV2Impl::createIndex(const std::string& db_name, const std::string& collection_name, + const std::string& field_name, const std::string& index_name, + milvus::IndexType index_type, milvus::MetricType metric_type, + const std::unordered_map& extra_params, bool sync, + int64_t timeout_ms) { + auto pre = [&db_name, &collection_name, &field_name, &index_name, index_type, metric_type, + &extra_params](proto::milvus::CreateIndexRequest& rpc_request) { rpc_request.set_db_name(db_name); rpc_request.set_collection_name(collection_name); - rpc_request.set_field_name(desc.FieldName()); - rpc_request.set_index_name(desc.IndexName()); + rpc_request.set_field_name(field_name); + rpc_request.set_index_name(index_name); auto kv_pair = rpc_request.add_extra_params(); kv_pair->set_key(milvus::INDEX_TYPE); - kv_pair->set_value(std::to_string(desc.IndexType())); + kv_pair->set_value(std::to_string(index_type)); // for scalar fields, no metric type - if (desc.MetricType() != MetricType::DEFAULT) { + if (metric_type != MetricType::DEFAULT) { kv_pair = rpc_request.add_extra_params(); kv_pair->set_key(milvus::METRIC_TYPE); - kv_pair->set_value(std::to_string(desc.MetricType())); + kv_pair->set_value(std::to_string(metric_type)); } kv_pair = rpc_request.add_extra_params(); kv_pair->set_key(milvus::PARAMS); - ::nlohmann::json json_obj(desc.ExtraParams()); + ::nlohmann::json json_obj(extra_params); kv_pair->set_value(json_obj.dump()); return Status::OK(); @@ -4200,15 +4212,16 @@ MilvusClientV2Impl::createIndex(const std::string& db_name, const std::string& c if (timeout_ms > 0) { progress_monitor = ProgressMonitor{static_cast(timeout_ms + 999) / 1000}; } - auto wait_for_status = [&db_name, &collection_name, &desc, &progress_monitor, this](const proto::common::Status&) { + auto wait_for_status = [&db_name, &collection_name, &field_name, &progress_monitor, this]( + const proto::common::Status&) { return ConnectionHandler::WaitForStatus( - [&db_name, &collection_name, &desc, this](Progress& progress) -> Status { + [&db_name, &collection_name, &field_name, this](Progress& progress) -> Status { progress.total_ = 100; DescribeIndexRequest request = DescribeIndexRequest() .WithDatabaseName(db_name) .WithCollectionName(collection_name) - .WithFieldName(desc.FieldName()); + .WithFieldName(field_name); DescribeIndexResponse response; auto status = DescribeIndex(request, response); if (!status.IsOk()) { diff --git a/src/impl/MilvusClientV2Impl.h b/src/impl/MilvusClientV2Impl.h index 53eb6d4f..85661fad 100644 --- a/src/impl/MilvusClientV2Impl.h +++ b/src/impl/MilvusClientV2Impl.h @@ -462,8 +462,13 @@ class MilvusClientV2Impl : public MilvusClientV2, public std::enable_shared_from queryIterator(QueryIteratorRequest& request, QueryIteratorPtr& iterator, const std::string& cluster_id); Status - createIndex(const std::string& db_name, const std::string& collection_name, const IndexDesc& desc, bool sync, - int64_t timeout_ms); + createIndex(const std::string& db_name, const std::string& collection_name, const IndexParam& index_param, + bool sync, int64_t timeout_ms); + + Status + createIndex(const std::string& db_name, const std::string& collection_name, const std::string& field_name, + const std::string& index_name, milvus::IndexType index_type, milvus::MetricType metric_type, + const std::unordered_map& extra_params, bool sync, int64_t timeout_ms); Status getFlushState(const std::string& db_name, const std::vector& segments, uint64_t flush_ts, bool& flushed); diff --git a/src/impl/request/collection/CreateCollectionRequest.cpp b/src/impl/request/collection/CreateCollectionRequest.cpp index ae253737..4cf6a853 100644 --- a/src/impl/request/collection/CreateCollectionRequest.cpp +++ b/src/impl/request/collection/CreateCollectionRequest.cpp @@ -18,6 +18,8 @@ #include +#include "../../utils/IndexUtils.h" + namespace milvus { const std::string& @@ -182,14 +184,44 @@ CreateCollectionRequest::AddProperty(const std::string& key, const std::string& return *this; } -const std::vector& +const std::vector& +CreateCollectionRequest::IndexParams() const { + return index_params_; +} + +void +CreateCollectionRequest::SetIndexParams(std::vector&& index_params) { + index_params_ = std::move(index_params); +} + +CreateCollectionRequest& +CreateCollectionRequest::WithIndexParams(std::vector&& index_params) { + SetIndexParams(std::move(index_params)); + return *this; +} + +CreateCollectionRequest& +CreateCollectionRequest::AddIndexParam(IndexParam&& index_param) { + index_params_.emplace_back(std::move(index_param)); + return *this; +} + +std::vector CreateCollectionRequest::Indexes() const { - return indexes_; + std::vector indexes; + indexes.reserve(index_params_.size()); + for (const auto& index_param : index_params_) { + indexes.emplace_back(ConvertToIndexDesc(index_param)); + } + return indexes; } void CreateCollectionRequest::SetIndexes(std::vector&& indexes) { - indexes_ = std::move(indexes); + index_params_.clear(); + for (const auto& desc : indexes) { + index_params_.emplace_back(ConvertToIndexParam(desc)); + } } CreateCollectionRequest& @@ -200,7 +232,7 @@ CreateCollectionRequest::WithIndexes(std::vector&& indexes) { CreateCollectionRequest& CreateCollectionRequest::AddIndex(IndexDesc&& index) { - indexes_.emplace_back(std::move(index)); + index_params_.emplace_back(ConvertToIndexParam(index)); return *this; } diff --git a/src/impl/request/index/CreateIndexRequest.cpp b/src/impl/request/index/CreateIndexRequest.cpp index 9ffe7405..8b2fc554 100644 --- a/src/impl/request/index/CreateIndexRequest.cpp +++ b/src/impl/request/index/CreateIndexRequest.cpp @@ -18,16 +18,48 @@ #include +#include "../../utils/IndexUtils.h" + namespace milvus { -const std::vector& +const std::vector& +CreateIndexRequest::IndexParams() const { + return index_params_; +} + +void +CreateIndexRequest::SetIndexParams(std::vector&& index_params) { + index_params_ = std::move(index_params); +} + +CreateIndexRequest& +CreateIndexRequest::WithIndexParams(std::vector&& index_params) { + SetIndexParams(std::move(index_params)); + return *this; +} + +CreateIndexRequest& +CreateIndexRequest::AddIndexParam(IndexParam&& index_param) { + index_params_.emplace_back(std::move(index_param)); + return *this; +} + +std::vector CreateIndexRequest::Indexes() const { - return indexes_; + std::vector indexes; + indexes.reserve(index_params_.size()); + for (const auto& index_param : index_params_) { + indexes.emplace_back(ConvertToIndexDesc(index_param)); + } + return indexes; } void CreateIndexRequest::SetIndexes(std::vector&& indexes) { - indexes_ = std::move(indexes); + index_params_.clear(); + for (const auto& desc : indexes) { + index_params_.emplace_back(ConvertToIndexParam(desc)); + } } CreateIndexRequest& @@ -38,7 +70,7 @@ CreateIndexRequest::WithIndexes(std::vector&& indexes) { CreateIndexRequest& CreateIndexRequest::AddIndex(IndexDesc&& index) { - indexes_.emplace_back(std::move(index)); + index_params_.emplace_back(ConvertToIndexParam(index)); return *this; } diff --git a/src/impl/types/IndexParam.cpp b/src/impl/types/IndexParam.cpp new file mode 100644 index 00000000..1e0e4438 --- /dev/null +++ b/src/impl/types/IndexParam.cpp @@ -0,0 +1,101 @@ +// Licensed to the LF AI & Data foundation under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include "milvus/types/IndexParam.h" + +#include + +namespace milvus { + +IndexParam::IndexParam() = default; + +IndexParam::IndexParam(std::string field_name, std::string index_name, milvus::IndexType index_type, + milvus::MetricType metric_type) + : field_name_(std::move(field_name)), + index_name_(std::move(index_name)), + metric_type_(metric_type), + index_type_(index_type) { +} + +const std::string& +IndexParam::FieldName() const { + return field_name_; +} + +Status +IndexParam::SetFieldName(std::string field_name) { + field_name_ = std::move(field_name); + return Status::OK(); +} + +const std::string& +IndexParam::IndexName() const { + return index_name_; +} + +Status +IndexParam::SetIndexName(std::string index_name) { + index_name_ = std::move(index_name); + return Status::OK(); +} + +milvus::MetricType +IndexParam::MetricType() const { + return metric_type_; +} + +Status +IndexParam::SetMetricType(milvus::MetricType metric_type) { + metric_type_ = metric_type; + return Status::OK(); +} + +milvus::IndexType +IndexParam::IndexType() const { + return index_type_; +} + +Status +IndexParam::SetIndexType(milvus::IndexType index_type) { + index_type_ = index_type; + return Status::OK(); +} + +Status +IndexParam::AddExtraParam(const std::string& key, const std::string& value) { + extra_params_[key] = value; + return Status::OK(); +} + +const std::unordered_map& +IndexParam::ExtraParams() const { + return extra_params_; +} + +Status +IndexParam::ExtraParamsFromJson(std::string json) { + try { + std::unordered_map temp = ::nlohmann::json::parse(std::move(json)); + for (const auto& pair : temp) { + extra_params_.insert(pair); + } + } catch (const ::nlohmann::json::exception& e) { + return {StatusCode::JSON_PARSE_ERROR, e.what()}; + } + return Status::OK(); +} + +} // namespace milvus diff --git a/src/impl/utils/IndexUtils.h b/src/impl/utils/IndexUtils.h new file mode 100644 index 00000000..89cba962 --- /dev/null +++ b/src/impl/utils/IndexUtils.h @@ -0,0 +1,42 @@ +// Licensed to the LF AI & Data foundation under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#pragma once + +#include "milvus/types/IndexDesc.h" +#include "milvus/types/IndexParam.h" + +namespace milvus { + +inline IndexParam +ConvertToIndexParam(const IndexDesc& desc) { + IndexParam index_param(desc.FieldName(), desc.IndexName(), desc.IndexType(), desc.MetricType()); + for (const auto& extra_param : desc.ExtraParams()) { + index_param.AddExtraParam(extra_param.first, extra_param.second); + } + return index_param; +} + +inline IndexDesc +ConvertToIndexDesc(const IndexParam& index_param) { + IndexDesc desc(index_param.FieldName(), index_param.IndexName(), index_param.IndexType(), index_param.MetricType()); + for (const auto& extra_param : index_param.ExtraParams()) { + desc.AddExtraParam(extra_param.first, extra_param.second); + } + return desc; +} + +} // namespace milvus diff --git a/src/include/milvus/request/collection/CreateCollectionRequest.h b/src/include/milvus/request/collection/CreateCollectionRequest.h index 90329a5c..555128cc 100644 --- a/src/include/milvus/request/collection/CreateCollectionRequest.h +++ b/src/include/milvus/request/collection/CreateCollectionRequest.h @@ -21,6 +21,7 @@ #include "../../types/CollectionSchema.h" #include "../../types/ConsistencyLevel.h" #include "../../types/IndexDesc.h" +#include "../../types/IndexParam.h" #include "milvus/Export.h" namespace milvus { @@ -236,32 +237,64 @@ class MILVUS_SDK_API CreateCollectionRequest { CreateCollectionRequest& AddProperty(const std::string& key, const std::string& property); + /** + * @brief Get index params. + * @return the index params. + */ + const std::vector& + IndexParams() const; + + /** + * @brief Set index params to be created. + * @param [in] index_params the index params. + */ + void + SetIndexParams(std::vector&& index_params); + + /** + * @brief Set index params to be created. + * @param [in] index_params the index params. + */ + CreateCollectionRequest& + WithIndexParams(std::vector&& index_params); + + /** + * @brief Add an index param to be created. + * @param [in] index_param the index param. + */ + CreateCollectionRequest& + AddIndexParam(IndexParam&& index_param); + /** * @brief Get indexes. * @return the indexes. + * @deprecated Use IndexParams() instead. */ - const std::vector& + [[deprecated("use IndexParams() instead")]] std::vector Indexes() const; /** * @brief Set indexes to be created. * @param [in] indexes the indexes. + * @deprecated Use WithIndexParams() instead. */ - void + [[deprecated("use WithIndexParams() instead")]] void SetIndexes(std::vector&& indexes); /** * @brief Set indexes to be created. * @param [in] indexes the indexes. + * @deprecated Use WithIndexParams() instead. */ - CreateCollectionRequest& + [[deprecated("use WithIndexParams() instead")]] CreateCollectionRequest& WithIndexes(std::vector&& indexes); /** * @brief Add an index to be created. * @param [in] index the index. + * @deprecated Use AddIndexParam() instead. */ - CreateCollectionRequest& + [[deprecated("use AddIndexParam() instead")]] CreateCollectionRequest& AddIndex(IndexDesc&& index); private: @@ -273,7 +306,7 @@ class MILVUS_SDK_API CreateCollectionRequest { int64_t num_shards_{1}; ConsistencyLevel level_{ConsistencyLevel::BOUNDED}; std::unordered_map properties_; - std::vector indexes_; + std::vector index_params_; }; } // namespace milvus diff --git a/src/include/milvus/request/index/CreateIndexRequest.h b/src/include/milvus/request/index/CreateIndexRequest.h index b98ba486..9a3e9886 100644 --- a/src/include/milvus/request/index/CreateIndexRequest.h +++ b/src/include/milvus/request/index/CreateIndexRequest.h @@ -20,6 +20,7 @@ #include #include "../../types/IndexDesc.h" +#include "../../types/IndexParam.h" #include "./IndexRequestBase.h" #include "milvus/Export.h" @@ -29,11 +30,11 @@ namespace milvus { * @brief Used by MilvusClientV2::CreateIndex() * @par Example * @code - * milvus::IndexDesc index("vector", "vector_idx", milvus::IndexType::HNSW, milvus::MetricType::L2); + * milvus::IndexParam index("vector", "vector_idx", milvus::IndexType::HNSW, milvus::MetricType::L2); * index.AddExtraParam("M", "16"); * auto status = client->CreateIndex(milvus::CreateIndexRequest() * .WithCollectionName("demo") - * .WithIndexes({std::move(index)}) + * .WithIndexParams({std::move(index)}) * .WithSync(true)); * @endcode */ @@ -44,32 +45,64 @@ class MILVUS_SDK_API CreateIndexRequest : public IndexRequestBase& + IndexParams() const; + + /** + * @brief Set index params to be created. + * @param [in] index_params the index params. + */ + void + SetIndexParams(std::vector&& index_params); + + /** + * @brief Set index params to be created. + * @param [in] index_params the index params. + */ + CreateIndexRequest& + WithIndexParams(std::vector&& index_params); + + /** + * @brief Add an index param to be created. + * @param [in] index_param the index param. + */ + CreateIndexRequest& + AddIndexParam(IndexParam&& index_param); + /** * @brief Get indexes. * @return the indexes. + * @deprecated Use IndexParams() instead. */ - const std::vector& + [[deprecated("use IndexParams() instead")]] std::vector Indexes() const; /** * @brief Set indexes to be created. * @param [in] indexes the indexes. + * @deprecated Use WithIndexParams() instead. */ - void + [[deprecated("use WithIndexParams() instead")]] void SetIndexes(std::vector&& indexes); /** * @brief Set indexes to be created. * @param [in] indexes the indexes. + * @deprecated Use WithIndexParams() instead. */ - CreateIndexRequest& + [[deprecated("use WithIndexParams() instead")]] CreateIndexRequest& WithIndexes(std::vector&& indexes); /** * @brief Add an index to be created. * @param [in] index the index. + * @deprecated Use AddIndexParam() instead. */ - CreateIndexRequest& + [[deprecated("use AddIndexParam() instead")]] CreateIndexRequest& AddIndex(IndexDesc&& index); /** @@ -129,7 +162,7 @@ class MILVUS_SDK_API CreateIndexRequest : public IndexRequestBase indexes_; + std::vector index_params_; bool sync_{true}; int64_t timeout_ms_{60000}; }; diff --git a/src/include/milvus/types/IndexDesc.h b/src/include/milvus/types/IndexDesc.h index 9fb3a139..7b2c11dc 100644 --- a/src/include/milvus/types/IndexDesc.h +++ b/src/include/milvus/types/IndexDesc.h @@ -51,7 +51,7 @@ class MILVUS_SDK_API IndexDesc { milvus::MetricType metric_type = milvus::MetricType::INVALID); /** - * @brief Filed name which the index belong to. + * @brief Field name which the index belong to. * @return the field name. */ const std::string& diff --git a/src/include/milvus/types/IndexParam.h b/src/include/milvus/types/IndexParam.h new file mode 100644 index 00000000..c9c332f1 --- /dev/null +++ b/src/include/milvus/types/IndexParam.h @@ -0,0 +1,137 @@ +// Licensed to the LF AI & Data foundation under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#pragma once + +#include +#include + +#include "../Status.h" +#include "IndexType.h" +#include "MetricType.h" +#include "milvus/Export.h" + +namespace milvus { + +/** + * @brief Parameters used to create an index on a collection field. + * Used by MilvusClientV2::CreateIndex(). + */ +class MILVUS_SDK_API IndexParam { + public: + /** + * @brief Construct a new IndexParam object. + */ + IndexParam(); + + /** + * @brief Construct a new IndexParam object. + * + * @param field_name field name which the index belong to + * @param index_name index name + * @param index_type index type see IndexType + * @param metric_type metric type see MetricType, no need to set this for scalar field index + */ + IndexParam(std::string field_name, std::string index_name, milvus::IndexType index_type, + milvus::MetricType metric_type = milvus::MetricType::INVALID); + + /** + * @brief Field name which the index belong to. + * @return the field name. + */ + const std::string& + FieldName() const; + + /** + * @brief Set field name which the index belong to. + * @param [in] field_name the field name. + */ + Status + SetFieldName(std::string field_name); + + /** + * @brief Index name. + * @return the index name. + */ + const std::string& + IndexName() const; + + /** + * @brief Set index name. + * @param [in] index_name the index name. + */ + Status + SetIndexName(std::string index_name); + + /** + * @brief Metric type. + * @return the metric type. + */ + milvus::MetricType + MetricType() const; + + /** + * @brief Set metric type. + * @param [in] metric_type the metric type. + */ + Status + SetMetricType(milvus::MetricType metric_type); + + /** + * @brief Index type. + * @return the index type. + */ + milvus::IndexType + IndexType() const; + + /** + * @brief Set index type. + * @param [in] index_type the index type. + */ + Status + SetIndexType(milvus::IndexType index_type); + + /** + * @brief Add extra param. + * @param [in] key the key. + * @param [in] value the value. + */ + Status + AddExtraParam(const std::string& key, const std::string& value); + + /** + * @brief Get extra params. + * @return the extra params. + */ + const std::unordered_map& + ExtraParams() const; + + /** + * @brief Construct extra params from a Json object. + * @param json Json string for parse + */ + Status + ExtraParamsFromJson(std::string json); + + private: + std::string field_name_; + std::string index_name_; + milvus::MetricType metric_type_{milvus::MetricType::INVALID}; + milvus::IndexType index_type_{milvus::IndexType::INVALID}; + std::unordered_map extra_params_; +}; + +} // namespace milvus diff --git a/test/it/v2/TestIndex.cpp b/test/it/v2/TestIndex.cpp index c9749ec3..4ad26716 100644 --- a/test/it/v2/TestIndex.cpp +++ b/test/it/v2/TestIndex.cpp @@ -23,8 +23,10 @@ using ::milvus::proto::milvus::ConnectRequest; using ::milvus::proto::milvus::ConnectResponse; +using ::milvus::proto::milvus::CreateIndexRequest; using ::milvus::proto::milvus::DescribeIndexRequest; using ::milvus::proto::milvus::DescribeIndexResponse; +using ::milvus::proto::milvus::LoadCollectionRequest; using ::testing::_; using ::testing::ElementsAre; using ::testing::Property; @@ -102,3 +104,120 @@ TEST_F(UnconnectMilvusMockedTest, CreateIndexRejectsEmptyIndexes) { EXPECT_FALSE(status.IsOk()); EXPECT_EQ(status.Code(), milvus::StatusCode::INVALID_ARGUMENT); } + +TEST_F(UnconnectMilvusMockedTest, CreateIndexWithIndexParams) { + auto client = CreateConnectedV2Client(service_, server_.ListenPort()); + + EXPECT_CALL(service_, CreateIndex(_, Property(&CreateIndexRequest::field_name, "vec_field"), _)) + .WillOnce([](::grpc::ServerContext*, const CreateIndexRequest* request, + ::milvus::proto::common::Status* status) { + EXPECT_EQ(request->collection_name(), "collection"); + EXPECT_EQ(request->index_name(), "vec_idx"); + std::unordered_map params{}; + for (const auto& pair : request->extra_params()) { + params.emplace(pair.key(), pair.value()); + } + EXPECT_EQ(params[milvus::INDEX_TYPE], std::to_string(milvus::IndexType::HNSW)); + EXPECT_EQ(params[milvus::METRIC_TYPE], std::to_string(milvus::MetricType::L2)); + EXPECT_EQ(params["params"], R"({"M":"16"})"); + status->set_code(milvus::proto::common::ErrorCode::Success); + return ::grpc::Status{}; + }); + + EXPECT_CALL(service_, CreateIndex(_, Property(&CreateIndexRequest::field_name, "text_field"), _)) + .WillOnce([](::grpc::ServerContext*, const CreateIndexRequest* request, + ::milvus::proto::common::Status* status) { + EXPECT_EQ(request->collection_name(), "collection"); + EXPECT_EQ(request->index_name(), "text_idx"); + std::unordered_map params{}; + for (const auto& pair : request->extra_params()) { + params.emplace(pair.key(), pair.value()); + } + EXPECT_EQ(params[milvus::INDEX_TYPE], std::to_string(milvus::IndexType::INVERTED)); + // scalar field index has no metric type + EXPECT_EQ(params.count(milvus::METRIC_TYPE), 0); + status->set_code(milvus::proto::common::ErrorCode::Success); + return ::grpc::Status{}; + }); + + milvus::IndexParam param_vec("vec_field", "vec_idx", milvus::IndexType::HNSW, milvus::MetricType::L2); + param_vec.AddExtraParam("M", "16"); + milvus::IndexParam param_scalar("text_field", "text_idx", milvus::IndexType::INVERTED); + auto status = client->CreateIndex(milvus::CreateIndexRequest() + .WithDatabaseName("db") + .WithCollectionName("collection") + .AddIndexParam(std::move(param_vec)) + .AddIndexParam(std::move(param_scalar)) + .WithSync(false)); + EXPECT_TRUE(status.IsOk()); +} + +TEST_F(UnconnectMilvusMockedTest, CreateIndexDeprecatedIndexDescForwarding) { + auto client = CreateConnectedV2Client(service_, server_.ListenPort()); + + EXPECT_CALL(service_, CreateIndex(_, Property(&CreateIndexRequest::field_name, "vec_field"), _)) + .WillOnce([](::grpc::ServerContext*, const CreateIndexRequest* request, + ::milvus::proto::common::Status* status) { + EXPECT_EQ(request->collection_name(), "collection"); + EXPECT_EQ(request->index_name(), "vec_idx"); + std::unordered_map params{}; + for (const auto& pair : request->extra_params()) { + params.emplace(pair.key(), pair.value()); + } + EXPECT_EQ(params[milvus::INDEX_TYPE], std::to_string(milvus::IndexType::HNSW)); + EXPECT_EQ(params[milvus::METRIC_TYPE], std::to_string(milvus::MetricType::L2)); + EXPECT_EQ(params["params"], R"({"M":"16"})"); + status->set_code(milvus::proto::common::ErrorCode::Success); + return ::grpc::Status{}; + }); + + milvus::IndexDesc index_desc("vec_field", "vec_idx", milvus::IndexType::HNSW, milvus::MetricType::L2); + index_desc.AddExtraParam("M", "16"); + auto status = client->CreateIndex(milvus::CreateIndexRequest() + .WithDatabaseName("db") + .WithCollectionName("collection") + .WithIndexes({std::move(index_desc)}) + .WithSync(false)); + EXPECT_TRUE(status.IsOk()); +} + +TEST_F(UnconnectMilvusMockedTest, CreateCollectionDeprecatedIndexDescForwarding) { + auto client = CreateConnectedV2Client(service_, server_.ListenPort()); + + EXPECT_CALL(service_, CreateCollection(_, _, _)) + .WillOnce([](::grpc::ServerContext*, const ::milvus::proto::milvus::CreateCollectionRequest*, + ::milvus::proto::common::Status*) { return ::grpc::Status{}; }); + + EXPECT_CALL(service_, CreateIndex(_, Property(&CreateIndexRequest::field_name, "vec_field"), _)) + .WillOnce([](::grpc::ServerContext*, const CreateIndexRequest* request, + ::milvus::proto::common::Status* status) { + EXPECT_EQ(request->collection_name(), "collection"); + EXPECT_EQ(request->index_name(), "vec_idx"); + std::unordered_map params{}; + for (const auto& pair : request->extra_params()) { + params.emplace(pair.key(), pair.value()); + } + EXPECT_EQ(params[milvus::INDEX_TYPE], std::to_string(milvus::IndexType::HNSW)); + EXPECT_EQ(params[milvus::METRIC_TYPE], std::to_string(milvus::MetricType::L2)); + EXPECT_EQ(params["params"], R"({"M":"16"})"); + status->set_code(milvus::proto::common::ErrorCode::Success); + return ::grpc::Status{}; + }); + + EXPECT_CALL(service_, LoadCollection(_, _, _)) + .WillOnce([](::grpc::ServerContext*, const LoadCollectionRequest*, + ::milvus::proto::common::Status*) { return ::grpc::Status{}; }); + + auto schema = std::make_shared("collection"); + schema->AddField(milvus::FieldSchema("id", milvus::DataType::INT64, "", true)); + schema->AddField(milvus::FieldSchema("vec_field", milvus::DataType::FLOAT_VECTOR).WithDimension(8)); + + milvus::IndexDesc index_desc("vec_field", "vec_idx", milvus::IndexType::HNSW, milvus::MetricType::L2); + index_desc.AddExtraParam("M", "16"); + auto status = client->CreateCollection(milvus::CreateCollectionRequest() + .WithDatabaseName("db") + .WithCollectionName("collection") + .WithCollectionSchema(schema) + .AddIndex(std::move(index_desc))); + EXPECT_TRUE(status.IsOk()); +} diff --git a/test/st/cases/TestArray.cpp b/test/st/cases/TestArray.cpp index 6c5c2d83..4037bd45 100644 --- a/test/st/cases/TestArray.cpp +++ b/test/st/cases/TestArray.cpp @@ -120,7 +120,7 @@ class MilvusServerTestArray : public MilvusServerTest { status = client_->CreateIndex( milvus::CreateIndexRequest() .WithCollectionName(collection_name) - .AddIndex(milvus::IndexDesc(field_vector, "", milvus::IndexType::FLAT, milvus::MetricType::L2))); + .AddIndexParam(milvus::IndexParam(field_vector, "", milvus::IndexType::FLAT, milvus::MetricType::L2))); milvus::test::ExpectStatusOK(status); status = client_->LoadCollection(milvus::LoadCollectionRequest().WithCollectionName(collection_name)); diff --git a/test/st/cases/TestCache.cpp b/test/st/cases/TestCache.cpp index 92e7dc19..9f9675d3 100644 --- a/test/st/cases/TestCache.cpp +++ b/test/st/cases/TestCache.cpp @@ -45,7 +45,7 @@ class MilvusServerTestCache : public milvus::test::MilvusServerTest { status = client_->CreateIndex( milvus::CreateIndexRequest() .WithCollectionName(collection_name) - .AddIndex(milvus::IndexDesc("vector", "", milvus::IndexType::FLAT, milvus::MetricType::L2))); + .AddIndexParam(milvus::IndexParam("vector", "", milvus::IndexType::FLAT, milvus::MetricType::L2))); milvus::test::ExpectStatusOK(status); status = client_->LoadCollection(milvus::LoadCollectionRequest().WithCollectionName(collection_name)); diff --git a/test/st/cases/TestCollection.cpp b/test/st/cases/TestCollection.cpp index 5c52e415..2bf2f273 100644 --- a/test/st/cases/TestCollection.cpp +++ b/test/st/cases/TestCollection.cpp @@ -52,9 +52,9 @@ TEST_P(MilvusServerTestCollection, CreateAndDeleteCollection) { milvus::test::ExpectStatusOK(status); // create index needed after 2.2.0 - milvus::IndexDesc index_desc("face", "", milvus::IndexType::FLAT, milvus::MetricType::L2); + milvus::IndexParam index_desc("face", "", milvus::IndexType::FLAT, milvus::MetricType::L2); status = client_->CreateIndex( - milvus::CreateIndexRequest().WithCollectionName(collection_name).AddIndex(std::move(index_desc))); + milvus::CreateIndexRequest().WithCollectionName(collection_name).AddIndexParam(std::move(index_desc))); milvus::test::ExpectStatusOK(status); // test for https://github.com/milvus-io/milvus-sdk-cpp/issues/188 @@ -244,9 +244,9 @@ TEST_F(MilvusServerTestCollectionOps, GetLoadState) { EXPECT_EQ(milvus::LoadState::LOAD_STATE_NOT_LOAD, state_resp.State()); // create index and load - milvus::IndexDesc index_desc("vec", "", milvus::IndexType::FLAT, milvus::MetricType::L2); + milvus::IndexParam index_desc("vec", "", milvus::IndexType::FLAT, milvus::MetricType::L2); status = client_->CreateIndex( - milvus::CreateIndexRequest().WithCollectionName(collection_name).AddIndex(std::move(index_desc))); + milvus::CreateIndexRequest().WithCollectionName(collection_name).AddIndexParam(std::move(index_desc))); milvus::test::ExpectStatusOK(status); status = client_->LoadCollection(milvus::LoadCollectionRequest().WithCollectionName(collection_name)); @@ -429,9 +429,9 @@ TEST_F(MilvusServerTestCollectionOps, AlterAndDropCollectionFieldProperties) { TEST_F(MilvusServerTestCollectionOps, TruncateCollection) { // create index first - milvus::IndexDesc index_desc("vec", "", milvus::IndexType::FLAT, milvus::MetricType::L2); + milvus::IndexParam index_desc("vec", "", milvus::IndexType::FLAT, milvus::MetricType::L2); auto status = client_->CreateIndex( - milvus::CreateIndexRequest().WithCollectionName(collection_name).AddIndex(std::move(index_desc))); + milvus::CreateIndexRequest().WithCollectionName(collection_name).AddIndexParam(std::move(index_desc))); milvus::test::ExpectStatusOK(status); // insert some data @@ -495,8 +495,8 @@ TEST_F(MilvusServerTestCollectionOps, DynamicField) { milvus::CreateCollectionRequest().WithCollectionName(dyn_coll).WithCollectionSchema(schema)); milvus::test::ExpectStatusOK(status); - milvus::IndexDesc idx("vec", "", milvus::IndexType::FLAT, milvus::MetricType::L2); - status = client_->CreateIndex(milvus::CreateIndexRequest().WithCollectionName(dyn_coll).AddIndex(std::move(idx))); + milvus::IndexParam idx("vec", "", milvus::IndexType::FLAT, milvus::MetricType::L2); + status = client_->CreateIndex(milvus::CreateIndexRequest().WithCollectionName(dyn_coll).AddIndexParam(std::move(idx))); milvus::test::ExpectStatusOK(status); status = client_->LoadCollection(milvus::LoadCollectionRequest().WithCollectionName(dyn_coll)); diff --git a/test/st/cases/TestDml.cpp b/test/st/cases/TestDml.cpp index 5207a40a..4cb0b03a 100644 --- a/test/st/cases/TestDml.cpp +++ b/test/st/cases/TestDml.cpp @@ -39,8 +39,8 @@ class MilvusServerTestDml : public MilvusServerTest { milvus::CreateCollectionRequest().WithCollectionName(name).WithCollectionSchema(schema)); milvus::test::ExpectStatusOK(status); - status = client_->CreateIndex(milvus::CreateIndexRequest().WithCollectionName(name).AddIndex( - milvus::IndexDesc("vector", "", milvus::IndexType::FLAT, milvus::MetricType::L2))); + status = client_->CreateIndex(milvus::CreateIndexRequest().WithCollectionName(name).AddIndexParam( + milvus::IndexParam("vector", "", milvus::IndexType::FLAT, milvus::MetricType::L2))); milvus::test::ExpectStatusOK(status); status = client_->LoadCollection(milvus::LoadCollectionRequest().WithCollectionName(name)); @@ -99,22 +99,22 @@ class MilvusServerTestDml : public MilvusServerTest { status = client_->CreateIndex( milvus::CreateIndexRequest() .WithCollectionName(collection_name) - .AddIndex(milvus::IndexDesc("v_float", "", milvus::IndexType::FLAT, milvus::MetricType::L2))); + .AddIndexParam(milvus::IndexParam("v_float", "", milvus::IndexType::FLAT, milvus::MetricType::L2))); milvus::test::ExpectStatusOK(status); status = client_->CreateIndex( milvus::CreateIndexRequest() .WithCollectionName(collection_name) - .AddIndex(milvus::IndexDesc("v_binary", "", milvus::IndexType::BIN_FLAT, milvus::MetricType::HAMMING))); + .AddIndexParam(milvus::IndexParam("v_binary", "", milvus::IndexType::BIN_FLAT, milvus::MetricType::HAMMING))); milvus::test::ExpectStatusOK(status); status = client_->CreateIndex( milvus::CreateIndexRequest() .WithCollectionName(collection_name) - .AddIndex(milvus::IndexDesc("v_fp16", "", milvus::IndexType::FLAT, milvus::MetricType::L2))); + .AddIndexParam(milvus::IndexParam("v_fp16", "", milvus::IndexType::FLAT, milvus::MetricType::L2))); milvus::test::ExpectStatusOK(status); - milvus::IndexDesc sparse_idx("v_sparse", "", milvus::IndexType::SPARSE_INVERTED_INDEX, milvus::MetricType::IP); + milvus::IndexParam sparse_idx("v_sparse", "", milvus::IndexType::SPARSE_INVERTED_INDEX, milvus::MetricType::IP); sparse_idx.AddExtraParam("drop_ratio_build", "0.2"); status = client_->CreateIndex( - milvus::CreateIndexRequest().WithCollectionName(collection_name).AddIndex(std::move(sparse_idx))); + milvus::CreateIndexRequest().WithCollectionName(collection_name).AddIndexParam(std::move(sparse_idx))); milvus::test::ExpectStatusOK(status); } diff --git a/test/st/cases/TestHybridSearch.cpp b/test/st/cases/TestHybridSearch.cpp index e0651af9..0ea83a62 100644 --- a/test/st/cases/TestHybridSearch.cpp +++ b/test/st/cases/TestHybridSearch.cpp @@ -48,13 +48,13 @@ class MilvusServerTestHybridSearch : public ::testing::Test { milvus::CreateCollectionRequest().WithCollectionName(collection_name).WithCollectionSchema(schema)); milvus::test::ExpectStatusOK(status); - milvus::IndexDesc idx_dense("dense", "", milvus::IndexType::FLAT, milvus::MetricType::COSINE); - milvus::IndexDesc idx_sparse("sparse", "", milvus::IndexType::SPARSE_INVERTED_INDEX, milvus::MetricType::IP); + milvus::IndexParam idx_dense("dense", "", milvus::IndexType::FLAT, milvus::MetricType::COSINE); + milvus::IndexParam idx_sparse("sparse", "", milvus::IndexType::SPARSE_INVERTED_INDEX, milvus::MetricType::IP); idx_sparse.AddExtraParam("drop_ratio_build", "0.2"); status = client_->CreateIndex(milvus::CreateIndexRequest() .WithCollectionName(collection_name) - .AddIndex(std::move(idx_dense)) - .AddIndex(std::move(idx_sparse))); + .AddIndexParam(std::move(idx_dense)) + .AddIndexParam(std::move(idx_sparse))); milvus::test::ExpectStatusOK(status); // insert data diff --git a/test/st/cases/TestIndex.cpp b/test/st/cases/TestIndex.cpp index befc7306..c0949f44 100644 --- a/test/st/cases/TestIndex.cpp +++ b/test/st/cases/TestIndex.cpp @@ -46,10 +46,10 @@ class MilvusServerTestIndex : public MilvusServerTest { TEST_F(MilvusServerTestIndex, CreateDescribeListDrop) { // create index - milvus::IndexDesc index_desc("vec", "my_index", milvus::IndexType::IVF_FLAT, milvus::MetricType::L2); + milvus::IndexParam index_desc("vec", "my_index", milvus::IndexType::IVF_FLAT, milvus::MetricType::L2); index_desc.AddExtraParam("nlist", "128"); auto status = client_->CreateIndex( - milvus::CreateIndexRequest().WithCollectionName(collection_name).AddIndex(std::move(index_desc))); + milvus::CreateIndexRequest().WithCollectionName(collection_name).AddIndexParam(std::move(index_desc))); std::cout << "index created" << std::endl; milvus::test::ExpectStatusOK(status); @@ -96,11 +96,11 @@ TEST_F(MilvusServerTestIndex, CreateDescribeListDrop) { } TEST_F(MilvusServerTestIndex, CreateHNSWIndex) { - milvus::IndexDesc index_desc("vec", "", milvus::IndexType::HNSW, milvus::MetricType::L2); + milvus::IndexParam index_desc("vec", "", milvus::IndexType::HNSW, milvus::MetricType::L2); index_desc.AddExtraParam("M", "16"); index_desc.AddExtraParam("efConstruction", "200"); auto status = client_->CreateIndex( - milvus::CreateIndexRequest().WithCollectionName(collection_name).AddIndex(std::move(index_desc))); + milvus::CreateIndexRequest().WithCollectionName(collection_name).AddIndexParam(std::move(index_desc))); milvus::test::ExpectStatusOK(status); status = @@ -125,11 +125,11 @@ TEST_F(MilvusServerTestIndex, CreateHNSWIndex) { TEST_F(MilvusServerTestIndex, AlterAndDropIndexProperties) { // create index first - milvus::IndexDesc index_desc("vec", "test_index", milvus::IndexType::HNSW, milvus::MetricType::L2); + milvus::IndexParam index_desc("vec", "test_index", milvus::IndexType::HNSW, milvus::MetricType::L2); index_desc.AddExtraParam("M", "16"); index_desc.AddExtraParam("efConstruction", "200"); auto status = client_->CreateIndex( - milvus::CreateIndexRequest().WithCollectionName(collection_name).AddIndex(std::move(index_desc))); + milvus::CreateIndexRequest().WithCollectionName(collection_name).AddIndexParam(std::move(index_desc))); milvus::test::ExpectStatusOK(status); // alter index properties diff --git a/test/st/cases/TestIterator.cpp b/test/st/cases/TestIterator.cpp index 68d2a530..319eec6b 100644 --- a/test/st/cases/TestIterator.cpp +++ b/test/st/cases/TestIterator.cpp @@ -44,9 +44,9 @@ class MilvusServerTestIterator : public ::testing::Test { milvus::CreateCollectionRequest().WithCollectionName(collection_name).WithCollectionSchema(schema)); milvus::test::ExpectStatusOK(status); - milvus::IndexDesc index_desc("vec", "", milvus::IndexType::FLAT, milvus::MetricType::L2); + milvus::IndexParam index_desc("vec", "", milvus::IndexType::FLAT, milvus::MetricType::L2); status = client_->CreateIndex( - milvus::CreateIndexRequest().WithCollectionName(collection_name).AddIndex(std::move(index_desc))); + milvus::CreateIndexRequest().WithCollectionName(collection_name).AddIndexParam(std::move(index_desc))); milvus::test::ExpectStatusOK(status); // insert data diff --git a/test/st/cases/TestNullableDefault.cpp b/test/st/cases/TestNullableDefault.cpp index 873068cb..0f352390 100644 --- a/test/st/cases/TestNullableDefault.cpp +++ b/test/st/cases/TestNullableDefault.cpp @@ -48,9 +48,9 @@ class MilvusServerTestNullable : public MilvusServerTest { milvus::CreateCollectionRequest().WithCollectionName(collection_name).WithCollectionSchema(schema)); milvus::test::ExpectStatusOK(status); - milvus::IndexDesc idx("vec", "", milvus::IndexType::FLAT, milvus::MetricType::L2); + milvus::IndexParam idx("vec", "", milvus::IndexType::FLAT, milvus::MetricType::L2); status = client_->CreateIndex( - milvus::CreateIndexRequest().WithCollectionName(collection_name).AddIndex(std::move(idx))); + milvus::CreateIndexRequest().WithCollectionName(collection_name).AddIndexParam(std::move(idx))); milvus::test::ExpectStatusOK(status); status = client_->LoadCollection(milvus::LoadCollectionRequest().WithCollectionName(collection_name)); @@ -271,9 +271,9 @@ class MilvusServerTestNullableVector : public MilvusServerTest { milvus::CreateCollectionRequest().WithCollectionName(collection_name).WithCollectionSchema(schema)); milvus::test::ExpectStatusOK(status); - milvus::IndexDesc index("vec", "", milvus::IndexType::FLAT, milvus::MetricType::L2); + milvus::IndexParam index("vec", "", milvus::IndexType::FLAT, milvus::MetricType::L2); status = client_->CreateIndex( - milvus::CreateIndexRequest().WithCollectionName(collection_name).AddIndex(std::move(index))); + milvus::CreateIndexRequest().WithCollectionName(collection_name).AddIndexParam(std::move(index))); milvus::test::ExpectStatusOK(status); status = client_->LoadCollection(milvus::LoadCollectionRequest().WithCollectionName(collection_name)); @@ -406,9 +406,9 @@ class MilvusServerTestDefaultValue : public MilvusServerTest { milvus::CreateCollectionRequest().WithCollectionName(collection_name).WithCollectionSchema(schema)); milvus::test::ExpectStatusOK(status); - milvus::IndexDesc idx("vec", "", milvus::IndexType::FLAT, milvus::MetricType::L2); + milvus::IndexParam idx("vec", "", milvus::IndexType::FLAT, milvus::MetricType::L2); status = client_->CreateIndex( - milvus::CreateIndexRequest().WithCollectionName(collection_name).AddIndex(std::move(idx))); + milvus::CreateIndexRequest().WithCollectionName(collection_name).AddIndexParam(std::move(idx))); milvus::test::ExpectStatusOK(status); status = client_->LoadCollection(milvus::LoadCollectionRequest().WithCollectionName(collection_name)); diff --git a/test/st/cases/TestPartition.cpp b/test/st/cases/TestPartition.cpp index 20f4876a..3397a6bf 100644 --- a/test/st/cases/TestPartition.cpp +++ b/test/st/cases/TestPartition.cpp @@ -35,9 +35,9 @@ class MilvusServerTestPartition : public MilvusServerTest { milvus::CreateCollectionRequest().WithCollectionName(collection_name).WithCollectionSchema(schema)); milvus::test::ExpectStatusOK(status); - milvus::IndexDesc index_desc("vec", "", milvus::IndexType::FLAT, milvus::MetricType::L2); + milvus::IndexParam index_desc("vec", "", milvus::IndexType::FLAT, milvus::MetricType::L2); status = client_->CreateIndex( - milvus::CreateIndexRequest().WithCollectionName(collection_name).AddIndex(std::move(index_desc))); + milvus::CreateIndexRequest().WithCollectionName(collection_name).AddIndexParam(std::move(index_desc))); milvus::test::ExpectStatusOK(status); } @@ -176,8 +176,8 @@ TEST_F(MilvusServerTestPartition, PartitionKey) { EXPECT_GE(lp_resp.PartitionsNames().size(), 4); // create index and load - milvus::IndexDesc idx("vec", "", milvus::IndexType::FLAT, milvus::MetricType::L2); - status = client_->CreateIndex(milvus::CreateIndexRequest().WithCollectionName(pk_coll).AddIndex(std::move(idx))); + milvus::IndexParam idx("vec", "", milvus::IndexType::FLAT, milvus::MetricType::L2); + status = client_->CreateIndex(milvus::CreateIndexRequest().WithCollectionName(pk_coll).AddIndexParam(std::move(idx))); milvus::test::ExpectStatusOK(status); status = client_->LoadCollection(milvus::LoadCollectionRequest().WithCollectionName(pk_coll)); diff --git a/test/st/cases/TestQuery.cpp b/test/st/cases/TestQuery.cpp index 9be68b44..32ed21e7 100644 --- a/test/st/cases/TestQuery.cpp +++ b/test/st/cases/TestQuery.cpp @@ -44,9 +44,9 @@ class MilvusServerTestQuery : public ::testing::Test { milvus::CreateCollectionRequest().WithCollectionName(collection_name).WithCollectionSchema(schema)); milvus::test::ExpectStatusOK(status); - milvus::IndexDesc index_desc("vec", "", milvus::IndexType::FLAT, milvus::MetricType::L2); + milvus::IndexParam index_desc("vec", "", milvus::IndexType::FLAT, milvus::MetricType::L2); status = client_->CreateIndex( - milvus::CreateIndexRequest().WithCollectionName(collection_name).AddIndex(std::move(index_desc))); + milvus::CreateIndexRequest().WithCollectionName(collection_name).AddIndexParam(std::move(index_desc))); milvus::test::ExpectStatusOK(status); // insert test data using row-based insert @@ -291,9 +291,9 @@ class MilvusServerTestQueryStringId : public ::testing::Test { milvus::CreateCollectionRequest().WithCollectionName(collection_name).WithCollectionSchema(schema)); milvus::test::ExpectStatusOK(status); - milvus::IndexDesc index_desc("vec", "", milvus::IndexType::FLAT, milvus::MetricType::L2); + milvus::IndexParam index_desc("vec", "", milvus::IndexType::FLAT, milvus::MetricType::L2); status = client_->CreateIndex( - milvus::CreateIndexRequest().WithCollectionName(collection_name).AddIndex(std::move(index_desc))); + milvus::CreateIndexRequest().WithCollectionName(collection_name).AddIndexParam(std::move(index_desc))); milvus::test::ExpectStatusOK(status); // insert test data with string IDs diff --git a/test/st/cases/TestSearch.cpp b/test/st/cases/TestSearch.cpp index e8cb9605..ea9785d8 100644 --- a/test/st/cases/TestSearch.cpp +++ b/test/st/cases/TestSearch.cpp @@ -47,9 +47,9 @@ class MilvusServerTestSearch : public MilvusServerTest { milvus::test::ExpectStatusOK(status); if (create_flat_index) { - milvus::IndexDesc index_desc("face", "", milvus::IndexType::FLAT, milvus::MetricType::L2); + milvus::IndexParam index_desc("face", "", milvus::IndexType::FLAT, milvus::MetricType::L2); status = client_->CreateIndex( - milvus::CreateIndexRequest().WithCollectionName(collection_name).AddIndex(std::move(index_desc))); + milvus::CreateIndexRequest().WithCollectionName(collection_name).AddIndexParam(std::move(index_desc))); EXPECT_EQ(status.Message(), "OK"); milvus::test::ExpectStatusOK(status); } @@ -200,9 +200,9 @@ TEST_F(MilvusServerTestSearch, SearchByStringIDs) { milvus::CreateCollectionRequest().WithCollectionName(collection_name).WithCollectionSchema(schema)); milvus::test::ExpectStatusOK(status); - milvus::IndexDesc index_desc("face", "", milvus::IndexType::FLAT, milvus::MetricType::L2); + milvus::IndexParam index_desc("face", "", milvus::IndexType::FLAT, milvus::MetricType::L2); status = client_->CreateIndex( - milvus::CreateIndexRequest().WithCollectionName(collection_name).AddIndex(std::move(index_desc))); + milvus::CreateIndexRequest().WithCollectionName(collection_name).AddIndexParam(std::move(index_desc))); milvus::test::ExpectStatusOK(status); std::vector inserted_ids{"pk_0", "pk_1", "pk_2"}; @@ -381,23 +381,23 @@ TEST_F(MilvusServerTestSearch, SearchWithMultipleVectorTypes) { milvus::test::ExpectStatusOK(status); // create indexes for each vector field - milvus::IndexDesc float_idx("float_vec", "", milvus::IndexType::FLAT, milvus::MetricType::L2); - milvus::IndexDesc binary_idx("binary_vec", "", milvus::IndexType::BIN_FLAT, milvus::MetricType::HAMMING); - milvus::IndexDesc fp16_idx("fp16_vec", "", milvus::IndexType::FLAT, milvus::MetricType::L2); - milvus::IndexDesc sparse_idx("sparse_vec", "", milvus::IndexType::SPARSE_INVERTED_INDEX, milvus::MetricType::IP); + milvus::IndexParam float_idx("float_vec", "", milvus::IndexType::FLAT, milvus::MetricType::L2); + milvus::IndexParam binary_idx("binary_vec", "", milvus::IndexType::BIN_FLAT, milvus::MetricType::HAMMING); + milvus::IndexParam fp16_idx("fp16_vec", "", milvus::IndexType::FLAT, milvus::MetricType::L2); + milvus::IndexParam sparse_idx("sparse_vec", "", milvus::IndexType::SPARSE_INVERTED_INDEX, milvus::MetricType::IP); sparse_idx.AddExtraParam("drop_ratio_build", "0.2"); status = - client_->CreateIndex(milvus::CreateIndexRequest().WithCollectionName(coll_name).AddIndex(std::move(float_idx))); + client_->CreateIndex(milvus::CreateIndexRequest().WithCollectionName(coll_name).AddIndexParam(std::move(float_idx))); milvus::test::ExpectStatusOK(status); status = client_->CreateIndex( - milvus::CreateIndexRequest().WithCollectionName(coll_name).AddIndex(std::move(binary_idx))); + milvus::CreateIndexRequest().WithCollectionName(coll_name).AddIndexParam(std::move(binary_idx))); milvus::test::ExpectStatusOK(status); status = - client_->CreateIndex(milvus::CreateIndexRequest().WithCollectionName(coll_name).AddIndex(std::move(fp16_idx))); + client_->CreateIndex(milvus::CreateIndexRequest().WithCollectionName(coll_name).AddIndexParam(std::move(fp16_idx))); milvus::test::ExpectStatusOK(status); status = client_->CreateIndex( - milvus::CreateIndexRequest().WithCollectionName(coll_name).AddIndex(std::move(sparse_idx))); + milvus::CreateIndexRequest().WithCollectionName(coll_name).AddIndexParam(std::move(sparse_idx))); milvus::test::ExpectStatusOK(status); // prepare data @@ -527,10 +527,10 @@ TEST_F(MilvusServerTestSearch, SearchWithIVFIndex) { createCollectionAndPartitions(false); auto dml_results = insertRecords(fields); - milvus::IndexDesc index_desc("face", "", milvus::IndexType::IVF_FLAT, milvus::MetricType::L2); + milvus::IndexParam index_desc("face", "", milvus::IndexType::IVF_FLAT, milvus::MetricType::L2); index_desc.AddExtraParam("nlist", "1024"); auto status = client_->CreateIndex( - milvus::CreateIndexRequest().WithCollectionName(collection_name).AddIndex(std::move(index_desc))); + milvus::CreateIndexRequest().WithCollectionName(collection_name).AddIndexParam(std::move(index_desc))); EXPECT_EQ(status.Message(), "OK"); milvus::test::ExpectStatusOK(status); @@ -575,11 +575,11 @@ TEST_F(MilvusServerTestSearch, HybridSearch) { milvus::test::ExpectStatusOK(status); // create indexes - milvus::IndexDesc idx1("vec1", "", milvus::IndexType::FLAT, milvus::MetricType::L2); - milvus::IndexDesc idx2("vec2", "", milvus::IndexType::FLAT, milvus::MetricType::L2); - status = client_->CreateIndex(milvus::CreateIndexRequest().WithCollectionName(coll_name).AddIndex(std::move(idx1))); + milvus::IndexParam idx1("vec1", "", milvus::IndexType::FLAT, milvus::MetricType::L2); + milvus::IndexParam idx2("vec2", "", milvus::IndexType::FLAT, milvus::MetricType::L2); + status = client_->CreateIndex(milvus::CreateIndexRequest().WithCollectionName(coll_name).AddIndexParam(std::move(idx1))); milvus::test::ExpectStatusOK(status); - status = client_->CreateIndex(milvus::CreateIndexRequest().WithCollectionName(coll_name).AddIndex(std::move(idx2))); + status = client_->CreateIndex(milvus::CreateIndexRequest().WithCollectionName(coll_name).AddIndexParam(std::move(idx2))); milvus::test::ExpectStatusOK(status); // insert data @@ -690,8 +690,8 @@ TEST_F(MilvusServerTestSearch, SearchWithGroupBy) { milvus::CreateCollectionRequest().WithCollectionName(coll_name).WithCollectionSchema(schema)); milvus::test::ExpectStatusOK(status); - milvus::IndexDesc idx("vec", "", milvus::IndexType::FLAT, milvus::MetricType::L2); - status = client_->CreateIndex(milvus::CreateIndexRequest().WithCollectionName(coll_name).AddIndex(std::move(idx))); + milvus::IndexParam idx("vec", "", milvus::IndexType::FLAT, milvus::MetricType::L2); + status = client_->CreateIndex(milvus::CreateIndexRequest().WithCollectionName(coll_name).AddIndexParam(std::move(idx))); milvus::test::ExpectStatusOK(status); // insert data: 3 categories, 10 rows each diff --git a/test/st/cases/TestStruct.cpp b/test/st/cases/TestStruct.cpp index 6a13eb42..f28d2684 100644 --- a/test/st/cases/TestStruct.cpp +++ b/test/st/cases/TestStruct.cpp @@ -47,12 +47,12 @@ class MilvusServerTestStruct : public MilvusServerTest { milvus::test::ExpectStatusOK(status); // create indexes - milvus::IndexDesc idx_vec("vec", "", milvus::IndexType::FLAT, milvus::MetricType::COSINE); - milvus::IndexDesc idx_st_vec("st[st_vec]", "", milvus::IndexType::HNSW, milvus::MetricType::MAX_SIM_COSINE); + milvus::IndexParam idx_vec("vec", "", milvus::IndexType::FLAT, milvus::MetricType::COSINE); + milvus::IndexParam idx_st_vec("st[st_vec]", "", milvus::IndexType::HNSW, milvus::MetricType::MAX_SIM_COSINE); status = client_->CreateIndex(milvus::CreateIndexRequest() .WithCollectionName(collection_name) - .AddIndex(std::move(idx_vec)) - .AddIndex(std::move(idx_st_vec))); + .AddIndexParam(std::move(idx_vec)) + .AddIndexParam(std::move(idx_st_vec))); milvus::test::ExpectStatusOK(status); status = client_->LoadCollection(milvus::LoadCollectionRequest().WithCollectionName(collection_name)); diff --git a/test/st/cases/TestTextMatch.cpp b/test/st/cases/TestTextMatch.cpp index f9ca1467..19f2577c 100644 --- a/test/st/cases/TestTextMatch.cpp +++ b/test/st/cases/TestTextMatch.cpp @@ -63,9 +63,9 @@ class MilvusServerTestTextMatch : public ::testing::Test { milvus::CreateCollectionRequest().WithCollectionName(collection_name).WithCollectionSchema(schema)); milvus::test::ExpectStatusOK(status); - milvus::IndexDesc idx("vec", "", milvus::IndexType::FLAT, milvus::MetricType::L2); + milvus::IndexParam idx("vec", "", milvus::IndexType::FLAT, milvus::MetricType::L2); status = client_->CreateIndex( - milvus::CreateIndexRequest().WithCollectionName(collection_name).AddIndex(std::move(idx))); + milvus::CreateIndexRequest().WithCollectionName(collection_name).AddIndexParam(std::move(idx))); milvus::test::ExpectStatusOK(status); // insert text data @@ -226,9 +226,9 @@ class MilvusServerTestBM25 : public ::testing::Test { milvus::CreateCollectionRequest().WithCollectionName(collection_name).WithCollectionSchema(schema)); milvus::test::ExpectStatusOK(status); - milvus::IndexDesc idx("sparse_vec", "", milvus::IndexType::SPARSE_INVERTED_INDEX, milvus::MetricType::BM25); + milvus::IndexParam idx("sparse_vec", "", milvus::IndexType::SPARSE_INVERTED_INDEX, milvus::MetricType::BM25); status = client_->CreateIndex( - milvus::CreateIndexRequest().WithCollectionName(collection_name).AddIndex(std::move(idx))); + milvus::CreateIndexRequest().WithCollectionName(collection_name).AddIndexParam(std::move(idx))); milvus::test::ExpectStatusOK(status); milvus::EntityRows rows_data; @@ -367,9 +367,9 @@ class MilvusServerTestMultiAnalyzer : public ::testing::Test { milvus::CreateCollectionRequest().WithCollectionName(collection_name).WithCollectionSchema(schema)); milvus::test::ExpectStatusOK(status); - milvus::IndexDesc idx("sparse_vec", "", milvus::IndexType::SPARSE_INVERTED_INDEX, milvus::MetricType::BM25); + milvus::IndexParam idx("sparse_vec", "", milvus::IndexType::SPARSE_INVERTED_INDEX, milvus::MetricType::BM25); status = client_->CreateIndex( - milvus::CreateIndexRequest().WithCollectionName(collection_name).AddIndex(std::move(idx))); + milvus::CreateIndexRequest().WithCollectionName(collection_name).AddIndexParam(std::move(idx))); milvus::test::ExpectStatusOK(status); milvus::EntityRows rows_data; diff --git a/test/ut/request/TestCollectionRequests.cpp b/test/ut/request/TestCollectionRequests.cpp index 3b941fdd..abc71f3e 100644 --- a/test/ut/request/TestCollectionRequests.cpp +++ b/test/ut/request/TestCollectionRequests.cpp @@ -81,23 +81,45 @@ TEST_F(CreateCollectionRequestTest, GettersAndSetters) { req.AddProperty("key2", "val2"); EXPECT_EQ(req.Properties().at("key2"), "val2"); - // Indexes + // IndexParams + milvus::IndexParam idx; + std::vector index_params; + index_params.push_back(idx); + req.WithIndexParams(std::move(index_params)); + EXPECT_EQ(req.IndexParams().size(), 1); + + // AddIndexParam + milvus::IndexParam idx2; + req.AddIndexParam(std::move(idx2)); + EXPECT_EQ(req.IndexParams().size(), 2); + + // SetIndexParams + std::vector index_params2; + index_params2.push_back(milvus::IndexParam()); + req.SetIndexParams(std::move(index_params2)); + EXPECT_EQ(req.IndexParams().size(), 1); +} + +TEST_F(CreateCollectionRequestTest, DeprecatedIndexDescMethods) { + milvus::CreateCollectionRequest req; + milvus::IndexDesc idx; - std::vector indexes; - indexes.push_back(idx); - req.WithIndexes(std::move(indexes)); + req.AddIndex(std::move(idx)); EXPECT_EQ(req.Indexes().size(), 1); + EXPECT_EQ(req.IndexParams().size(), 1); - // AddIndex - milvus::IndexDesc idx2; - req.AddIndex(std::move(idx2)); - EXPECT_EQ(req.Indexes().size(), 2); - - // SetIndexes std::vector indexes2; indexes2.push_back(milvus::IndexDesc()); req.SetIndexes(std::move(indexes2)); EXPECT_EQ(req.Indexes().size(), 1); + EXPECT_EQ(req.IndexParams().size(), 1); + + std::vector indexes3; + indexes3.push_back(milvus::IndexDesc()); + auto& ref = req.WithIndexes(std::move(indexes3)); + EXPECT_EQ(req.Indexes().size(), 1); + EXPECT_EQ(req.IndexParams().size(), 1); + EXPECT_EQ(&ref, &req); } TEST_F(CreateCollectionRequestTest, FluentChaining) { diff --git a/test/ut/request/TestIndexRequests.cpp b/test/ut/request/TestIndexRequests.cpp index 316c6ac7..4e373325 100644 --- a/test/ut/request/TestIndexRequests.cpp +++ b/test/ut/request/TestIndexRequests.cpp @@ -26,9 +26,9 @@ TEST_F(CreateIndexRequestTest, GettersAndSetters) { req.WithCollectionName("idx_coll"); EXPECT_EQ(req.CollectionName(), "idx_coll"); - milvus::IndexDesc idx; - req.AddIndex(std::move(idx)); - EXPECT_EQ(req.Indexes().size(), 1); + milvus::IndexParam index_param; + req.AddIndexParam(std::move(index_param)); + EXPECT_EQ(req.IndexParams().size(), 1); req.WithSync(false); EXPECT_FALSE(req.Sync()); @@ -36,10 +36,16 @@ TEST_F(CreateIndexRequestTest, GettersAndSetters) { req.WithTimeoutMs(90000); EXPECT_EQ(req.TimeoutMs(), 90000); - std::vector indexes2; - indexes2.push_back(milvus::IndexDesc()); - req.SetIndexes(std::move(indexes2)); - EXPECT_EQ(req.Indexes().size(), 1); + std::vector index_params2; + index_params2.push_back(milvus::IndexParam()); + req.SetIndexParams(std::move(index_params2)); + EXPECT_EQ(req.IndexParams().size(), 1); + + std::vector index_params3; + index_params3.push_back(milvus::IndexParam()); + auto& ref = req.WithIndexParams(std::move(index_params3)); + EXPECT_EQ(req.IndexParams().size(), 1); + EXPECT_EQ(&ref, &req); req.SetSync(true); EXPECT_TRUE(req.Sync()); @@ -48,6 +54,29 @@ TEST_F(CreateIndexRequestTest, GettersAndSetters) { EXPECT_EQ(req.TimeoutMs(), 30000); } +TEST_F(CreateIndexRequestTest, DeprecatedIndexDescMethods) { + milvus::CreateIndexRequest req; + + milvus::IndexDesc idx; + req.AddIndex(std::move(idx)); + EXPECT_EQ(req.Indexes().size(), 1); + // the deprecated input is forwarded to the IndexParam list + EXPECT_EQ(req.IndexParams().size(), 1); + + std::vector indexes2; + indexes2.push_back(milvus::IndexDesc()); + req.SetIndexes(std::move(indexes2)); + EXPECT_EQ(req.Indexes().size(), 1); + EXPECT_EQ(req.IndexParams().size(), 1); + + std::vector indexes3; + indexes3.push_back(milvus::IndexDesc()); + auto& ref = req.WithIndexes(std::move(indexes3)); + EXPECT_EQ(req.Indexes().size(), 1); + EXPECT_EQ(req.IndexParams().size(), 1); + EXPECT_EQ(&ref, &req); +} + TEST_F(CreateIndexRequestTest, IndexRequestBaseMethods) { milvus::CreateIndexRequest req; diff --git a/test/ut/types/TestIndexParam.cpp b/test/ut/types/TestIndexParam.cpp new file mode 100644 index 00000000..347ac69e --- /dev/null +++ b/test/ut/types/TestIndexParam.cpp @@ -0,0 +1,74 @@ +// Licensed to the LF AI & Data foundation under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include + +#include "milvus/types/IndexParam.h" + +class IndexParamTest : public ::testing::Test {}; + +TEST_F(IndexParamTest, GeneralTesting) { + milvus::IndexParam index_param("field_name", "index_name", milvus::IndexType::HNSW, milvus::MetricType::L2); + + EXPECT_EQ(index_param.FieldName(), "field_name"); + EXPECT_EQ(index_param.IndexName(), "index_name"); + EXPECT_EQ(index_param.IndexType(), milvus::IndexType::HNSW); + EXPECT_EQ(index_param.MetricType(), milvus::MetricType::L2); +} + +TEST_F(IndexParamTest, SettersAndGetters) { + milvus::IndexParam index_param; + + index_param.SetFieldName("field_name"); + EXPECT_EQ(index_param.FieldName(), "field_name"); + + index_param.SetIndexName("index_name"); + EXPECT_EQ(index_param.IndexName(), "index_name"); + + index_param.SetIndexType(milvus::IndexType::IVF_FLAT); + EXPECT_EQ(index_param.IndexType(), milvus::IndexType::IVF_FLAT); + + index_param.SetMetricType(milvus::MetricType::COSINE); + EXPECT_EQ(index_param.MetricType(), milvus::MetricType::COSINE); +} + +TEST_F(IndexParamTest, AddExtraParam) { + milvus::IndexParam index_param; + auto status = index_param.AddExtraParam("nlist", "1024"); + EXPECT_TRUE(status.IsOk()); + + status = index_param.AddExtraParam("nprobe", "16"); + EXPECT_TRUE(status.IsOk()); + + auto& params = index_param.ExtraParams(); + EXPECT_EQ(params.size(), 2); + EXPECT_EQ(params.at("nlist"), "1024"); + EXPECT_EQ(params.at("nprobe"), "16"); +} + +TEST_F(IndexParamTest, ExtraParamsFromJson) { + milvus::IndexParam index_param; + auto status = index_param.ExtraParamsFromJson(R"({"nlist":"1024","nprobe":"16"})"); + EXPECT_TRUE(status.IsOk()); + + auto& params = index_param.ExtraParams(); + EXPECT_EQ(params.at("nlist"), "1024"); + EXPECT_EQ(params.at("nprobe"), "16"); + + // invalid json + status = index_param.ExtraParamsFromJson("not valid json"); + EXPECT_FALSE(status.IsOk()); +} diff --git a/tutorial/1_quickstart/src/main.cpp b/tutorial/1_quickstart/src/main.cpp index f2a4f3df..78cd062e 100644 --- a/tutorial/1_quickstart/src/main.cpp +++ b/tutorial/1_quickstart/src/main.cpp @@ -53,7 +53,7 @@ main() { milvus::CreateCollectionRequest() .WithCollectionName(collection) .WithCollectionSchema(schema) - .AddIndex(milvus::IndexDesc("embedding", "", milvus::IndexType::AUTOINDEX, milvus::MetricType::COSINE))); + .AddIndexParam(milvus::IndexParam("embedding", "", milvus::IndexType::AUTOINDEX, milvus::MetricType::COSINE))); if (!Ok(status, "create collection")) { return 1; } diff --git a/tutorial/2_collection/src/main.cpp b/tutorial/2_collection/src/main.cpp index e7ba2a1d..894b5b6a 100644 --- a/tutorial/2_collection/src/main.cpp +++ b/tutorial/2_collection/src/main.cpp @@ -70,7 +70,7 @@ main() { .WithCollectionName(collection) .WithCollectionSchema(schema) .WithConsistencyLevel(milvus::ConsistencyLevel::BOUNDED) - .AddIndex(milvus::IndexDesc("embedding", "", milvus::IndexType::AUTOINDEX, milvus::MetricType::COSINE))); + .AddIndexParam(milvus::IndexParam("embedding", "", milvus::IndexType::AUTOINDEX, milvus::MetricType::COSINE))); if (!Ok(status, "create collection")) { return 1; } diff --git a/tutorial/4_index/src/main.cpp b/tutorial/4_index/src/main.cpp index ece5c130..20013443 100644 --- a/tutorial/4_index/src/main.cpp +++ b/tutorial/4_index/src/main.cpp @@ -53,16 +53,16 @@ main() { } std::cout << "CreateCollection succeeded." << std::endl; - milvus::IndexDesc vector_index("embedding", "embedding_hnsw_idx", milvus::IndexType::HNSW, + milvus::IndexParam vector_index("embedding", "embedding_hnsw_idx", milvus::IndexType::HNSW, milvus::MetricType::COSINE); vector_index.AddExtraParam("M", "16"); vector_index.AddExtraParam("efConstruction", "100"); auto request = milvus::CreateIndexRequest() .WithCollectionName(collection) - .AddIndex(std::move(vector_index)) - .AddIndex(milvus::IndexDesc("category", "category_inverted_idx", milvus::IndexType::INVERTED)) - .AddIndex(milvus::IndexDesc("price", "price_sort_idx", milvus::IndexType::STL_SORT)); - // CreateIndex builds all supplied index definitions. Each IndexDesc identifies a field, + .AddIndexParam(std::move(vector_index)) + .AddIndexParam(milvus::IndexParam("category", "category_inverted_idx", milvus::IndexType::INVERTED)) + .AddIndexParam(milvus::IndexParam("price", "price_sort_idx", milvus::IndexType::STL_SORT)); + // CreateIndex builds all supplied index definitions. Each IndexParam identifies a field, // index name and type, plus any metric or build parameters. std::cout << "Calling CreateIndex..." << std::endl; status = client->CreateIndex(request); diff --git a/tutorial/5_dml/src/main.cpp b/tutorial/5_dml/src/main.cpp index fc50418a..83259815 100644 --- a/tutorial/5_dml/src/main.cpp +++ b/tutorial/5_dml/src/main.cpp @@ -50,7 +50,7 @@ main() { milvus::CreateCollectionRequest() .WithCollectionName(collection) .WithCollectionSchema(schema) - .AddIndex(milvus::IndexDesc("embedding", "", milvus::IndexType::AUTOINDEX, milvus::MetricType::COSINE))); + .AddIndexParam(milvus::IndexParam("embedding", "", milvus::IndexType::AUTOINDEX, milvus::MetricType::COSINE))); if (!Ok(status, "create collection")) { return 1; } diff --git a/tutorial/6_dql/src/main.cpp b/tutorial/6_dql/src/main.cpp index 56ad7a2e..973936a5 100644 --- a/tutorial/6_dql/src/main.cpp +++ b/tutorial/6_dql/src/main.cpp @@ -95,9 +95,10 @@ main() { milvus::CreateCollectionRequest() .WithCollectionName(collection) .WithCollectionSchema(schema) - .AddIndex(milvus::IndexDesc("dense", "", milvus::IndexType::AUTOINDEX, milvus::MetricType::COSINE)) - .AddIndex( - milvus::IndexDesc("sparse", "", milvus::IndexType::SPARSE_INVERTED_INDEX, milvus::MetricType::IP))); + .AddIndexParam( + milvus::IndexParam("dense", "", milvus::IndexType::AUTOINDEX, milvus::MetricType::COSINE)) + .AddIndexParam( + milvus::IndexParam("sparse", "", milvus::IndexType::SPARSE_INVERTED_INDEX, milvus::MetricType::IP))); if (!Ok(status, "create collection")) { return 1; }