This is the smallest complete MilvusClientV2 application in the C++ SDK. It connects to Milvus,
creates a collection with an integer primary key, text, and a float vector, inserts two rows,
loads the collection, performs a cosine vector search, and removes the collection.
- Create and connect a
MilvusClientV2instance. - Define a collection schema and an
AutoIndex. - Insert row-oriented
EntityRows. - Load a collection and run a strongly consistent search.
- Release and drop resources during cleanup.
- C++14 compiler, CMake 3.16+, Python 3, and Conan 2.
- Milvus 2.6 or later running at an accessible endpoint.
The tutorial defaults to MILVUS_URI=http://localhost:19530 and
MILVUS_TOKEN=root:Milvus. Override them when needed:
MILVUS_URI="https://your-endpoint" MILVUS_TOKEN="your-token" make runFrom this directory:
make
make runmake installs milvus-sdk-cpp as a Conan dependency (default 3.0.2@milvus/dev), configures
CMake, and builds cmake_build/tutorial_quickstart. Set MILVUS_SDK_VERSION,
MILVUS_SDK_USER, or MILVUS_SDK_CHANNEL to consume another package reference.
The program cleans up its tutorial collection on normal completion. make clean removes the local
build directory.
A successful run includes:
Calling Connect...
Connect succeeded.
Calling DropCollection for stale data...
Stale collection cleanup completed.
Calling CreateCollection...
CreateCollection succeeded.
Calling Insert...
Insert succeeded: 2 rows.
Calling LoadCollection...
LoadCollection succeeded.
Calling Search...
Search succeeded.
Search result sets: ...
Calling ReleaseCollection...
ReleaseCollection succeeded.
Calling DropCollection...
DropCollection succeeded.
connection refused: start Milvus or setMILVUS_URIto the reachable endpoint.unauthenticatedorpermission denied: set a validMILVUS_TOKEN.- load or search failures: verify that Milvus is healthy and has enough resources.