All Products
Search
Document Center

DashVector:Create a client

Last Updated:Apr 11, 2024

This topic describes how to create a DashVector client by using the SDK for Python.

Note

With a DashVector client, you can connect to the DashVector server to perform operations on collections.

Prerequisites

API definition

dashvector.Client(
    api_key: str,
    endpoint: str,
    protocol: dashvector.DashVectorProtocol = dashvector.DashVectorProtocol.GRPC,
    timeout: float = 10.0
) -> Client

Example

Note

You need to replace YOUR_API_KEY with your API key and YOUR_CLUSTER_ENDPOINT with the endpoint of your cluster in the sample code for the code to run properly.

import dashvector

client = dashvector.Client(
    api_key='YOUR_API_KEY',
    endpoint='YOUR_CLUSTER_ENDPOINT'
)

# Check whether the client is successfully created.
if client:
    print('create client success!')

# You can also use the following code to check whether the client is successfully created.
# from dashvector import DashVectorCode
# if client.code == DashVectorCode.Success:
#     print('create client success!')

Request parameters

Parameter

Type

Default value

Description

api_key

str

-

The API key.

endpoint

str

-

The endpoint of the cluster.

protocol

DashVectorProtocol

DashVectorProtocol.GRPC

Optional. The communication protocol. Valid values: DashVectorProtocol.GRPC and DashVectorProtocol.HTTP.

timeout

float

10.0

Optional. The timeout period, in seconds. A value of -1 indicates no timeout.

Note
  1. To view the endpoint of the cluster, go to the cluster details page in the console.

  2. We recommend that you use the default value DashVectorProtocol.GRPC of the protocol parameter for higher performance.

Response parameters

Note

A Client object is returned, which contains the operation result, as described in the following table.

Field

Type

Description

Example

code

int

The returned status code. For more information, see Status codes.

0

message

str

The returned message.

success

request_id

str

The unique ID of the request.

19215409-ea66-4db9-8764-26ce2eb5bb99