Skip to main content

model2vec-rs (Python)

Python bindings for model2vec-rs, the Rust implementation of Model2Vec.

Installation

pip install maturin
maturin develop --release   # from this directory

Usage

from model2vec_rs import StaticModel

model = StaticModel.from_pretrained("minishlab/potion-base-8M")

embeddings = model.encode(["Hello world", "Rust is awesome"])  # np.ndarray, shape (2, dim)
embedding = model.encode("Hello world")                        # np.ndarray, shape (dim,)

model.dim  # int
model.normalize  # bool, whether encode L2-normalizes by default
model.max_length  # int | None, the default max tokens per sentence for encode

encode accepts max_length (default: the model's max_length, None for no limit), batch_size (default None, which encodes all sentences in one parallel pass) and normalize (default None, which uses the model's setting), and releases the GIL while encoding.

As in model2vec, the model's max_length comes from its config (512 if unset, null for no limit). Override it with StaticModel.from_pretrained(..., max_length=...); from_arrays defaults to 512.

Loading from arrays

from_arrays builds a model from a tokenizer JSON string and NumPy arrays you have already loaded:

import numpy as np
from model2vec_rs import StaticModel

tokenizer = open("tokenizer.json").read()
embeddings = np.load("embeddings.npy")  # float32 or int8, shape (rows, dim)

model = StaticModel.from_arrays(tokenizer, embeddings, normalize=True)

embeddings and weights are copied, so later changes to your arrays don't affect the model. To avoid the copy, pass C-contiguous arrays over memory that cannot be written to, such as np.load("embeddings.npy", mmap_mode="r") or np.frombuffer(data, dtype=np.float32).reshape(rows, dim) with data a bytes object: these are shared with the model, which keeps them alive. Writable arrays are always copied, because another thread could write to them while encode reads them without the GIL. token_mapping is always copied.

model.embeddings and model.weights return the arrays the model reads from as read-only arrays, without copying. Use them instead of your original arrays to keep only one copy in memory; passing them to from_arrays again shares them with the new model. They are None for models loaded with from_pretrained.

Performance

We encoded the same 666,808 Wikipedia paragraphs (11M words) with blink-8m using the Rust crate, these bindings, and Python model2vec:

Encoding throughput of Rust, the Python bindings and Python model2vec

On a single thread the bindings are about as fast as Rust and roughly 24× faster than model2vec; on all cores they are roughly 38× faster than model2vec.

To reproduce (from the repository root):

uv run --with ./python scripts/python_compare.py --model minishlab/blink-8m --bindings --rust-api flat --no-python-multiprocessing --out bindings.json
uv run scripts/bindings_chart.py bindings.json

Measured on an Apple M3 Pro with 5 alternating rounds per implementation, 5 timed passes each; throughput is the median over all passes. As in the main benchmark, model2vec runs with use_multiprocessing=False, which is faster than its default process pool. See scripts/python_compare.py for the options.

Metadata

Release files for model2vec-rs 0.5.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for model2vec-rs 0.5.1
File Size Uploaded Provenance Actions
model2vec_rs-0.5.1.tar.gz 153.6 kB With provenance Details for model2vec_rs-0.5.1.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for model2vec-rs 0.5.1
File Actions
model2vec_rs-0.5.1-cp310-abi3-win_arm64.whl CPython 3.10 abi3 Windows ARM64 Details for model2vec_rs-0.5.1-cp310-abi3-win_arm64.whl
model2vec_rs-0.5.1-cp310-abi3-win_amd64.whl CPython 3.10 abi3 Windows x86-64 Details for model2vec_rs-0.5.1-cp310-abi3-win_amd64.whl
model2vec_rs-0.5.1-cp310-abi3-musllinux_1_2_x86_64.whl CPython 3.10 abi3 Linux musl 1.2+ x86-64 Details for model2vec_rs-0.5.1-cp310-abi3-musllinux_1_2_x86_64.whl
model2vec_rs-0.5.1-cp310-abi3-musllinux_1_2_aarch64.whl CPython 3.10 abi3 Linux musl 1.2+ ARM64 Details for model2vec_rs-0.5.1-cp310-abi3-musllinux_1_2_aarch64.whl
model2vec_rs-0.5.1-cp310-abi3-manylinux_2_28_x86_64.whl CPython 3.10 abi3 Linux glibc 2.28+ x86-64 Details for model2vec_rs-0.5.1-cp310-abi3-manylinux_2_28_x86_64.whl
model2vec_rs-0.5.1-cp310-abi3-manylinux_2_28_aarch64.whl CPython 3.10 abi3 Linux glibc 2.28+ ARM64 Details for model2vec_rs-0.5.1-cp310-abi3-manylinux_2_28_aarch64.whl
model2vec_rs-0.5.1-cp310-abi3-macosx_11_0_arm64.whl CPython 3.10 abi3 macOS 11.0+ ARM64 Details for model2vec_rs-0.5.1-cp310-abi3-macosx_11_0_arm64.whl
model2vec_rs-0.5.1-cp310-abi3-macosx_10_12_x86_64.whl CPython 3.10 abi3 macOS 10.12+ x86-64 Details for model2vec_rs-0.5.1-cp310-abi3-macosx_10_12_x86_64.whl

Total release size: 41.3 MB

Release files / model2vec_rs-0.5.1.tar.gz

Download URL model2vec_rs-0.5.1.tar.gz
Size 153.6 kB
Tags Source
SHA-256 checksum
How to use checksums
db1ab1a79f06f5e6b0dc024704ab3be656f71bac80a79298ef71458384cd06da
BLAKE2b-256 checksum
How to use checksums
f490a1b1320c93e169f052ff579102915806aa589d75d551add9b80a2d7e7212
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 24, 2026.

Transparency log

Release files / model2vec_rs-0.5.1-cp310-abi3-win_arm64.whl

Download URL model2vec_rs-0.5.1-cp310-abi3-win_arm64.whl
Size 3.0 MB
Tags CPython 3.10 Windows ARM64 abi3
SHA-256 checksum
How to use checksums
aa89947cd02ec2f6b0ffe60504b3efd2d77e8e32205ebbae846f5da234c77a09
BLAKE2b-256 checksum
How to use checksums
fdc6ba5d52cffd746a0ec160f001d0595baecdd7d5a7be9c4862ced809f5d9e8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 24, 2026.

Transparency log

Release files / model2vec_rs-0.5.1-cp310-abi3-win_amd64.whl

Download URL model2vec_rs-0.5.1-cp310-abi3-win_amd64.whl
Size 3.1 MB
Tags CPython 3.10 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
34273ad17774ed90baa16c04313a805de5be08621966b45f0eca2a1df4b5b794
BLAKE2b-256 checksum
How to use checksums
354c4f75e995ce8f480dd6f3cbbc1103f452700422931b92f6d35382a04d4835
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 24, 2026.

Transparency log

Release files / model2vec_rs-0.5.1-cp310-abi3-musllinux_1_2_x86_64.whl

Download URL model2vec_rs-0.5.1-cp310-abi3-musllinux_1_2_x86_64.whl
Size 10.6 MB
Tags CPython 3.10 Linux musl 1.2+ x86-64 abi3
SHA-256 checksum
How to use checksums
92f0c0ee68920847ca51d4b42bd17d2b2637326fbde22947f9b40f50efef1d17
BLAKE2b-256 checksum
How to use checksums
81aedc39169e6f3a38aa1063776b3e596e28e3a811c12771e46c37c8b4dc2b86
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 24, 2026.

Transparency log

Release files / model2vec_rs-0.5.1-cp310-abi3-musllinux_1_2_aarch64.whl

Download URL model2vec_rs-0.5.1-cp310-abi3-musllinux_1_2_aarch64.whl
Size 10.2 MB
Tags CPython 3.10 Linux musl 1.2+ ARM64 abi3
SHA-256 checksum
How to use checksums
e8271caa08343948d3d7459e065e1f2d27dfed664063247057c11604b54058f7
BLAKE2b-256 checksum
How to use checksums
5393e881640e7e94bda8278f1996ecb7e9755105bc2b34f1477d3b0aa68942d9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 24, 2026.

Transparency log

Release files / model2vec_rs-0.5.1-cp310-abi3-manylinux_2_28_x86_64.whl

Download URL model2vec_rs-0.5.1-cp310-abi3-manylinux_2_28_x86_64.whl
Size 3.7 MB
Tags CPython 3.10 Linux glibc 2.28+ x86-64 abi3
SHA-256 checksum
How to use checksums
4e71f701a1d389d5f7e7c021cd940b97bfc466f4bd64d5e0dd76f4ef81e59ab8
BLAKE2b-256 checksum
How to use checksums
0c777634b609591c3f957a09b289acfde2b5f86488d952fc640438dc2db5df0c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 24, 2026.

Transparency log

Release files / model2vec_rs-0.5.1-cp310-abi3-manylinux_2_28_aarch64.whl

Download URL model2vec_rs-0.5.1-cp310-abi3-manylinux_2_28_aarch64.whl
Size 3.8 MB
Tags CPython 3.10 Linux glibc 2.28+ ARM64 abi3
SHA-256 checksum
How to use checksums
8814f1a9aa24d291b07f4a934b0fa57ddf72376552f1db4e7f61a99923de6cdf
BLAKE2b-256 checksum
How to use checksums
35ada2e1f6576599918f731e93687607d30fe0af89c336d738bc5f090765ffe6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 24, 2026.

Transparency log

Release files / model2vec_rs-0.5.1-cp310-abi3-macosx_11_0_arm64.whl

Download URL model2vec_rs-0.5.1-cp310-abi3-macosx_11_0_arm64.whl
Size 3.3 MB
Tags CPython 3.10 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
aa394460f15edd38cee31951d56bbf1d226ada2dea7baaaed373e3e9eb46c25a
BLAKE2b-256 checksum
How to use checksums
530e7c63cd068a92dbfa7f41930460a8ff7a5f30ffb60d49458c76e3018fa994
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 24, 2026.

Transparency log

Release files / model2vec_rs-0.5.1-cp310-abi3-macosx_10_12_x86_64.whl

Download URL model2vec_rs-0.5.1-cp310-abi3-macosx_10_12_x86_64.whl
Size 3.4 MB
Tags CPython 3.10 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
19cbb19555229d5232cbd246ae11b7c1941def84048bf3871826db73e71cc8c2
BLAKE2b-256 checksum
How to use checksums
43cf5eeb55291d1d365419a6ff1f8529be7be9408d690a43f28112de17bc2f86
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 24, 2026.

Transparency log

Security for model2vec-rs 0.5.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 9 files in this release have been uploaded with provenance metadata.

Select from 9 files

Attestation for model2vec_rs-0.5.1.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 24, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page