Fast State-of-the-Art Static Embeddings in Rust
open sourceMITself-hostablefree
model2vec-rs is Minish's official Rust implementation of inference for Model2Vec static embedding models such as potion-base-8M and potion-retrieval-32M: it tokenizes text, looks up stored token vectors and averages them, with no neural network, so it embeds hundreds of thousands of texts per second on a CPU. It loads models from the Hugging Face Hub, a local path or in-memory bytes (for WebAssembly and embedded builds), keeps f32, f16 and int8 weights and can quantize to int8 at load time, and comes as a library, an opt-in CLI and Python bindings. Minish measured 575,000 texts a second on one thread and 2.6 million on all cores of an M3 Pro, 15 to 24 times faster than Python Model2Vec; distillation and training stay in the Python package.
Problems it solves
- embed text in a Rust program at hundreds of thousands of sentences per second on a CPU
- sentence embeddings in Rust without ONNX Runtime, libtorch or any C++ dependency
- compile my embedding model into the binary and load it from bytes at startup
- run text embeddings in WebAssembly
- a command-line tool that turns a file of sentences into embeddings as JSON
- embeddings in Rust that load in milliseconds, for a CLI that starts often
- embed huge text collections for deduplication or clustering without a GPU
- speed up Python Model2Vec inference with a native extension
- cut an embedding model's memory to a quarter with int8 quantization
- an offline-only build that can't download models from the internet
Features
- inference for Model2Vec static models: tokenize, look up, average
- loads from the Hugging Face Hub, local paths, or bytes (from_bytes) for WASM and embedded use
- f32, f16 and int8 weights; quantize_int8 at load time
- batch encoding with configurable max length and batch size; Rayon parallelism
- flat row-major output (encode_flat)
- opt-in CLI (cli feature): encode-single and encode a file to JSON
- Python bindings (model2vec_rs.StaticModel) that release the GIL
- local-only and wasm feature sets
- 575K texts/s single-threaded, 2.6M texts/s on all cores of an M3 Pro (Minish's benchmark)
Limitations
- Doesn't distill or train models: that's the Python model2vec package; model2vec-rs only runs inference1
Capabilities
| Has a command line tool | plan not known |
|---|---|
| Has official SDKs | plan not known |
Alternatives
The same job
These do what model2vec-rs does.
- fastembed-rs Rust library for generating vector embeddings, reranking locally
- candle Minimalist ML framework for Rust
- Model2Vec Fast state-of-the-art static embeddings, and lightweight classifiers trained on top of them