Skip to main content

New

This operation creates a connection to the specified Milvus server with the specified configuration.

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

Request Syntax​

Creates a connection to the specified Milvus server.

go
cli, err := milvusclient.New(ctx, &milvusclient.ClientConfig{
Address: "YOUR_CLUSTER_ENDPOINT",
})

PARAMETERS:

  • config (*ClientConfig) -

    The configuration for the connection, including the Milvus server address.

RETURN TYPE:

*Client, error

RETURNS:

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

PARAMETERS:

  • result (*Client) -

    The *Client value returned by New().

ERROR HANDLING:

  • error

    The operation fails. Check err != nil for failure details.

Example​

Demonstrates New() usage.

go
import (
"context"
"fmt"
"log"

"github.com/milvus-io/milvus/client/v3/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)
Minimum SDK versionv3.0.x
Was this page helpful?