Trait kalosm_language_model::Embedder
source · pub trait Embedder: Send + Sync + 'static {
type VectorSpace: VectorSpace + Send + Sync + 'static;
// Required method
fn embed<'life0, 'life1, 'async_trait>(
&'life0 self,
input: &'life1 str
) -> Pin<Box<dyn Future<Output = Result<Embedding<Self::VectorSpace>>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
// Provided methods
fn embed_batch<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
inputs: &'life1 [&'life2 str]
) -> Pin<Box<dyn Future<Output = Result<Vec<Embedding<Self::VectorSpace>>>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait { ... }
fn into_any_embedder(self) -> DynEmbedder
where Self: Sized { ... }
}
Expand description
A model that can be used to embed text. This trait is generic over the vector space that the model uses to help keep track of what embeddings came from which model.
§Example
use kalosm_language_model::Embedder;
use rbert::*;
#[tokio::main]
async fn main() {
// Bert implements Embedder
let mut bert = Bert::builder().build().unwrap();
let sentences = vec![
"Cats are cool",
"The geopolitical situation is dire",
"Pets are great",
"Napoleon was a tyrant",
"Napoleon was a great general",
];
// Embed a batch of documents into the bert vector space
let embeddings = bert.embed_batch(&sentences).await.unwrap();
println!("embeddings {:?}", embeddings);
}
Required Associated Types§
sourcetype VectorSpace: VectorSpace + Send + Sync + 'static
type VectorSpace: VectorSpace + Send + Sync + 'static
The vector space that this embedder uses.
Required Methods§
Provided Methods§
sourcefn embed_batch<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
inputs: &'life1 [&'life2 str]
) -> Pin<Box<dyn Future<Output = Result<Vec<Embedding<Self::VectorSpace>>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn embed_batch<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
inputs: &'life1 [&'life2 str]
) -> Pin<Box<dyn Future<Output = Result<Vec<Embedding<Self::VectorSpace>>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Embed a batch of strings.
sourcefn into_any_embedder(self) -> DynEmbedderwhere
Self: Sized,
fn into_any_embedder(self) -> DynEmbedderwhere
Self: Sized,
Convert this embedder into an embedder trait object.