跳到主要内容
版本:v2.6.x

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)

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

Go
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: "localhost:19530",
})
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)