pub struct ContentRecommender { /* private fields */ }Expand description
Implementations§
Source§impl ContentRecommender
impl ContentRecommender
Sourcepub fn new(m: usize, ef_construction: usize, decay_factor: f64) -> Self
pub fn new(m: usize, ef_construction: usize, decay_factor: f64) -> Self
Create a new content-based recommender.
§Arguments
m- HNSW connections per node (12-48 recommended)ef_construction- HNSW construction parameter (100-200 recommended)decay_factor- IDF decay factor (0.9-0.99 recommended)
§Examples
use aprender::recommend::ContentRecommender;
let rec = ContentRecommender::new(16, 200, 0.95);Sourcepub fn add_item(
&mut self,
item_id: impl Into<String>,
content: impl Into<String>,
)
pub fn add_item( &mut self, item_id: impl Into<String>, content: impl Into<String>, )
Add an item to the recommender.
§Arguments
item_id- Unique identifier for the itemcontent- Text content to extract features from
§Examples
use aprender::recommend::ContentRecommender;
let mut rec = ContentRecommender::new(16, 200, 0.95);
rec.add_item("item1", "machine learning tutorial");
rec.add_item("item2", "deep learning guide");Sourcepub fn recommend(
&self,
item_id: &str,
k: usize,
) -> Result<Vec<(String, f64)>, AprenderError>
pub fn recommend( &self, item_id: &str, k: usize, ) -> Result<Vec<(String, f64)>, AprenderError>
Recommend similar items.
§Arguments
item_id- Item to find similar items fork- Number of recommendations to return
§Returns
List of (item_id, similarity_score) pairs, sorted by similarity (highest first)
§Examples
use aprender::recommend::ContentRecommender;
let mut rec = ContentRecommender::new(16, 200, 0.95);
rec.add_item("a", "machine learning");
rec.add_item("b", "deep learning");
rec.add_item("c", "machine intelligence");
let similar = rec.recommend("a", 2).expect("recommend should succeed");
assert_eq!(similar.len(), 2);Trait Implementations§
Auto Trait Implementations§
impl Freeze for ContentRecommender
impl !RefUnwindSafe for ContentRecommender
impl !Send for ContentRecommender
impl !Sync for ContentRecommender
impl Unpin for ContentRecommender
impl UnsafeUnpin for ContentRecommender
impl !UnwindSafe for ContentRecommender
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
Mutably borrows from an owned value. Read more
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>
Converts
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>
Converts
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