ContextLite Rust Client
A high-performance, async Rust client for ContextLite - the ultra-fast context engine for retrieval and AI applications.
Quick Start
Add this to your Cargo.toml
:
[]
= "1.0"
Basic usage:
use ;
async
Features
- High Performance: Built on Tokio for blazing-fast async operations
- Type Safety: Comprehensive type definitions with builder patterns
- Connection Pooling: HTTP connection pooling for optimal performance
- Error Handling: Rich error types with proper error chaining
- Authentication: Bearer token authentication support
- Validation: Client-side validation for better error messages
- Flexible API: Builder patterns for easy configuration
Supported Operations
✓ Health Checks - Server status and SMT solver information
✓ Document Management - Add, search, and delete documents
✓ Context Assembly - SMT-optimized context compilation
✓ Authentication - Bearer token security
✓ Error Handling - Comprehensive error types and retry logic
Example Usage
Document Operations
use ;
let client = new?;
// Add a document with metadata
let document = new
.with_metadata;
let doc_id = client.add_document.await?;
// Update the document
let updated_doc = new;
client.update_document.await?;
// Get the document
let retrieved = client.get_document.await?;
// Delete the document
client.delete_document.await?;
Advanced Search
use ;
let client = new?;
let query = new
.with_limit
.with_offset
.with_filters;
let results = client.search.await?;
for doc_ref in results.documents
Context Assembly
use ;
let client = new?;
let request = new
.with_budget // Token budget
.with_max_results // Max documents
.with_metadata; // Include metadata
let context = client.assemble_context.await?;
println!;
println!;
Configuration
Client Configuration
use ClientConfig;
let config = new
.with_auth_token
.with_timeout // 30 second timeout
.with_connection_pool; // Enable pooling, max 100 connections
let client = with_config?;
Environment Variables
The client respects these environment variables:
CONTEXTLITE_URL
: Default server URLCONTEXTLITE_TOKEN
: Default authentication tokenCONTEXTLITE_TIMEOUT
: Default timeout in seconds
Error Handling
The client provides comprehensive error handling with detailed error messages:
use ;
match client.health.await
Installation
Install ContextLite server:
# Via Cargo
# Via Homebrew (macOS/Linux)
# Via npm
# Via Python pip
Then add the client to your project:
Documentation
- Website: contextlite.com
- API Docs: docs.rs/contextlite-client
- GitHub: github.com/Michael-A-Kuykendall/contextlite
- Examples: Check the
examples/
directory in the repository
Testing
Run the tests (requires a running ContextLite server):
# Start ContextLite server on port 8083
# Run tests
Performance
The Rust client is designed for high performance:
- Connection Pooling: Reuses HTTP connections for better throughput
- Async I/O: Non-blocking operations using Tokio
- Zero-Copy: Minimal data copying where possible
- Efficient Serialization: Fast JSON processing with serde
License
This project is licensed under the MIT License - see the LICENSE file for details.
Contributing
- Fork the repository
- Create a feature branch
- Add tests for your changes
- Ensure all tests pass
- Submit a pull request
Built with care by the ContextLite Team