Skip to main content

New()

Addedv2.6.x

This operation creates a connection to the specified Zilliz Cloud cluster with the specified configuration.

func New(ctx context.Context, config *ClientConfig) (*Client, error)

RETURN TYPE:

*Client, error

RETURNS:

A connected Client instance ready for use. Returns an error if the connection fails.

EXCEPTIONS:

  • error

    Check err != nil for failure details.

Example

import (
"context"
"fmt"
"log"

"github.com/milvus-io/milvus/client/v2/milvusclient"
)

ctx, cancel := context.WithCancel(context.Background())
defer cancel()

// Connect to a local Milvus server
cli, err := milvusclient.New(ctx, &milvusclient.ClientConfig{
Address: "YOUR_CLUSTER_ENDPOINT",
})
if err != nil {
log.Fatal("failed to create client:", err)
}
defer cli.Close(ctx)

collections, err := cli.ListCollections(ctx, milvusclient.NewListCollectionOption())
if err != nil {
log.Fatal("failed to list collections:", err)
}
fmt.Println(collections)