milvus-logo
LFAI
< Docs
  • Go
    • Connections

NewClient()

This method creates a Milvus client that connects to a specific Milvus deployment.

func NewClient(ctx context.Context, config Config) (Client, error)

Request Parameter

Parameter

Description

Type

ctx

Context for the current call to work.

context.Context

config

Client configurations.

client.Config

client.Config

This struct type defines all possible client configuration items as follows:

type Config struct {
    Address       string // Remote address, "localhost:19530".
    Username      string // Username for auth.
    Password      string // Password for auth.
    DBName        string // DBName for this client.
    Identifier    string // Identifier for this connection
    EnableTLSAuth bool   // Enable TLS Auth for transport security.
    APIKey        string // API key (For Zilliz Cloud clusters only)
    ServerVersion string // ServerVersion

    DialOptions []grpc.DialOption // Dial options for GRPC.

    RetryRateLimit *RetryRateLimitOption // option for retry on rate limit interceptor

    DisableConn bool
    // contains filtered or unexported fields
}

client.RetryRateLimit

This struct type defines the retry options for the connection.

type RetryRateLimitOption struct {
    MaxRetry   uint
    MaxBackoff time.Duration
}

Return

A client.Client.

Errors

Any error in the execution of the request. Possible errors are as follows:

  • ErrClientNotReady: The client is not connected to Milvus.

  • The call to this API fails.

Example

import (
   "context"

   "github.com/milvus-io/milvus-sdk-go/v2/client"
)

mc, err := client.NewClient(context.Background(), client.Config{
   Address: "host:port",
})
if err != nil {
   // handle error
}
mc.HasCollection(context.Background(), "YOUR_COLLECTION_NAME")

Try Managed Milvus for Free

Zilliz Cloud is hassle-free, powered by Milvus and 10x faster.

Get Started
Feedback

Was this page helpful?