█

AI/TLDR

Buy me a coffee
Buy me a coffee

Model2Vec-RS

Fast static embedding inference in Rust for Model2Vec models

Embedding Models & InferenceOpen source
Language
Rust
License
MIT
$cargo add model2vec-rs
IN SHORT

What is Model2Vec-RS?

Model2Vec-RS is the official Rust implementation for running Model2Vec static embedding models. Model2Vec is a technique that turns sentence transformers into compact static embedding models, cutting model size and speeding up inference. It sits in the Embedding Models & Inference category of the Retrieval & Knowledge (RAG) tools and is open-source, written in Rust and licensed MIT.

Overview

Model2Vec-RS is the official Rust implementation for running Model2Vec static embedding models. Model2Vec is a technique that turns sentence transformers into compact static embedding models, cutting model size and speeding up inference. This crate handles the inference side, so you can generate embeddings from text with low latency.

It is aimed at Rust developers who need embeddings inside an application or pipeline without the overhead of a full transformer runtime. You can use it as a library in your own code or as a standalone command-line tool for quick terminal-based encoding.

As an embedding inference tool, it loads pre-trained Model2Vec models directly from the Hugging Face Hub or from a local path, supports f32, f16, and i8 weights stored in safetensors files, and offers feature flags for native, local-only, and WebAssembly builds.

What it does

  • Loads Model2Vec models from the Hugging Face Hub by model ID or from a local path via from_pretrained
  • Alternative loaders for embedded and WASM use: from_bytes, from_owned, and from_borrowed for in-memory data
  • Supports f32, f16, and i8 weight types stored in safetensors files
  • Batch encoding with configurable max sequence length and batch size
  • Ships both a Rust library and a standalone CLI (encode-single, encode)
  • Feature flags for native, fancy-regex, local-only, and wasm runtime configurations

Getting started

You can use Model2Vec-RS as a Rust library or as a standalone CLI tool. Both load models from the Hugging Face Hub or a local path.

Add the crate as a dependency

Add model2vec-rs to your Rust project with Cargo.

bashbash
cargo add model2vec-rs

Load a model and generate embeddings

Load a model from the Hugging Face Hub (or a local path) and encode a list of sentences. The result is a Vec<Vec<f32>>.

rustrust
use anyhow::Result;
use model2vec_rs::model::StaticModel;

fn main() -> Result<()> {
    // Arguments: (repo_or_path, hf_token, normalize_embeddings, subfolder_in_repo)
    let model = StaticModel::from_pretrained(
        "minishlab/potion-base-8M",
        None,
        None,
        None,
    )?;

    let sentences = vec![
        "Hello world".to_string(),
        "Rust is awesome".to_string(),
    ];

    let embeddings = model.encode(&sentences);
    println!("Generated {} embeddings.", embeddings.len());

    Ok(())
}

Or install and use the CLI

Install the executable in release mode, then encode a single sentence. Output is printed as JSON.

bashbash
cargo install model2vec-rs
model2vec-rs encode-single "Hello world" "minishlab/potion-base-8M"

Commands and code are distilled from the project's own documentation — always check the official repo for the latest.

When to use it

  • Generating text embeddings inside a Rust application or service with low latency
  • Quick terminal-based encoding of sentences or files via the CLI
  • Running static embeddings in embedded or WebAssembly environments using in-memory model loading
  • Batch-encoding documents for semantic search or retrieval indexing

How Model2Vec-RS compares

Model2Vec-RS alongside other open-source embedding models & inference tools AI/TLDR tracks, ranked by GitHub stars.

ToolStarsWhat it does
Sentence Transformers★ 19.3kThe standard Python framework for loading, training, and computing embeddings with sentence and reranking models.
OpenCLIP★ 14.3kAn open implementation of CLIP for training and running image-text embedding models, with a large catalogue of pretrained checkpoints for zero-shot classification and retrieval.
PyTorch Metric Learning★ 6.3kPyTorch library of losses, miners, distances, samplers, trainers and accuracy testers for training embedding models with deep metric and self-supervised learning.
EmbeddingGemma (Gemma)★ 5.9kGoogle DeepMind's Gemma repo, home to EmbeddingGemma, a 308M multilingual embedding model small enough to run on-device for RAG and semantic search.
Text Embeddings Inference (TEI)★ 5.1kHugging Face's Rust-based server for deploying embedding, reranking, and sequence-classification models with high throughput on GPU or CPU.
text2vec★ 5kPython library for sentence embeddings and text similarity, implementing Word2Vec, BM25, Sentence-BERT, CoSENT and BGE with Chinese and multilingual models.
Infinity (Embeddings)★ 3kA high-throughput serving engine for text embeddings, rerankers, CLIP, and ColPali models, exposing an OpenAI-compatible API.
Model2Vec-RS★ 241Fast static embedding inference in Rust for Model2Vec models