The BGE-M3 model produces dense, sparse, and ColBERT embeddings in a single forward pass. Use Bgem3Embedding and Bgem3InitOptions.
Note: The default quantized model (BGEM3Q) is optimized for CPUs. For GPU inference, you must load a custom exported model (FP32, FP16, or INT8) via try_new_from_path.
use fastembed::{Bgem3Embedding, Bgem3InitOptions, Bgem3Model};
let mut model = Bgem3Embedding::try_new(
Bgem3InitOptions::new(Bgem3Model::BGEM3Q)
.with_max_length(1024)
.with_show_download_progress(true),
)?;
let documents = vec![
"Hello, World!",
"This is an example passage.",
"fastembed-rs is licensed under Apache 2.0",
"i dont know"
];
let output = model.embed(documents, None)?;
println!("Dense dimension: {}", output.dense[0].len());
println!("Sparse non-zero tokens: {}", output.sparse[0].indices.len());
println!("ColBERT token count: {}", output.colbert[0].len());