148 lines
4.2 KiB
Rust
148 lines
4.2 KiB
Rust
//! High-performance feature store for online and offline ML feature serving
|
|
//!
|
|
//! This crate provides comprehensive feature store capabilities including:
|
|
//! - Online feature serving with sub-100ms retrieval
|
|
//! - Offline feature computation and storage
|
|
//! - Point-in-time correctness with temporal consistency
|
|
//! - Feature versioning and lineage tracking
|
|
//! - Vector store integrations for embedding storage
|
|
//! - Real-time feature drift monitoring
|
|
//! - Batch and streaming feature computation
|
|
|
|
#![deny(missing_docs)]
|
|
|
|
// Module declarations
|
|
pub mod computation;
|
|
pub mod serving;
|
|
pub mod store;
|
|
pub mod vector_store;
|
|
pub mod versioning;
|
|
|
|
// Re-exports for convenience
|
|
pub use computation::{
|
|
ComputationJob, ComputationResult, ComputeConfig, FeatureComputeEngine, JobStatus,
|
|
};
|
|
pub use serving::{
|
|
BatchFeatureRequest, BatchFeatureResponse, DriftReport, FeatureRequest, FeatureResponse,
|
|
OnlineServer, ServingConfig,
|
|
};
|
|
pub use store::{FeatureBatch, FeatureMetadata, FeatureStore, FeatureStoreConfig, FeatureValue};
|
|
pub use vector_store::{EmbeddingConfig, SearchFilter, SimilarityResult, VectorStore};
|
|
pub use versioning::{
|
|
CompatibilityResult, FeatureLineage, FeatureVersion, VersionManager, VersionMetadata,
|
|
};
|
|
|
|
/// Feature store error types
|
|
#[derive(Debug, thiserror::Error)]
|
|
pub enum FeatureStoreError {
|
|
/// Storage backend error
|
|
#[error("Storage error: {0}")]
|
|
Storage(String),
|
|
|
|
/// Feature or entity not found
|
|
#[error("Not found: {0}")]
|
|
NotFound(String),
|
|
|
|
/// Configuration error
|
|
#[error("Configuration error: {0}")]
|
|
Configuration(String),
|
|
|
|
/// Validation error
|
|
#[error("Validation error: {0}")]
|
|
Validation(String),
|
|
|
|
/// Computation error
|
|
#[error("Computation error: {0}")]
|
|
Computation(String),
|
|
|
|
/// Version compatibility error
|
|
#[error("Version error: {0}")]
|
|
Version(String),
|
|
|
|
/// Vector store error
|
|
#[error("Vector store error: {0}")]
|
|
VectorStore(String),
|
|
}
|
|
|
|
/// Result type for feature store operations
|
|
pub type Result<T> = std::result::Result<T, FeatureStoreError>;
|
|
|
|
/// Feature store builder for convenient configuration
|
|
#[derive(Debug, Default)]
|
|
pub struct FeatureStoreBuilder {
|
|
postgres_url: Option<String>,
|
|
redis_url: Option<String>,
|
|
vector_store_url: Option<String>,
|
|
enable_caching: bool,
|
|
cache_ttl: std::time::Duration,
|
|
max_connections: u32,
|
|
}
|
|
|
|
impl FeatureStoreBuilder {
|
|
/// Create a new feature store builder
|
|
#[must_use]
|
|
pub fn new() -> Self {
|
|
Self {
|
|
postgres_url: None,
|
|
redis_url: None,
|
|
vector_store_url: None,
|
|
enable_caching: true,
|
|
cache_ttl: std::time::Duration::from_secs(300),
|
|
max_connections: 10,
|
|
}
|
|
}
|
|
|
|
/// Set `PostgreSQL` connection URL
|
|
pub fn with_postgres(mut self, url: impl Into<String>) -> Self {
|
|
self.postgres_url = Some(url.into());
|
|
self
|
|
}
|
|
|
|
/// Set Redis connection URL for caching
|
|
pub fn with_redis(mut self, url: impl Into<String>) -> Self {
|
|
self.redis_url = Some(url.into());
|
|
self
|
|
}
|
|
|
|
/// Set vector store connection URL
|
|
pub fn with_vector_store(mut self, url: impl Into<String>) -> Self {
|
|
self.vector_store_url = Some(url.into());
|
|
self
|
|
}
|
|
|
|
/// Enable or disable caching
|
|
#[must_use]
|
|
pub fn with_caching(mut self, enabled: bool) -> Self {
|
|
self.enable_caching = enabled;
|
|
self
|
|
}
|
|
|
|
/// Set cache TTL duration
|
|
#[must_use]
|
|
pub fn with_cache_ttl(mut self, ttl: std::time::Duration) -> Self {
|
|
self.cache_ttl = ttl;
|
|
self
|
|
}
|
|
|
|
/// Set maximum database connections
|
|
#[must_use]
|
|
pub fn with_max_connections(mut self, max: u32) -> Self {
|
|
self.max_connections = max;
|
|
self
|
|
}
|
|
|
|
/// Build the feature store
|
|
pub async fn build(self) -> Result<FeatureStore> {
|
|
let config = FeatureStoreConfig {
|
|
postgres_url: self.postgres_url,
|
|
redis_url: self.redis_url,
|
|
vector_store_url: self.vector_store_url,
|
|
enable_caching: self.enable_caching,
|
|
cache_ttl: self.cache_ttl,
|
|
max_connections: self.max_connections,
|
|
};
|
|
|
|
FeatureStore::new(config).await
|
|
}
|
|
}
|