-
Notifications
You must be signed in to change notification settings - Fork 99
/
Copy pathembedding_fastembed.rs
38 lines (31 loc) · 1.13 KB
/
embedding_fastembed.rs
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
35
36
37
38
#[cfg(feature = "fastembed")]
use langchain_rust::embedding::{Embedder, EmbeddingModel, FastEmbed, InitOptions, TextEmbedding};
#[cfg(feature = "fastembed")]
#[tokio::main]
async fn main() {
// With default model
let fastembed = FastEmbed::try_new().unwrap();
let embeddings = fastembed
.embed_documents(&["hello world".to_string(), "foo bar".to_string()])
.await
.unwrap();
println!("Len: {}", embeddings.len());
println!("Embeddings: {:?}", embeddings);
// With custom model
let model = TextEmbedding::try_new(
InitOptions::new(EmbeddingModel::AllMiniLML6V2).with_show_download_progress(true),
)
.unwrap();
let fastembed = FastEmbed::from(model);
fastembed
.embed_documents(&["hello world".to_string(), "foo bar".to_string()])
.await
.unwrap();
println!("Len: {:?}", embeddings.len());
}
#[cfg(not(feature = "fastembed"))]
fn main() {
println!("This example requires the 'fastembed' feature to be enabled.");
println!("Please run the command as follows:");
println!("cargo run --example embedding_fastembed --features=fastembed");
}