This standalone project creates one vector index and two scalar indexes with MilvusClientV2:
HNSW with cosine distance for a float vector, INVERTED for text, and STL_SORT for a numeric field.
- Create a collection without indexes so index creation is explicit.
- Call
CreateIndexwith field, index name, type, metric, and HNSW build parameters. - Use
ListIndexesto inspect all indexes andDescribeIndexfor detailed metadata. - Drop one index, then drop the collection and remaining indexes.
Vector indexes require a compatible metric. Scalar choices include INVERTED for general filtering
and STL_SORT for ordered numeric values; AutoIndex is a convenient server-selected alternative.
Use a C++14 compiler, CMake 3.16+, Python 3, Conan 2, and Milvus 2.6 or later. Defaults are
MILVUS_URI=http://localhost:19530 and MILVUS_TOKEN=root:Milvus.
make
make runThe project consumes milvus-sdk-cpp/3.0.3@milvus/dev by default. Package and connection settings
can be overridden with the MILVUS_SDK_*, MILVUS_URI, and MILVUS_TOKEN environment variables.
Index listing order and numeric type values may vary by server, but a successful run includes:
Calling Connect...
Connect succeeded.
Calling DropCollection for stale data...
Stale collection cleanup completed.
Calling CreateCollection...
CreateCollection succeeded.
Calling CreateIndex...
CreateIndex succeeded.
Calling ListIndexes...
ListIndexes succeeded.
embedding_hnsw_idx field=embedding type=...
category_inverted_idx field=category type=...
price_sort_idx field=price type=...
Calling DescribeIndex...
DescribeIndex succeeded.
Described vector indexes: 1
Calling DropIndex...
DropIndex succeeded.
Calling DropCollection...
DropCollection succeeded.
- index creation errors: verify field, index type, metric, and extra parameters are compatible.
- index timeout: check Milvus health and available CPU and memory.
- connection or authentication errors: check
MILVUS_URIandMILVUS_TOKEN. - rerunning after interruption: the fixed tutorial collection is removed first.