Getting Started
Relevant source files
The following files were used as context for generating this wiki page:
The Milvus Rust SDK is the official library for interacting with the Milvus vector database using the Rust programming language. It facilitates connection management, collection schema definition, data mutation (insert, delete, upsert), and high-performance vector similarity searches or scalar queries. Sources: README.md:1-5, Cargo.toml:1-5
This guide provides the necessary steps to integrate the SDK into a Rust project, establish a connection to a Milvus cluster, and perform fundamental operations such as collection creation and indexing. Sources: README.md:7-10, examples/index_example.rs:17-25
Installation and Setup
To use the Milvus SDK in your Rust application, add it as a dependency in your Cargo.toml file or use the cargo command line tool. Sources: README.md:10-12
cargo add milvus-sdk-rust
The SDK relies on several core dependencies to handle asynchronous networking and data serialization, specifically tonic for gRPC communication, tokio for the runtime, and prost for Protocol Buffers. Sources: Cargo.toml:12-28
Development Prerequisites
For developers contributing to or testing the SDK, the following tools are required:
- Cargo: Rust package manager and build tool.
- Protocol Compiler: Required for compiling
.protofiles viabuild.rs. - Docker: Used to spin up local Milvus instances for integration testing.
Sources: README.md:31-35, build.rs:5-18
Establishing a Connection
Connections are managed through the Client or ClientBuilder structures. The client communicates with the Milvus proxy using gRPC. Sources: src/authentication.rs:53-55, examples/authentication.rs:7-12
Client Lifecycle Flow
The following diagram illustrates the typical lifecycle of a Milvus client from initialization to collection management.
Authentication Configuration
The SDK supports basic authentication. Credentials can be provided during client initialization. Sources: examples/authentication.rs:7-10, src/authentication.rs:18-35
| Option | Type | Description |
|---|---|---|
URL | String | Endpoint of the Milvus server (e.g., http://localhost:19530) |
username | String | Username for basic auth (default: "root") |
password | String | Password for basic auth (default: "Milvus") |
| Sources: examples/authentication.rs:7-12, README.md:18 |
Schema and Collection Management
Before data can be inserted, a CollectionSchema must be defined. This involves using the CollectionSchemaBuilder to specify fields, data types, and primary keys. Sources: examples/index_example.rs:25-35, src/proto/milvus.proto.milvus.rs:76-92
Field Schemas
Milvus supports various data types, including scalars (Int64, VarChar) and vectors (FloatVector). Sources: examples/query_search.rs:104-110, src/proto/milvus.proto.milvus.rs:434-445
let mut schema = CollectionSchemaBuilder::new(COLLECTION_NAME, "Description");
schema
.add_field(FieldSchema::new_primary_int64("id", "primary key", true))
.add_field(FieldSchema::new_float_vector("embeddings", "vector field", 128))
.add_field(FieldSchema::new_varchar("title", "scalar field", 64))
.enable_dynamic_field();
let schema = schema.build()?;
Sources: examples/index_example.rs:25-35
Data Operations
Once a collection is created, you can insert data and build indexes. Data is organized into FieldColumn objects before being sent via the insert method. Sources: examples/index_example.rs:51-60, examples/query_search.rs:114-125
Indexing and Loading
Indexing is required for efficient vector similarity searches. After creating an index, the collection must be loaded into memory. Sources: examples/index_example.rs:70-85, src/proto/milvus.proto.milvus.rs:175-188
Search and Query
- Search: Performed on vector fields using query vectors and specific search parameters (e.g.,
nprobe,radius). Sources: examples/query_search.rs:54-68, src/proto/milvus.proto.milvus.rs:475-495 - Query: Used for scalar filtering using boolean expressions (e.g.,
id > 100). Sources: examples/query_search.rs:31-45, examples/index_example.rs:90-95
Summary
Starting with the Milvus Rust SDK involves adding the dependency to Cargo.toml, initializing a Client with optional authentication, and defining a structured CollectionSchema. Users must follow the sequence of Inserting data, Creating an Index, and Loading the collection before vector searches can be executed. The library utilizes gRPC for all server communications, ensuring type-safe and performant interactions with the Milvus ecosystem. Sources: README.md:7-30, examples/index_example.rs:17-110, Cargo.toml:12-25