rust-sbert
Library Listed
Rust implementation of Sentence Bert (SBert)
- Downloads
- 10
- Dependents
- 0
- Stars
- 127
- Forks
- 12
- Contributors
- 5
- Commits
- 72
- Latest release
- 0.4.1 ·
About
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 onconfig.json'smodel_typefield. Implemented:DistilBertBackend,BertBackend.post: Vec<Box<dyn Module>>— built frommodules.jsonin declared order. The forward pass threads aFeaturesenum (Token { .. }→Sentence { .. }) through each module;Poolingdoes the token→sentence reduction.
To extend:
- New backbone (e.g. RoBERTa): add a
RobertaBackendstruct + implTransformerBackendfor it + add a match arm inmodules::transformer::load. Note this alone is not enough: tokenization is hard-coded tovocab.txt+ WordPiece inSentenceTransformer::new, so a backbone with a different tokenizer (RoBERTa's SentencePiece/BPE) also needs a newtokenizers::Tokenizerimplementation and corresponding tokenizer-file resolution. - New post-transformer module (e.g.
WeightedLayerPooling): add a module struct + implModulefor it + add a match arm onshort_typeinSentenceTransformer::new.
See src/modules/ for the building blocks.
Compatibility
- 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.
| Project | Downloads | Dependents | Stars | Latest release | Runs on (GPU) | Native code | License |
|---|---|---|---|---|---|---|---|
|
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-rs Listed
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 |
|
Rust interface to word2vec. |
59 downloads over 30 days | 1 | 32 | 0.3.3 | GPU support unknown | No native code found | MIT |
|
pure rust implemention of word2vec |
Not measured | Not applicable | 87 | Not measured | Not measured | Not measured | None stated |
All projects in Run and serve modelsAll projects in Text, embeddings and search
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 daysdormancy: last activity 2026-10-07, 33 days ago, E = 365: activefeatured: 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
- Description: the crates.io description
- crates.io database dump, fetched
- RustSec advisory database, fetched
- GitHub repository, fetched
- crates.io package, fetched
- GitHub contributors, fetched
Adoption0 active dependents, 0 new dependents in 365 days1 not measured
| Signal | Value | Source | Fetched | Counts |
|---|---|---|---|---|
| Active dependents | 0 | crates.io database dump | Yes | |
| New dependents (365 days) | 0 | crates.io database dump | Yes | |
| Peak active dependents | 0 | crates.io database dump | Yes | |
| Active dependents as a share of the peak | 1 | crates.io database dump | Yes | |
| Binary downloads per release | Not measured | Yes |
MaintenanceLatest human commit: 33 days ago3 not measured
| Signal | Value | Source | Fetched | Counts |
|---|---|---|---|---|
| Latest human commit | 2026-10-07 | GitHub repository | Yes | |
| Latest release | 2023-09-23 | crates.io database dump | Yes | |
| First release | 2020-05-18 | crates.io database dump | Yes | |
| Latest version | 0.4.1 | crates.io database dump | Yes | |
| Days the oldest outside issue waits for a reply | 33 | GitHub repository | Yes | |
| Maintainer replies over 365 days | 4 | GitHub repository | Yes | |
| Repository archived | false | GitHub repository | Yes | |
| Repository gone | false | GitHub repository | Yes | |
| Release commit or manifest in the repo | true | crates.io package | Yes | |
| Published docs | true | crates.io database dump | Yes | |
| Latest release fails cargo check | Not measured | Yes | ||
| Build check date | Not measured | Yes | ||
| Build check toolchain | Not measured | Yes |
SecurityUnpatched vulnerabilities: none
| Signal | Value | Source | Fetched | Counts |
|---|---|---|---|---|
| Unpatched vulnerabilities past the grace window | none | RustSec advisory database | Yes | |
| RustSec unmaintained advisory | none | RustSec advisory database | Yes | |
| Deprecation notice | none | crates.io database dump | Yes | |
| Deprecated requirement | none | crates.io database dump | Yes |
Distribution7 releases, 10 downloads over 30 days5 not measured
| Signal | Value | Source | Fetched | Counts |
|---|---|---|---|---|
| Releases | 7 | crates.io database dump | Yes | |
| Downloads over 30 days | 10 | crates.io database dump | Yes | |
| Binary downloads over the last 3 releases | Not measured | Yes | ||
| Homebrew installs on request over 365 days | Not measured | Yes | ||
| Repology repository families | Not measured | Yes | ||
| Docker pull growth over 90 days | Not measured | Yes | ||
| Docker pulls at the growth baseline | Not measured | Yes | ||
| Every version a prerelease | false | crates.io database dump | Yes | |
| Every version 0.0.x | false | crates.io database dump | Yes | |
| Every version yanked | false | crates.io database dump | Yes | |
| Crate deleted from crates.io | false | crates.io database dump | Yes |
Repository127 stars, 12 forks, 5 contributors, 72 commits. Stars alone never qualify a project.
| Signal | Value | Source | Fetched | Counts |
|---|---|---|---|---|
| GitHub stars | 127 | GitHub repository | Yes — one part of the repository route | |
| GitHub forks | 12 | GitHub repository | Yes — one part of the repository route | |
| Contributors with a GitHub account | 5 | GitHub contributors | Yes — one part of the repository route | |
| Commits on the default branch | 72 | GitHub repository | No | |
| Repository's main crate left out of the entry | none | crates.io database dump | Yes |
Facts that never count
| Signal | Value | Source | Fetched | Counts |
|---|---|---|---|---|
| License | Apache-2.0 | crates.io database dump | No | |
| Runs on, from listed crates and their direct dependencies | CUDA | crates.io database dump | No | |
| What shows each backend | CUDA: sbert dependency tch | crates.io database dump | No | |
| Native code, from listed crates and their dependencies | Binds native code: torch-sys | crates.io database dump | No | |
| Python bindings, from direct dependencies of listed crates | No Python binding crate found | crates.io database dump | No | |
| Crates that depend on a listed crate directly | 0 | crates.io database dump | No |
Corrections and review history
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.