pub struct RecommendationEngine { /* private fields */ }Expand description
Main recommendation engine coordinating all recommendation capabilities
Implementations§
Source§impl RecommendationEngine
impl RecommendationEngine
Sourcepub fn with_rate_limiter(config: RateLimitConfig, now: i64) -> Self
pub fn with_rate_limiter(config: RateLimitConfig, now: i64) -> Self
Create a new recommendation engine with rate limiting enabled.
config controls per-user and global token-bucket parameters.
now is the initial Unix timestamp (seconds) used to seed the buckets.
Sourcepub fn set_rate_limiter(&mut self, config: RateLimitConfig, now: i64)
pub fn set_rate_limiter(&mut self, config: RateLimitConfig, now: i64)
Enable (or replace) the rate limiter on an existing engine.
Sourcepub fn disable_rate_limiter(&mut self)
pub fn disable_rate_limiter(&mut self)
Disable rate limiting on this engine.
Sourcepub fn has_rate_limiter(&self) -> bool
pub fn has_rate_limiter(&self) -> bool
Returns true if rate limiting is currently enabled.
Sourcepub fn user_available_tokens(&self, user_id: &str) -> Option<f64>
pub fn user_available_tokens(&self, user_id: &str) -> Option<f64>
Query how many tokens remain for a user without consuming any.
Returns None if rate limiting is disabled or if the user has no bucket yet.
Sourcepub fn global_available_tokens(&self) -> Option<f64>
pub fn global_available_tokens(&self) -> Option<f64>
Query how many global tokens remain without consuming any.
Returns None if rate limiting is disabled.
Sourcepub fn recommend(
&mut self,
request: &RecommendationRequest,
) -> RecommendResult<RecommendationResults>
pub fn recommend( &mut self, request: &RecommendationRequest, ) -> RecommendResult<RecommendationResults>
Get recommendations for a user
For the Hybrid strategy, all sub-strategies are evaluated in parallel
via rayon. The resulting candidate lists are merged and deduplicated by
content ID, taking the maximum score for any item that appeared in
multiple strategy outputs.
If a rate limiter is configured, the request is checked against both the
per-user and global token buckets. When the limit is exceeded a
RecommendError::RateLimited error is returned immediately.
§Errors
Returns an error if recommendation generation fails or the caller is rate-limited.
Sourcepub fn record_view(
&mut self,
user_id: Uuid,
content_id: Uuid,
watch_time_ms: i64,
completed: bool,
) -> RecommendResult<()>
pub fn record_view( &mut self, user_id: Uuid, content_id: Uuid, watch_time_ms: i64, completed: bool, ) -> RecommendResult<()>
Sourcepub fn record_rating(
&mut self,
user_id: Uuid,
content_id: Uuid,
rating: f32,
) -> RecommendResult<()>
pub fn record_rating( &mut self, user_id: Uuid, content_id: Uuid, rating: f32, ) -> RecommendResult<()>
Sourcepub fn update_trending(&mut self) -> RecommendResult<()>
pub fn update_trending(&mut self) -> RecommendResult<()>
Sourcepub fn get_user_profile(&self, user_id: Uuid) -> RecommendResult<UserProfile>
pub fn get_user_profile(&self, user_id: Uuid) -> RecommendResult<UserProfile>
Sourcepub fn get_similar_users(
&self,
user_id: Uuid,
limit: usize,
) -> RecommendResult<Vec<Uuid>>
pub fn get_similar_users( &self, user_id: Uuid, limit: usize, ) -> RecommendResult<Vec<Uuid>>
Trait Implementations§
Auto Trait Implementations§
impl Freeze for RecommendationEngine
impl RefUnwindSafe for RecommendationEngine
impl Send for RecommendationEngine
impl Sync for RecommendationEngine
impl Unpin for RecommendationEngine
impl UnsafeUnpin for RecommendationEngine
impl UnwindSafe for RecommendationEngine
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> 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