2025-05-18 11:01:00
github.com

This crate provides a lightweight Rust implementation for loading and inference of Model2Vec static embedding models. For distillation and training, the Python Model2Vec package can be used.
Add the crate:
Make embeddings:
use anyhow::Result;
use model2vec_rs::model::StaticModel;
fn main() -> Result()> {
// Load a model from the Hugging Face Hub or a local path
// args = (repo_or_path, token, normalize, subfolder)
let model = StaticModel::from_pretrained("minishlab/potion-base-8M", None, None, None)?;
// Prepare a list of sentences
let sentences = vec![
"Hello world".to_string(),
"Rust is awesome".to_string(),
];
// Create embeddings
let embeddings = model.encode(&sentences);
println!("Embeddings: {:?}", embeddings);
Ok(())
}
Make embeddings with the CLI:
# Single sentence
cargo run -- encode "Hello world" minishlab/potion-base-8M
# Multiple lines from a file
echo -e "Hello world\nRust is awesome" > input.txt
cargo run -- encode input.txt minishlab/potion-base-8M --output embeds.json
Make embeddings with custom encode args:
let embeddings = model.encode_with_args(
&sentences, // input texts
Some(512), // max length
1024, // batch size
);
We provide a number of models that can be used out of the box. These models are available on the HuggingFace hub and can be loaded using the from_pretrained
method. The models are listed below.
We compared the performance of the Rust implementation with the Python version of Model2Vec. The benchmark was run single-threaded on a CPU.
Implementation | Throughput |
---|---|
Rust | 8000 samples/second |
Python | 4650 samples/second |
The Rust version is roughly 1.7× faster than the Python version.
MIT
Keep your files stored safely and securely with the SanDisk 2TB Extreme Portable SSD. With over 69,505 ratings and an impressive 4.6 out of 5 stars, this product has been purchased over 8K+ times in the past month. At only $129.99, this Amazon’s Choice product is a must-have for secure file storage.
Help keep private content private with the included password protection featuring 256-bit AES hardware encryption. Order now for just $129.99 on Amazon!
Help Power Techcratic’s Future – Scan To Support
If Techcratic’s content and insights have helped you, consider giving back by supporting the platform with crypto. Every contribution makes a difference, whether it’s for high-quality content, server maintenance, or future updates. Techcratic is constantly evolving, and your support helps drive that progress.
As a solo operator who wears all the hats, creating content, managing the tech, and running the site, your support allows me to stay focused on delivering valuable resources. Your support keeps everything running smoothly and enables me to continue creating the content you love. I’m deeply grateful for your support, it truly means the world to me! Thank you!
BITCOIN bc1qlszw7elx2qahjwvaryh0tkgg8y68enw30gpvge Scan the QR code with your crypto wallet app |
DOGECOIN D64GwvvYQxFXYyan3oQCrmWfidf6T3JpBA Scan the QR code with your crypto wallet app |
ETHEREUM 0xe9BC980DF3d985730dA827996B43E4A62CCBAA7a Scan the QR code with your crypto wallet app |
Please read the Privacy and Security Disclaimer on how Techcratic handles your support.
Disclaimer: As an Amazon Associate, Techcratic may earn from qualifying purchases.