IBM Cloud Docs
Connecting to Milvus service

Connecting to Milvus service

Run any one of the following commands to connect with Milvus:

Before you begin

Make sure that the following items are installed or available:

  • Python and Pymilvus package. For more information, see About PyMilvus.
  • Hostname and port for the Milvus instance. You can get Milvus host and port information from Infrastructure manager (click the Milvus service to open the Details page and note the host and port information from the GRPC host).
  • Assign a role to the user or service ID from Infrastructure manager. For information about user roles, see Managing roles and privileges.

Procedure

You can connect to a Milvus service by using API key or IAM token.

  1. Provision a Milvus service in watsonx.data. For more information, see Adding a Milvus service.

  2. Run one of the following commands by using Python SDK (PyMilvus) to connect with Milvus for gRPC route:

    • Using GRPC calls:

      print(fmt.format("start connecting to Milvus"))
      connections.connect(host="<host>", port="<port>", secure=True, user="ibmlhapikey", password="<api-key>")
      has = utility.has_collection("hello_milvus")
      print(f"Does collection hello_milvus exist in Milvus: {has}")
      

      Replace <api-key> with the IBM API key. For information about getting an API key, see Getting IBM API Key.

    • Using IAM token

      connections.connect(host="<host>", port="<port>", secure=True, user="ibmlhtoken", password="<token>")
      

      Replace <token> with the IAM token. For information about getting a token, see Getting IBM Access Management (IAM) token.

    • Using Uniform Resource Identifier (URI)

      print(fmt.format("start connecting to Milvus"))
      connections.connect( alias="default", uri="https://<host>:<grpc-port>", user = "ibmlhtoken", password = "<token>" )
      has = utility.has_collection("hello_milvus")
      print(f"Does collection hello_milvus exist in Milvus: {has}")
      

      Replace <token> with the IAM token. For information about getting a token, see Getting IBM Access Management (IAM) token.

What to do next

You can perform the following operations after establishing a connection with a Milvus service:

  • Manage data

  • Manage databases: You can create databases in Milvus and allocate privileges to certain users to manage them. A Milvus cluster supports a maximum of 64 databases. For more information, see Manage Databases.

  • Manage collections: You can create and manage collections using the SDK of your choice. A Milvus cluster supports a maximum of 65,536 collections. For more information, see Manage Collections.

  • Manage partitions: You can create and manage partitions in a collection. A Milvus cluster supports a maximum of 4095 partitions. For more information, see Manage Partitions.

  • Manage indexes: You can creating and managing indexes on vector fields in a collection. For more information, see Manage Indexes.

  • Search and Query: For information searching and querying data in Milvus, see Search, Query & Get.