relevancy

Struct RelevancyStore

source
pub struct RelevancyStore { /* private fields */ }

Implementations§

source§

impl RelevancyStore

Top-level API for the Relevancy component

source

pub fn new(db_path: String) -> Self

Construct a new RelevancyStore

This is non-blocking since databases and other resources are lazily opened.

source

pub fn close(&self)

Close any open resources (for example databases)

Calling close will interrupt any in-progress queries on other threads.

source

pub fn interrupt(&self)

Interrupt any current database queries

source

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.

source

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.

source

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.

source

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.

source

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.

source

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.

source

pub fn get_bandit_data( &self, bandit: String, arm: String, ) -> ApiResult<BanditData>

Retrieves the data for a specific bandit and arm.

source§

impl RelevancyStore

source

pub fn ensure_interest_data_populated(&self) -> ApiResult<()>

Download the interest data from remote settings if needed

source

pub fn classify( &self, top_urls_by_frecency: Vec<String>, ) -> Result<InterestVector>

Trait Implementations§

source§

impl<UT> LiftRef<UT> for RelevancyStore

source§

impl<UT> LowerError<UT> for RelevancyStore

source§

fn lower_error(obj: Self) -> RustBuffer

Lower this value for scaffolding function return Read more
source§

impl<UT> LowerReturn<UT> for RelevancyStore

source§

type ReturnType = <Arc<RelevancyStore> as LowerReturn<UniFfiTag>>::ReturnType

The type that should be returned by scaffolding functions for this type. Read more
source§

fn lower_return(obj: Self) -> Result<Self::ReturnType, RustCallError>

Lower the return value from an scaffolding call Read more
§

fn handle_failed_lift( error: LiftArgsError, ) -> Result<Self::ReturnType, RustCallError>

Lower the return value for failed argument lifts Read more
source§

impl<UT> TypeId<UT> for RelevancyStore

source§

const TYPE_ID_META: MetadataBuffer = _

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T, UT> HandleAlloc<UT> for T
where T: Send + Sync,

§

fn new_handle(value: Arc<T>) -> Handle

Create a new handle for an Arc value Read more
§

unsafe fn clone_handle(handle: Handle) -> Handle

Clone a handle Read more
§

unsafe fn consume_handle(handle: Handle) -> Arc<T>

Consume a handle, getting back the initial Arc<> Read more
§

unsafe fn get_arc(handle: Handle) -> Arc<Self>

Get a clone of the Arc<> using a “borrowed” handle. Read more
source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> Same for T

source§

type Output = T

Should always be Self
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

source§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> ErasedDestructor for T
where T: 'static,

§

impl<T> MaybeSendSync for T