rust-sbert

Library Listed

Rust implementation of Sentence Bert (SBert)

Checked · Sources

Downloads
10
Dependents
0
Stars
127
Forks
12
Contributors
5
Commits
72
Latest release
0.4.1 ·

About

From the project README ·

Rust port of sentence-transformers using rust-bert and tch-rs.

The model pipeline is driven by a checkpoint's modules.json manifest: the library reads it, picks the transformer backend from <0_*/config.json>'s model_type, and composes the post-transformer modules (Pooling, optional Dense, optional Normalize) in declared order. Adding a new transformer backbone (RoBERTa, MPNet, …) is one trait impl + one match arm in the factory.

Supports both rust-tokenizers and Hugging Face's tokenizers.

Supported models

Any sentence-transformers checkpoint whose modules.json references one of the implemented backends and module types loads out of the box:

  • Transformer backends: bert (e.g. all-MiniLM-L6-v2, paraphrase-MiniLM-L6-v2, bert-base-nli-mean-tokens), distilbert (e.g. distiluse-base-multilingual-cased).
  • Post-transformer modules: Pooling (mean), Dense (linear+tanh, optional), Normalize (L2, optional).
  • DistilRoBERTa-based sequence classifiers (unchanged from prior releases — see src/models/distilroberta.rs).
Read the full README

For distiluse-base-multilingual-cased the supported languages are: Arabic, Chinese, Dutch, English, French, German, Italian, Korean, Polish, Portuguese, Russian, Spanish, Turkish. Performance on the extended STS2017: 80.1.

Usage

Example

The API is made to be very easy to use and enables you to create quality multilingual sentence embeddings in a straightforward way.

Load a model by pointing at its directory (must contain modules.json and the subdirectories/paths it references):

let mut home: PathBuf = env::current_dir().unwrap();
home.push("path-to-model");

You can use different versions of the models that use different tokenizers:

// To use Hugging Face tokenizer
let sbert_model = SBertHF::new(home, None).unwrap();

// To use Rust-tokenizers
let sbert_model = SBertRT::new(home, None).unwrap();

SBert<T> is a backward-compat alias for the underlying SentenceTransformer<T> struct — both names refer to the same type, so existing call sites keep working unchanged.

Now, you can encode your sentences:

let texts = vec![
    "You can encode".to_string(),
    "As many sentences".to_string(),
    "As you want".to_string(),
    "Enjoy ;)".to_string(),
];

let batch_size = 64;

let output = sbert_model.forward(&texts, batch_size).unwrap();

The parameter batch_size can be left to None to let the model use its default value.

Then you can use the output sentence embedding in any application you want.

Loading a bert-backbone checkpoint (e.g. all-MiniLM-L6-v2)

rust-bert publishes pre-converted rust_model.ot weights for a handful of well-known checkpoints (those its own sentence-embeddings pipeline lists — all-MiniLM-L6-v2 is one of them), so no Python toolchain is needed for those. For anything else you must convert the weights yourself (see the next section); note that hub checkpoints shipping 2_Dense/model.safetensors are not covered by utils/prepare_models.py either. The HF modules.json for all-MiniLM-L6-v2 declares the Transformer at path: "" (files at the model root):

mkdir -p models/all-MiniLM-L6-v2/1_Pooling
HF=https://huggingface.co/sentence-transformers/all-MiniLM-L6-v2/resolve/main

curl -L -o models/all-MiniLM-L6-v2/model.ot                $HF/rust_model.ot
curl -L -o models/all-MiniLM-L6-v2/config.json             $HF/config.json
curl -L -o models/all-MiniLM-L6-v2/vocab.txt               $HF/vocab.txt
curl -L -o models/all-MiniLM-L6-v2/tokenizer_config.json   $HF/tokenizer_config.json
curl -L -o models/all-MiniLM-L6-v2/sentence_bert_config.json $HF/sentence_bert_config.json
curl -L -o models/all-MiniLM-L6-v2/special_tokens_map.json $HF/special_tokens_map.json
curl -L -o models/all-MiniLM-L6-v2/1_Pooling/config.json   $HF/1_Pooling/config.json
curl -L -o models/all-MiniLM-L6-v2/modules.json            $HF/modules.json

Then load as usual: SBertRT::new("models/all-MiniLM-L6-v2", None).

Convert distilbert models from Python to Rust

For checkpoints that don't ship a pre-converted .ot (e.g. the original distiluse-base-multilingual-cased export), convert the PyTorch weights manually.

Firstly, get a model provided by UKPLabs (all models are here):

mkdir -p models/distiluse-base-multilingual-cased

wget -P models https://public.ukp.informatik.tu-darmstadt.de/reimers/sentence-transformers/v0.2/distiluse-base-multilingual-cased.zip

unzip models/distiluse-base-multilingual-cased.zip -d models/distiluse-base-multilingual-cased

Then, you need to convert the model in a suitable format (requires pytorch):

python utils/prepare_distilbert.py models/distiluse-base-multilingual-cased

A dockerized environment is also available for running the conversion script:

docker build -t tch-converter -f utils/Dockerfile .

docker run \
  -v $(pwd)/models/distiluse-base-multilingual-cased:/model \
  tch-converter:latest \
  python prepare_distilbert.py /model

Finally, set "output_attentions": true in distiluse-base-multilingual-cased/0_distilbert/config.json.

Pipeline architecture

SentenceTransformer<T> holds:

  • transformer: Box<dyn TransformerBackend> — dispatches on config.json's model_type field. Implemented: DistilBertBackend, BertBackend.
  • post: Vec<Box<dyn Module>> — built from modules.json in declared order. The forward pass threads a Features enum (Token { .. } → Sentence { .. }) through each module; Pooling does the token→sentence reduction.

To extend:

  • New backbone (e.g. RoBERTa): add a RobertaBackend struct + impl TransformerBackend for it + add a match arm in modules::transformer::load. Note this alone is not enough: tokenization is hard-coded to vocab.txt + WordPiece in SentenceTransformer::new, so a backbone with a different tokenizer (RoBERTa's SentencePiece/BPE) also needs a new tokenizers::Tokenizer implementation and corresponding tokenizer-file resolution.
  • New post-transformer module (e.g. WeightedLayerPooling): add a module struct + impl Module for it + add a match arm on short_type in SentenceTransformer::new.

See src/modules/ for the building blocks.

Runs on
CUDA
What shows it
  • CUDA: sbert dependency tch
Native code
Required
  • Binds native code: torch-sys
Python bindings
No Python binding crate found
License
Apache-2.0

Compare with similar projects

Order: strongest tier first, then most downloads, then name, with unmeasured values last. A library counts downloads over 30 days. An app counts binary downloads per release. An app with none counts its crate downloads over 30 days. ML Rust runs this catalogue, so its closest project always gets a row.

rust-sbert beside the projects that share a topic with it
ProjectDownloadsDependentsStarsLatest releaseRuns on (GPU)Native codeLicense
rust-sbert This page Listed

Rust implementation of Sentence Bert (SBert)

10 downloads over 30 days 0 127 0.4.1 CUDA Binds native code: torch-sys Apache-2.0
fastembed-rs Featured

Library for generating vector embeddings, reranking locally.

1,147,765 downloads over 30 days 331 1,051 7.6.1 CUDA, WebGPU, Metal Binds native code: accelerate-src (feature accelerate), intel-mkl-src (feature mkl), ort-sys (feature directml) Apache-2.0
model2vec-rs Featured

Official Rust Implementation of Model2Vec

194,422 downloads over 30 days 48 234 0.4.0 GPU support unknown No native code found MIT

fastText pure Rust implementation

102,405 downloads over 30 days 4 71 0.8.1 GPU support unknown Binds native code: cfasttext-sys, cfasttext_static. Build uses a native toolchain: cc MIT
splintr Listed

Tokenizer for Rust and Python: pure Rust by default, with 18 bundled vocabularies and four backends covering BPE, SentencePiece and WordPiece. Its output matches Hugging Face tokenizers id for id on 14 model families, including GPT-2, Qwen, Whisper, T5 and BERT.

Python bindings

8,204 downloads over 30 days 7 63 0.22.2 GPU support unknown Binds native code: pcre2-sys (feature pcre2) MIT
word2vec Listed Dormant

Rust interface to word2vec.

59 downloads over 30 days 1 32 0.3.3 GPU support unknown No native code found MIT
word2vec-rs App Listed Dormant

pure rust implemention of word2vec

Not measured Not applicable 87 Not measured Not measured Not measured None stated
Why ListedNo archive, New or Featured rule places it, so it is Listed.

What it lacks for Featured

  • It has 0 active dependents and 0 new dependents in 365 days. Featured needs 11 active dependents or 9 new dependents in 365 days. The repository route reads 127 stars, 12 forks and 5 contributors. It needs 4,539 stars, 434 forks and 79 contributors together.

What else the check found

  • The last activity is on 7 Oct 2026, 33 days ago. The rules expect an update within 365 days. Dormancy rule

Exact rules: Listed, Featured library. The check on applied thresholds version 9.

Every rule outcome, as the check records it
  • expected-interval: version 0.4.1 base 300, raised to the 365-day floor: E = 365 days
  • dormancy: last activity 2026-10-07, 33 days ago, E = 365: active
  • featured: not featured: active_users 0 < 11 and new_adopters 0 < 9 and repository route stars 127 (needs 4539), forks 12 (needs 434), contributors 5 (needs 79)
  • listed: listed: no archive, new or featured rule applies

Measurements and sources

Each signal row shows the raw value, its source and the fetch date. The Sources list gathers every distinct source on this page. Movement needs more history.

Sources6 sources
Adoption0 active dependents, 0 new dependents in 365 days1 not measured
Adoption measurements
SignalValueSourceFetchedCounts
Active dependents0crates.io database dumpYes
New dependents (365 days)0crates.io database dumpYes
Peak active dependents0crates.io database dumpYes
Active dependents as a share of the peak1crates.io database dumpYes
Binary downloads per releaseNot measuredYes
MaintenanceLatest human commit: 33 days ago3 not measured
Maintenance measurements
SignalValueSourceFetchedCounts
Latest human commit2026-10-07GitHub repositoryYes
Latest release2023-09-23crates.io database dumpYes
First release2020-05-18crates.io database dumpYes
Latest version0.4.1crates.io database dumpYes
Days the oldest outside issue waits for a reply33GitHub repositoryYes
Maintainer replies over 365 days4GitHub repositoryYes
Repository archivedfalseGitHub repositoryYes
Repository gonefalseGitHub repositoryYes
Release commit or manifest in the repotruecrates.io packageYes
Published docstruecrates.io database dumpYes
Latest release fails cargo checkNot measuredYes
Build check dateNot measuredYes
Build check toolchainNot measuredYes
SecurityUnpatched vulnerabilities: none
Security measurements
SignalValueSourceFetchedCounts
Unpatched vulnerabilities past the grace windownoneRustSec advisory databaseYes
RustSec unmaintained advisorynoneRustSec advisory databaseYes
Deprecation noticenonecrates.io database dumpYes
Deprecated requirementnonecrates.io database dumpYes
Distribution7 releases, 10 downloads over 30 days5 not measured
Distribution measurements
SignalValueSourceFetchedCounts
Releases7crates.io database dumpYes
Downloads over 30 days10crates.io database dumpYes
Binary downloads over the last 3 releasesNot measuredYes
Homebrew installs on request over 365 daysNot measuredYes
Repology repository familiesNot measuredYes
Docker pull growth over 90 daysNot measuredYes
Docker pulls at the growth baselineNot measuredYes
Every version a prereleasefalsecrates.io database dumpYes
Every version 0.0.xfalsecrates.io database dumpYes
Every version yankedfalsecrates.io database dumpYes
Crate deleted from crates.iofalsecrates.io database dumpYes
Repository127 stars, 12 forks, 5 contributors, 72 commits. Stars alone never qualify a project.
Repository measurements
SignalValueSourceFetchedCounts
GitHub stars127GitHub repositoryYes — one part of the repository route
GitHub forks12GitHub repositoryYes — one part of the repository route
Contributors with a GitHub account5GitHub contributorsYes — one part of the repository route
Commits on the default branch72GitHub repositoryNo
Repository's main crate left out of the entrynonecrates.io database dumpYes
Facts that never count
Facts that never count measurements
SignalValueSourceFetchedCounts
LicenseApache-2.0crates.io database dumpNo
Runs on, from listed crates and their direct dependenciesCUDAcrates.io database dumpNo
What shows each backendCUDA: sbert dependency tchcrates.io database dumpNo
Native code, from listed crates and their dependenciesBinds native code: torch-syscrates.io database dumpNo
Python bindings, from direct dependencies of listed cratesNo Python binding crate foundcrates.io database dumpNo
Crates that depend on a listed crate directly0crates.io database dumpNo

Corrections and review history

Report a correction

No correction applies to this entry.

Judgments

A judgment enters only through an approved issue and a merged pull request.

No judgment applies to this entry.