pub trait Embedder:
Send
+ Sync
+ 'static {
type Error: Send + Sync + 'static;
// Required method
fn embed_for(
&self,
input: EmbeddingInput,
) -> impl Future<Output = Result<Embedding, Self::Error>> + Send;
// Provided methods
fn embed_string(
&self,
input: String,
) -> impl Future<Output = Result<Embedding, Self::Error>> + Send { ... }
fn embed_vec(
&self,
inputs: Vec<String>,
) -> impl Future<Output = Result<Vec<Embedding>, Self::Error>> + Send { ... }
fn embed_vec_for(
&self,
inputs: Vec<EmbeddingInput>,
) -> impl Future<Output = Result<Vec<Embedding>, Self::Error>> + Send { ... }
}
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::*;
use kalosm_language_model::Embedder;
#[tokio::main]
async fn main() {
// Bert implements Embedder
let mut bert = Bert::new().await.unwrap();
let sentences = [
"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§
Required Methods§
Sourcefn embed_for(
&self,
input: EmbeddingInput,
) -> impl Future<Output = Result<Embedding, Self::Error>> + Send
fn embed_for( &self, input: EmbeddingInput, ) -> impl Future<Output = Result<Embedding, Self::Error>> + Send
Embed a EmbeddingInput
into a vector space
Provided Methods§
Sourcefn embed_string(
&self,
input: String,
) -> impl Future<Output = Result<Embedding, Self::Error>> + Send
fn embed_string( &self, input: String, ) -> impl Future<Output = Result<Embedding, Self::Error>> + Send
Embed some text into a vector space.
Sourcefn embed_vec(
&self,
inputs: Vec<String>,
) -> impl Future<Output = Result<Vec<Embedding>, Self::Error>> + Send
fn embed_vec( &self, inputs: Vec<String>, ) -> impl Future<Output = Result<Vec<Embedding>, Self::Error>> + Send
Embed a Vec<String>
into a vector space. Returns a list of embeddings in the same order as the inputs.
Sourcefn embed_vec_for(
&self,
inputs: Vec<EmbeddingInput>,
) -> impl Future<Output = Result<Vec<Embedding>, Self::Error>> + Send
fn embed_vec_for( &self, inputs: Vec<EmbeddingInput>, ) -> impl Future<Output = Result<Vec<Embedding>, Self::Error>> + Send
Embed a Vec<String>
into a vector space. Returns a list of embeddings in the same order as the inputs.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.