This topic describes how to create a DashVector client by using the SDK for Python.
With a DashVector client, you can connect to the DashVector server to perform operations on collections.
Prerequisites
A cluster is created. For more information, see Create a cluster.
An API key is obtained. For more information, see Manage API keys.
The SDK of the latest version is installed. For more information, see Install DashVector SDK.
API definition
dashvector.Client(
api_key: str,
endpoint: str,
protocol: dashvector.DashVectorProtocol = dashvector.DashVectorProtocol.GRPC,
timeout: float = 10.0
) -> ClientExample
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. |
To view the endpoint of the cluster, go to the cluster details page in the console.
We recommend that you use the default value
DashVectorProtocol.GRPCof the protocol parameter for higher performance.
Response parameters
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 |