Rust library for generating vector embeddings, reranking. Re-write of qdrant/fastembed. https://docs.rs/fastembed
Find a file
2025-12-07 10:06:44 +01:00
.github Update workflows to use image-models 2025-12-07 09:48:30 +01:00
src Merge remote-tracking branch 'anush/main' 2025-12-07 10:06:44 +01:00
tests Merge remote-tracking branch 'anush/main' 2025-12-07 10:06:44 +01:00
.envrc feat: allow embedding image bytes, Nix environment (#150) 2025-02-28 15:05:30 +05:30
.gitignore feat: allow embedding image bytes, Nix environment (#150) 2025-02-28 15:05:30 +05:30
.releaserc chore: Miscellaneous Code Improvements (#191) 2025-10-31 12:50:55 +05:30
Cargo.toml Merge remote-tracking branch 'anush/main' 2025-12-07 10:06:44 +01:00
flake.lock feat: allow embedding image bytes, Nix environment (#150) 2025-02-28 15:05:30 +05:30
flake.nix feat: allow embedding image bytes, Nix environment (#150) 2025-02-28 15:05:30 +05:30
LICENSE docs: Update LICENSE (#11) 2023-12-23 06:28:07 +05:30
README.md docs: add missing models to README (#199) 2025-11-29 02:54:18 +05:30

FastEmbed-rs 🦀

Rust library for generating vector embeddings, reranking locally!

Crates.io MIT Licensed Semantic release

🍕 Features

🔍 Not looking for Rust?

🤖 Models

Text Embedding

Quantized versions are also available for several models above (append Q to the model enum variant, e.g., EmbeddingModel::BGESmallENV15Q).

Sparse Text Embedding

Image Embedding

Reranking

Support

To support the library, please donate to our primary upstream dependency, ort - The Rust wrapper for the ONNX runtime.

🚀 Installation

Run the following in your project directory:

cargo add fastembed

Or add the following line to your Cargo.toml:

[dependencies]
fastembed = "5"

📖 Usage

Text Embeddings

use fastembed::{TextEmbedding, InitOptions, EmbeddingModel};

// With default options
let mut model = TextEmbedding::try_new(Default::default())?;

// With custom options
let mut 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

Sparse Text Embeddings

use fastembed::{SparseEmbedding, SparseInitOptions, SparseModel, SparseTextEmbedding};

// With default options
let mut model = SparseTextEmbedding::try_new(Default::default())?;

// With custom options
let mut model = SparseTextEmbedding::try_new(
    SparseInitOptions::new(SparseModel::SPLADEPPV1).with_show_download_progress(true),
)?;

let documents = vec![
    "passage: Hello, World!",
    "query: Hello, World!",
    "passage: This is an example passage.",
    "fastembed-rs is licensed under Apache  2.0"
    ];

// Generate embeddings with the default batch size, 256
let embeddings: Vec<SparseEmbedding> = model.embed(documents, None)?;

Image Embeddings

use fastembed::{ImageEmbedding, ImageInitOptions, ImageEmbeddingModel};

// With default options
let mut model = ImageEmbedding::try_new(Default::default())?;

// With custom options
let mut 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

Candidates Reranking

use fastembed::{TextRerank, RerankInitOptions, RerankerModel};

// With default options
let mut model = TextRerank::try_new(Default::default())?;

// With custom options
let mut 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, 256 and return document contents
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.

📄 LICENSE

Apache 2.0