pub struct StorageLayer {
pub database: Arc<Database>,
pub redis: Arc<RedisPool>,
pub files: Arc<FileStorage>,
pub vector: Option<Arc<VectorStoreBackend>>,
pub redis_status: DependencyStatus,
pub vector_status: DependencyStatus,
}Expand description
Main storage layer that orchestrates all storage backends
Fields§
§database: Arc<Database>Database connection pool
redis: Arc<RedisPool>Redis connection pool
files: Arc<FileStorage>File storage backend
vector: Option<Arc<VectorStoreBackend>>Vector database client (optional) Note: Using concrete type instead of trait object for now
redis_status: DependencyStatusStatus of the Redis dependency after init.
vector_status: DependencyStatusStatus of the vector DB dependency after init.
Implementations§
Source§impl StorageLayer
impl StorageLayer
Sourcepub async fn new(config: &StorageConfig) -> Result<Self>
pub async fn new(config: &StorageConfig) -> Result<Self>
Create a new storage layer.
For each optional dependency:
- if
enabledisfalse(or the section is absent), the dependency is treated asDisabledand a no-op fallback is used, - if
enabledistrueand init succeeds, status isHealthy, - if
enabledistrue, init fails, andallow_degradedisfalse, the call returnsErrso startup fails loudly, - if
enabledistrue, init fails, andallow_degradedistrue, the error is logged aterror!level and the dependency status is set toDegradedwhile the gateway keeps running.
Sourcepub async fn health_check(&self) -> Result<StorageHealthStatus>
pub async fn health_check(&self) -> Result<StorageHealthStatus>
Health check for all storage backends
Sourcepub fn files(&self) -> &FileStorage
pub fn files(&self) -> &FileStorage
Get file storage
Sourcepub fn vector(&self) -> Option<&VectorStoreBackend>
pub fn vector(&self) -> Option<&VectorStoreBackend>
Get vector store (if available)
Sourcepub async fn redis_conn(&self) -> Result<RedisConnection>
pub async fn redis_conn(&self) -> Result<RedisConnection>
Get a Redis connection
Sourcepub async fn store_file(&self, filename: &str, content: &[u8]) -> Result<String>
pub async fn store_file(&self, filename: &str, content: &[u8]) -> Result<String>
Store file and return file ID
Sourcepub async fn delete_file(&self, file_id: &str) -> Result<()>
pub async fn delete_file(&self, file_id: &str) -> Result<()>
Delete file
Sourcepub async fn store_embeddings(
&self,
id: &str,
embeddings: &[f32],
metadata: Option<Value>,
) -> Result<()>
pub async fn store_embeddings( &self, id: &str, embeddings: &[f32], metadata: Option<Value>, ) -> Result<()>
Store vector embeddings
Sourcepub async fn search_similar(
&self,
query_vector: &[f32],
limit: usize,
threshold: Option<f32>,
) -> Result<Vec<SearchResult>>
pub async fn search_similar( &self, query_vector: &[f32], limit: usize, threshold: Option<f32>, ) -> Result<Vec<SearchResult>>
Search similar vectors
Sourcepub async fn cache_set(
&self,
key: &str,
value: &str,
ttl: Option<u64>,
) -> Result<()>
pub async fn cache_set( &self, key: &str, value: &str, ttl: Option<u64>, ) -> Result<()>
Set cache value with optional TTL
Sourcepub async fn cache_delete(&self, key: &str) -> Result<()>
pub async fn cache_delete(&self, key: &str) -> Result<()>
Delete cache key
Sourcepub async fn cache_exists(&self, key: &str) -> Result<bool>
pub async fn cache_exists(&self, key: &str) -> Result<bool>
Check if cache key exists
Sourcepub async fn cache_mget(&self, keys: &[String]) -> Result<Vec<Option<String>>>
pub async fn cache_mget(&self, keys: &[String]) -> Result<Vec<Option<String>>>
Batch cache operations
Sourcepub async fn cache_mset(
&self,
pairs: &[(String, String)],
ttl: Option<u64>,
) -> Result<()>
pub async fn cache_mset( &self, pairs: &[(String, String)], ttl: Option<u64>, ) -> Result<()>
Set multiple cache values with optional TTL
Sourcepub async fn list_push(&self, key: &str, value: &str) -> Result<()>
pub async fn list_push(&self, key: &str, value: &str) -> Result<()>
List operations Push value to list
Sourcepub async fn list_length(&self, key: &str) -> Result<usize>
pub async fn list_length(&self, key: &str) -> Result<usize>
Get list length
Sourcepub async fn set_add(&self, key: &str, member: &str) -> Result<()>
pub async fn set_add(&self, key: &str, member: &str) -> Result<()>
Set operations Add member to set
Sourcepub async fn hash_set(&self, key: &str, field: &str, value: &str) -> Result<()>
pub async fn hash_set(&self, key: &str, field: &str, value: &str) -> Result<()>
Hash operations Set hash field value
Sourcepub async fn hash_get(&self, key: &str, field: &str) -> Result<Option<String>>
pub async fn hash_get(&self, key: &str, field: &str) -> Result<Option<String>>
Get hash field value
Sourcepub async fn hash_get_all(&self, key: &str) -> Result<HashMap<String, String>>
pub async fn hash_get_all(&self, key: &str) -> Result<HashMap<String, String>>
Get all hash fields and values
Sourcepub async fn subscribe(&self, channels: &[String]) -> Result<Subscription>
pub async fn subscribe(&self, channels: &[String]) -> Result<Subscription>
Subscribe to Redis channels Subscribe to Redis channels for pub/sub messaging
Trait Implementations§
Source§impl Clone for StorageLayer
impl Clone for StorageLayer
Auto Trait Implementations§
impl !RefUnwindSafe for StorageLayer
impl !UnwindSafe for StorageLayer
impl Freeze for StorageLayer
impl Send for StorageLayer
impl Sync for StorageLayer
impl Unpin for StorageLayer
impl UnsafeUnpin for StorageLayer
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> BudgetAwareRouting for T
impl<T> BudgetAwareRouting for T
Source§fn filter_by_budget(
&self,
providers: Vec<String>,
budget_router: &BudgetAwareRouter,
) -> Vec<String>
fn filter_by_budget( &self, providers: Vec<String>, budget_router: &BudgetAwareRouter, ) -> Vec<String>
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more