Vearch Rust SDK
A high-level Rust client for the Vearch vector database, providing a type-safe and ergonomic API for vector similarity search and document operations.
Features
- ๐ Async/await support - Built with Tokio for high-performance async operations
- ๐ Type-safe API - Full Rust type safety with comprehensive error handling
- ๐๏ธ Builder pattern - Fluent API for building complex queries and filters
- ๐ Complete coverage - All major Vearch operations supported
- ๐๏ธ Database management - Create, delete, and manage databases
- ๐๏ธ Space management - Create, configure, and manage table spaces
- ๐ RBAC Authentication - Role-based access control with user and role management
- ๐งช Well tested - Comprehensive test coverage and examples
Installation
Add this to your Cargo.toml:
[]
= "3.5.0"
= { = "1.0", = ["full"] }
Quick Start
use ;
async
Core Concepts
Documents
Documents are the primary data structure in Vearch, containing both scalar fields and vector fields:
use Document;
let doc = new
.with_field
.with_field
.with_field
.with_vector;
Vector Fields
Vector fields store high-dimensional vectors for similarity search:
use VectorField;
let vector = new
.with_min_score
.with_max_score;
Filters
Filters allow you to query documents based on scalar field values:
use ;
let filter = new
.gte
.in_values
.lt
.build;
Index Parameters
Configure search behavior with index-specific parameters:
use IndexParamsBuilder;
let params = new
.metric_type
.ef_search // For HNSW index
.nprobe // For IVFFLAT index
.build;
Databases
Databases are the top-level containers in Vearch:
use DatabaseBuilder;
let db_request = new
.with_description
.build;
Table Spaces
Table spaces define the schema and indexing for documents:
use ;
let space_request = new
.with_field
.with_field
.with_index
.with_partition_num
.with_replica_num
.build;
API Reference
Document Operations
Insert/Update Documents
// Insert new documents
let docs = vec!;
let result = client.upsert.await?;
println!;
Query Documents
// Query by document IDs
let docs = client.query.await?;
// Query by filters
let docs = client.query.await?;
Search Documents
// Simple vector search
let result = client.search.await?;
// Advanced search with filters and parameters
let result = client.search_with_request.await?;
Delete Documents
// Delete by IDs
let result = client.delete_by_ids.await?;
// Delete by filter
let result = client.delete_by_filter.await?;
Database Operations
Create Database
let db_request = new
.with_description
.build;
let result = client.create_database.await?;
Manage Database
// List all databases
let databases = client.list_databases.await?;
// Get database info
let db_info = client.get_database.await?;
// Delete database
let result = client.delete_database.await?;
Table Space Operations
Create Table Space
let space_request = new
.with_field
.with_field
.with_index
.with_partition_num
.with_replica_num
.build;
let result = client.create_space.await?;
Manage Table Space
// List spaces in database
let spaces = client.list_spaces.await?;
// Get space info
let space_info = client.get_space.await?;
// Get space statistics
let stats = client.get_space_stats.await?;
// Rebuild index
let result = client.rebuild_index.await?;
// Delete space
let result = client.delete_space.await?;
Filter Operations
Building Complex Filters
use ;
// Using the builder pattern
let filter = new
.gte
.lt
.in_values
.not_in
.build;
// Using utility functions
let range_filter = range_filter;
let text_filter = text_filter;
Filter Operators
Supported operators:
>- Greater than>=- Greater than or equal<- Less than<=- Less than or equalIN- Value in listNOT IN- Value not in list
Search Configuration
Index Types
HNSW (Hierarchical Navigable Small World)
let params = new
.metric_type
.ef_search
.build;
IVFFLAT (Inverted File with Flat compression)
let params = new
.metric_type
.nprobe
.parallel_on_queries
.build;
FLAT (Exhaustive search)
let params = new
.metric_type
.build;
Multi-Vector Search
let ranker = weighted_ranker;
let result = client.search_with_request.await?;
Authentication and Authorization
The SDK supports Vearch's RBAC (Role-Based Access Control) system for secure access management.
Setting up Authentication
use ;
// Create client with authentication
let auth_config = new
.with_role
.build;
let mut client = new?
.with_auth;
// Login to get authentication token
client.login.await?;
Managing Roles and Permissions
use ;
// Create role with specific permissions
let privileges = new
.document
.space
.database
.build;
let role = new
.with_privileges
.build;
client.create_role.await?;
Managing Users
use UserBuilder;
let user = new
.with_role
.build;
client.create_user.await?;
Supported Resource Types
ResourceAll- All resources (root access)ResourceCluster- Cluster managementResourceDB- Database operationsResourceSpace- Table space operationsResourceDocument- Document operationsResourceIndex- Index management- And more...
Permission Levels
ReadOnly- Read-only accessWriteOnly- Write-only accessWriteRead- Full read-write access
Error Handling
The SDK provides comprehensive error handling:
use ;
match client.upsert.await
Configuration
Client Options
use Duration;
// Custom timeout
let client = with_timeout?;
// Clone client for concurrent use
let client2 = client.clone;
Load Balancing
let result = client.search_with_request.await?;
Examples
See the examples/ directory for complete working examples:
basic_operations.rs- Basic CRUD operationsvector_search.rs- Vector similarity searchdatabase_operations.rs- Database and table space managementauthentication.rs- RBAC authentication and authorizationfilters.rs- Complex filtering examplesbatch_operations.rs- Batch document operations
Testing
Run the test suite:
Run with verbose output:
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
This project is licensed under the Apache 2.0 License - see the LICENSE file for details.