Client Management
Relevant source files
The following files were used as context for generating this wiki page:
Introduction
Client Management is the central orchestration layer of the Milvus Rust SDK, responsible for establishing connections, managing gRPC communications, and handling authentication with the Milvus server. The primary interface is the Client struct, which encapsulates a MilvusServiceClient and provides an asynchronous API for collection operations, data manipulation, and administrative tasks.
The system supports fine-grained configuration through a ClientBuilder, allowing developers to define connection parameters such as URIs, timeouts, and security credentials. It serves as the gateway for all interactions, including user and role-based access control (RBAC), collection metadata management, and vector search operations.
Sources: src/client.rs, src/authentication.rs:1-25, README.md
Connection Architecture
The connection logic utilizes the tonic gRPC framework to communicate with the Milvus proxy or standalone server. Connections are established asynchronously, and the client maintains an internal gRPC service client that handles the underlying protocol buffers and network transport.
Sequence: Client Initialization
The following diagram illustrates the process of building and connecting a client to a Milvus instance.
Sources: src/client.rs, examples/authentication.rs:6-12
Configuration Options
The ClientBuilder provides several methods to customize the connection:
| Method | Type | Description |
|---|---|---|
new(uri) | String | Initializes builder with server endpoint (e.g., http://localhost:19530). |
username(u) | String | Sets the username for Basic Authentication. |
password(p) | String | Sets the password for Basic Authentication. |
timeout(d) | Duration | Sets the gRPC request timeout. |
Sources: src/client.rs, tests/aggressivehpctesting/phase_1_crud_and_indexing.rs:24-27
Service Methods and APIs
The Client implementation exposes a wide range of methods that map to the Milvus gRPC service definitions found in milvus.proto. These are categorized into Collection Management, Data Manipulation, and Administrative services.
Collection and Alias Management
Clients manage the lifecycle of collections and their aliases through high-level async methods.
// Example from tests/client.rs:69-75
let mut schema = CollectionSchemaBuilder::new(NAME, "hello world");
let schema = schema
.add_field(FieldSchema::new_int64("i64_field", ""))
.set_primary_key("i64_field")?
.build()?;
client.create_collection(schema, None).await?;
Sources: tests/client.rs:69-82, src/proto/milvus.proto.milvus.rs:887-945
Key Management Functions
| Function | Description | Source |
|---|---|---|
create_collection | Creates a new collection with a defined schema. | src/proto/milvus.proto.milvus.rs:887 |
has_collection | Checks for the existence of a collection by name. | src/proto/milvus.proto.milvus.rs:946 |
drop_collection | Deletes a collection and its associated data. | src/proto/milvus.proto.milvus.rs:916 |
create_alias | Assigns a new alias to an existing collection. | src/proto/milvus.proto.milvus.rs:1134 |
flush | Ensures all data in the collection is persisted. | src/proto/milvus.proto.milvus.rs:1351 |
Authentication and RBAC
The authentication module provides the logic for managing users, roles, and privileges. The SDK ensures security by encoding passwords in Base64 before transmission to the server.
User and Role Logic
The system allows for creating users, assigning them to roles, and granting specific privileges to those roles.
Security Data Structures
The SDK interacts with various gRPC message types to handle RBAC:
RoleEntity: Represents a security role name.UserEntity: Represents a system user.GrantEntity: Defines the relationship between a role, an object (resource), and a specific privilege.
Sources: src/proto/milvus.proto.milvus.rs:1631-1638, src/proto/milvus.proto.milvus.rs:1725-1744
User Management Operations
| Operation | Implementation Method | Description |
|---|---|---|
| Create User | create_user | Creates a credential with a Base64 encoded password. |
| Update Password | update_password | Securely updates an existing user password. |
| Grant Role | grant_role | Maps a user to a specific role entity. |
| Grant Privilege | grant_privilege_v2 | Grants a specific action (e.g., "Load") on a collection. |
Sources: src/authentication.rs:64-83, src/authentication.rs:608-644, src/authentication.rs:252-277
Conclusion
Client Management in the Milvus Rust SDK provides a robust, asynchronous interface for interacting with Milvus clusters. By abstracting gRPC complexities and providing a fluent ClientBuilder and comprehensive RBAC methods, the system allows for secure and efficient management of large-scale vector databases. The use of strongly typed schemas and result-based error handling ensures reliability in production environments.