pub struct Scorer<K, D = u32> { /* private fields */ }Expand description
Efficiently scores the relevance of a query embedding to document embeddings using BM25. K is the type of the document id and D is the type of the token embedder.
Implementations§
Source§impl<K, D> Scorer<K, D>
impl<K, D> Scorer<K, D>
Sourcepub fn upsert(&mut self, document_id: &K, embedding: Embedding<D>)
pub fn upsert(&mut self, document_id: &K, embedding: Embedding<D>)
Upserts a document embedding into the scorer. If an embedding with the same id already
exists, it will be replaced. Note that upserting a document will change the true value of
avgdl. The more avgdl drifts from its true value, the less accurate the BM25 scores
will be.
Sourcepub fn remove(&mut self, document_id: &K)
pub fn remove(&mut self, document_id: &K)
Removes a document embedding from the scorer if it exists.
Sourcepub fn score(
&self,
document_id: &K,
query_embedding: &Embedding<D>,
) -> Option<f32>
pub fn score( &self, document_id: &K, query_embedding: &Embedding<D>, ) -> Option<f32>
Scores the embedding for the given document against a given query embedding. Returns None
if the document does not exist in the scorer.
Sourcepub fn matches(&self, query_embedding: &Embedding<D>) -> Vec<ScoredDocument<K>>
pub fn matches(&self, query_embedding: &Embedding<D>) -> Vec<ScoredDocument<K>>
Returns all documents relevant (i.e., score > 0) to the given query embedding, sorted by relevance.
Trait Implementations§
Auto Trait Implementations§
impl<K, D> Freeze for Scorer<K, D>
impl<K, D> RefUnwindSafe for Scorer<K, D>where
K: RefUnwindSafe,
D: RefUnwindSafe,
impl<K, D> Send for Scorer<K, D>
impl<K, D> Sync for Scorer<K, D>
impl<K, D> Unpin for Scorer<K, D>
impl<K, D> UnwindSafe for Scorer<K, D>where
K: UnwindSafe,
D: UnwindSafe,
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