Crates.io | fastembed |
lib.rs | fastembed |
version | 4.3.0 |
source | src |
created_at | 2023-09-19 12:41:46.995685 |
updated_at | 2024-11-27 03:24:15.440365 |
description | Rust implementation of https://github.com/qdrant/fastembed |
homepage | https://crates.io/crates/fastembed |
repository | https://github.com/Anush008/fastembed-rs |
max_upload_size | |
id | 976821 |
size | 656,062 |
The default model is Flag Embedding, which is top of the MTEB leaderboard.
Run the following command in your project directory:
cargo add fastembed
Or add the following line to your Cargo.toml:
[dependencies]
fastembed = "3"
use fastembed::{TextEmbedding, InitOptions, EmbeddingModel};
// With default InitOptions
let model = TextEmbedding::try_new(Default::default())?;
// With custom InitOptions
let model = TextEmbedding::try_new(
InitOptions::new(EmbeddingModel::AllMiniLML6V2).with_show_download_progress(true),
)?;
let documents = vec![
"passage: Hello, World!",
"query: Hello, World!",
"passage: This is an example passage.",
// You can leave out the prefix but it's recommended
"fastembed-rs is licensed under Apache 2.0"
];
// Generate embeddings with the default batch size, 256
let embeddings = model.embed(documents, None)?;
println!("Embeddings length: {}", embeddings.len()); // -> Embeddings length: 4
println!("Embedding dimension: {}", embeddings[0].len()); // -> Embedding dimension: 384
use fastembed::{ImageEmbedding, ImageInitOptions, ImageEmbeddingModel};
// With default InitOptions
let model = ImageEmbedding::try_new(Default::default())?;
// With custom InitOptions
let model = ImageEmbedding::try_new(
ImageInitOptions::new(ImageEmbeddingModel::ClipVitB32).with_show_download_progress(true),
)?;
let images = vec!["assets/image_0.png", "assets/image_1.png"];
// Generate embeddings with the default batch size, 256
let embeddings = model.embed(images, None)?;
println!("Embeddings length: {}", embeddings.len()); // -> Embeddings length: 2
println!("Embedding dimension: {}", embeddings[0].len()); // -> Embedding dimension: 512
use fastembed::{TextRerank, RerankInitOptions, RerankerModel};
let model = TextRerank::try_new(
RerankInitOptions::new(RerankerModel::BGERerankerBase).with_show_download_progress(true),
)?;
let documents = vec![
"hi",
"The giant panda (Ailuropoda melanoleuca), sometimes called a panda bear, is a bear species endemic to China.",
"panda is animal",
"i dont know",
"kind of mammal",
];
// Rerank with the default batch size
let results = model.rerank("what is panda?", documents, true, None)?;
println!("Rerank result: {:?}", results);
Alternatively, local model files can be used for inference via the try_new_from_user_defined(...)
methods of respective structs.
To support the library, please consider donating to our primary upstream dependency, ort
- The Rust wrapper for the ONNX runtime.
It's important we justify the "fast" in FastEmbed. FastEmbed is fast because of:
Apache 2.0 © 2024