Crate contextlite_client

Crate contextlite_client 

Source
Expand description

§ContextLite Rust Client

A high-performance, async Rust client for the ContextLite context engine.

§Features

  • Async/Await Support: Built on Tokio for high-performance async operations
  • Type Safety: Comprehensive type definitions with builder patterns
  • Error Handling: Rich error types with proper error chaining
  • Connection Pooling: HTTP connection pooling for optimal performance
  • Authentication: Bearer token authentication support
  • Validation: Client-side validation for better error messages
  • Flexible API: Builder patterns for easy configuration

§Quick Start

use contextlite_client::{ContextLiteClient, ClientConfig, Document, SearchQuery};
 
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    // Create a client with default configuration
    let client = ContextLiteClient::new("http://localhost:8080")?;
     
    // Or with custom configuration
    let config = ClientConfig::new("http://localhost:8083")
        .with_auth_token("your-token")
        .with_timeout(60);
    let client = ContextLiteClient::with_config(config)?;
     
    // Add a document
    let document = Document::new("example.txt", "This is an example document");
    let doc_id = client.add_document(&document).await?;
     
    // Search for documents
    let query = SearchQuery::new("example").with_limit(10);
    let results = client.search(&query).await?;
     
    println!("Found {} documents", results.documents.len());
     
    Ok(())
}

§Error Handling

The client provides comprehensive error handling with detailed error messages:

use contextlite_client::{ContextLiteClient, ContextLiteError};
 
#[tokio::main]
async fn main() {
    let client = ContextLiteClient::new("http://localhost:8080").unwrap();
     
    match client.health().await {
        Ok(health) => println!("Server is healthy: {}", health.status),
        Err(ContextLiteError::AuthError { message }) => {
            eprintln!("Authentication failed: {}", message);
        },
        Err(ContextLiteError::ServerError { status, message }) => {
            eprintln!("Server error {}: {}", status, message);
        },
        Err(err) => eprintln!("Error: {}", err),
    }
}

Re-exports§

pub use client::ContextLiteClient;
pub use error::ContextLiteError;
pub use error::Result;
pub use types::CompleteHealthStatus;
pub use types::SmtInfo;
pub use types::DatabaseStats;
pub use types::Features;
pub use types::ClientConfig;
pub use types::ContextRequest;
pub use types::ContextResponse;
pub use types::Document;
pub use types::DocumentReference;
pub use types::SearchQuery;
pub use types::SearchResponse;
pub use types::StorageInfo;

Modules§

client
ContextLite HTTP client implementation.
error
Error types for the ContextLite Rust client.
types
Core types for the ContextLite Rust client.

Type Aliases§

Client
Convenience alias for the main client type