File size: 1,028 Bytes
84d2a97
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
use common::types::ScoreType;

use crate::common::operation_error::{OperationError, OperationResult};
use crate::data_types::vectors::DenseVector;

mod context_query;
mod discovery_query;
mod reco_query;

pub use context_query::{ContextPair, ContextQuery};
pub use discovery_query::DiscoveryQuery;
pub use reco_query::RecoQuery;

pub trait TransformInto<Output, T = DenseVector, U = DenseVector> {
    /// Change the underlying type of the query, or just process it in some way.
    fn transform<F>(self, f: F) -> OperationResult<Output>
    where
        F: FnMut(T) -> OperationResult<U>;

    fn transform_into(self) -> OperationResult<Output>
    where
        Self: Sized,
        T: TryInto<U, Error = OperationError>,
    {
        self.transform(|v| v.try_into())
    }
}

pub trait Query<T> {
    /// Compares the vectors of the query against a single vector via a similarity function,
    /// then folds the similarites into a single score.
    fn score_by(&self, similarity: impl Fn(&T) -> ScoreType) -> ScoreType;
}