Show HN: Model2vec-Rs – Fast Static Text Embeddings in Rust
Published on: 2025-07-04 07:01:35
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.
Quick Start
Add the crate:
cargo add model2vec-rs
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- 8 M # Multiple lines from a file echo -e "Hello world
Rust is
... Read full article.