pub struct RelevancyStore { /* private fields */ }
Implementations§
source§impl RelevancyStore
impl RelevancyStore
Top-level API for the Relevancy component
sourcepub fn new(db_path: String) -> Self
pub fn new(db_path: String) -> Self
Construct a new RelevancyStore
This is non-blocking since databases and other resources are lazily opened.
sourcepub fn close(&self)
pub fn close(&self)
Close any open resources (for example databases)
Calling close
will interrupt any in-progress queries on other threads.
sourcepub fn ingest(
&self,
top_urls_by_frecency: Vec<String>,
) -> ApiResult<InterestVector>
pub fn ingest( &self, top_urls_by_frecency: Vec<String>, ) -> ApiResult<InterestVector>
Ingest top URLs to build the user’s interest vector.
Consumer should pass a list of the user’s top URLs by frecency to this method. It will then:
- Download the URL interest data from remote settings. Eventually this should be cached / stored in the database, but for now it would be fine to download fresh data each time.
- Match the user’s top URls against the interest data to build up their interest vector.
- Store the user’s interest vector in the database.
This method may execute for a long time and should only be called from a worker thread.
sourcepub fn calculate_metrics(&self) -> ApiResult<InterestMetrics>
pub fn calculate_metrics(&self) -> ApiResult<InterestMetrics>
Calculate metrics for the validation phase
This runs after Self::ingest. It takes the interest vector that ingest created and calculates a set of metrics that we can report to glean.
sourcepub fn user_interest_vector(&self) -> ApiResult<InterestVector>
pub fn user_interest_vector(&self) -> ApiResult<InterestVector>
Get the user’s interest vector directly.
This runs after Self::ingest. It returns the interest vector directly so that the
consumer can show it in an about:
page.
sourcepub fn bandit_init(&self, bandit: String, arms: &[String]) -> ApiResult<()>
pub fn bandit_init(&self, bandit: String, arms: &[String]) -> ApiResult<()>
Initializes probability distributions for any uninitialized items (arms) within a bandit model.
This method takes a bandit
identifier and a list of arms
(items) and ensures that each arm
in the list has an initialized probability distribution in the database. For each arm, if the
probability distribution does not already exist, it will be created, using Beta(1,1) as default,
which represents uniform distribution.
sourcepub fn bandit_select(
&self,
bandit: String,
arms: &[String],
) -> ApiResult<String>
pub fn bandit_select( &self, bandit: String, arms: &[String], ) -> ApiResult<String>
Selects the optimal item (arm) to display to the user based on a multi-armed bandit model.
This method takes in a bandit
identifier and a list of possible arms
(items) and uses a
Thompson sampling approach to select the arm with the highest probability of success.
For each arm, it retrieves the Beta distribution parameters (alpha and beta) from the
database, creates a Beta distribution, and samples from it to estimate the arm’s probability
of success. The arm with the highest sampled probability is selected and returned.
sourcepub fn bandit_update(
&self,
bandit: String,
arm: String,
selected: bool,
) -> ApiResult<()>
pub fn bandit_update( &self, bandit: String, arm: String, selected: bool, ) -> ApiResult<()>
Updates the bandit model’s arm data based on user interaction (selection or non-selection).
This method takes in a bandit
identifier, an arm
identifier, and a selected
flag.
If selected
is true, it updates the model to reflect a successful selection of the arm,
reinforcing its positive reward probability. If selected
is false, it updates the
beta (failure) distribution of the arm, reflecting a lack of selection and reinforcing
its likelihood of a negative outcome.
sourcepub fn get_bandit_data(
&self,
bandit: String,
arm: String,
) -> ApiResult<BanditData>
pub fn get_bandit_data( &self, bandit: String, arm: String, ) -> ApiResult<BanditData>
Retrieves the data for a specific bandit and arm.
source§impl RelevancyStore
impl RelevancyStore
sourcepub fn ensure_interest_data_populated(&self) -> ApiResult<()>
pub fn ensure_interest_data_populated(&self) -> ApiResult<()>
Download the interest data from remote settings if needed
pub fn classify( &self, top_urls_by_frecency: Vec<String>, ) -> Result<InterestVector>
Trait Implementations§
source§impl<UT> LiftRef<UT> for RelevancyStore
impl<UT> LiftRef<UT> for RelevancyStore
type LiftType = Arc<RelevancyStore>
source§impl<UT> LowerError<UT> for RelevancyStore
impl<UT> LowerError<UT> for RelevancyStore
source§fn lower_error(obj: Self) -> RustBuffer
fn lower_error(obj: Self) -> RustBuffer
source§impl<UT> LowerReturn<UT> for RelevancyStore
impl<UT> LowerReturn<UT> for RelevancyStore
source§type ReturnType = <Arc<RelevancyStore> as LowerReturn<UniFfiTag>>::ReturnType
type ReturnType = <Arc<RelevancyStore> as LowerReturn<UniFfiTag>>::ReturnType
source§fn lower_return(obj: Self) -> Result<Self::ReturnType, RustCallError>
fn lower_return(obj: Self) -> Result<Self::ReturnType, RustCallError>
§fn handle_failed_lift(
error: LiftArgsError,
) -> Result<Self::ReturnType, RustCallError>
fn handle_failed_lift( error: LiftArgsError, ) -> Result<Self::ReturnType, RustCallError>
source§impl<UT> TypeId<UT> for RelevancyStore
impl<UT> TypeId<UT> for RelevancyStore
const TYPE_ID_META: MetadataBuffer = _
Auto Trait Implementations§
impl !Freeze for RelevancyStore
impl !RefUnwindSafe for RelevancyStore
impl Send for RelevancyStore
impl Sync for RelevancyStore
impl Unpin for RelevancyStore
impl !UnwindSafe for RelevancyStore
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
§impl<T, UT> HandleAlloc<UT> for T
impl<T, UT> HandleAlloc<UT> for T
§fn new_handle(value: Arc<T>) -> Handle
fn new_handle(value: Arc<T>) -> Handle
§unsafe fn clone_handle(handle: Handle) -> Handle
unsafe fn clone_handle(handle: Handle) -> Handle
§unsafe fn consume_handle(handle: Handle) -> Arc<T>
unsafe fn consume_handle(handle: Handle) -> Arc<T>
Arc<>
Read more