Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
57f56c6
fix: Miscellaneous
anush008 Nov 16, 2026
bd38533
fix: check special-token room per input type and test reranker logits…
anush008 Nov 16, 2026
c7a97ea
fix: keep 7.7.0 results for inputs that worked and test each new branch
anush008 Nov 16, 2026
5f48e53
fix: use the default Hugging Face endpoint when HF_ENDPOINT is empty
anush008 Nov 16, 2026
aaa2b0c
fix: turn aborts, hangs, and wrong tokens on edge-case inputs into co…
anush008 Nov 16, 2026
f2aed3f
fix: hold one batch of text model output in memory and correct the mo…
anush008 Nov 16, 2026
44ff445
test: cover the candle loaders and fit the model test bounds to measu…
anush008 Nov 16, 2026
1a51e43
docs: correct the README model list, dependency lines, and notes
anush008 Nov 16, 2026
9eb2ea5
fix: pad on the left in Qwen3TextEmbedding::new and refuse rows of un…
anush008 Nov 16, 2026
6aeac25
docs: use the model card's prompt format in the Qwen3 README example
anush008 Nov 16, 2026
50535ab
fix: load Qwen3 configs written by transformers 5 and the Qwen3-VL 8B…
anush008 Nov 16, 2026
0083019
fix: keep the resized image size check free of integer overflow
anush008 Nov 16, 2026
e4c11b0
fix: wait for a model download in progress and correct BERT, Nomic, Q…
anush008 Nov 16, 2026
1c656ee
test: check BERT and CLIP image vectors against reference values and …
anush008 Nov 16, 2026
13dd263
docs: drop the query and passage prefixes from the examples and state…
anush008 Nov 16, 2026
1ac5483
ci: lint bert-text and ort-load-dynamic, run the BERT suite, and save…
anush008 Nov 16, 2026
1e8677b
fix: limit each buffer of an image resize to 512 MiB and wait through…
anush008 Nov 16, 2026
a3d5111
fix: address review findings in the download wait, the BERT config, a…
anush008 Nov 16, 2026
77169b9
fix: take a cached file during the wait for another download and drop…
anush008 Nov 16, 2026
f4b2870
test: compare the whole ClipVitB32 image vectors with the Python refe…
anush008 Nov 16, 2026
d094770
fix: keep zero scores of either sign in corpus order in top_k
anush008 Nov 16, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ jobs:
./build.sh --update --build --config Release --parallel --compile_no_warning_as_error --skip_submodule_sync
cd ..

- name: Always Save Cache
if: always() && steps.cache-build-restore.outputs.cache-hit != 'true'
# A build that failed or was cancelled must not be saved: the key cannot be written twice.
- name: Save ONNX Build
if: steps.cache-build-restore.outputs.cache-hit != 'true'
uses: actions/cache/save@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
with:
key: '${{ steps.cache-build-restore.outputs.cache-primary-key }}'
Expand All @@ -60,6 +61,7 @@ jobs:
- { name: image, filter: "--test image-embeddings" }
- { name: qwen3, filter: "--features qwen3 --lib --test qwen3", cache: test-qwen3 }
- { name: nomic-v2-moe, filter: "--features nomic-v2-moe --test nomic_v2_moe", cache: test-nomic-v2-moe }
- { name: bert-text, filter: "--features bert-text --lib --test bert_embedding", cache: test-bert-text }

steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
Expand Down Expand Up @@ -129,9 +131,15 @@ jobs:
- os: ubuntu-latest
name: nomic-v2-moe
features: "nomic-v2-moe,hf-hub-native-tls"
- os: ubuntu-latest
name: bert-text
features: "bert-text,hf-hub-native-tls"
- os: ubuntu-latest
name: rustls-image
features: "hf-hub-rustls-tls,image-models"
- os: ubuntu-latest
name: ort-load-dynamic
features: "ort-load-dynamic,hf-hub-native-tls,image-models"
- os: windows-latest
name: directml
features: "directml,hf-hub-native-tls,image-models"
Expand All @@ -149,7 +157,7 @@ jobs:

# The in-file tests of the Metal code: the fused Qwen3 kernels and the model-level
# Metal checks. They build random weights, so nothing is downloaded but ONNX Runtime,
# which the crate links whatever its features.
# which `ort-download-binaries-native-tls` adds so that the ONNX unit tests run here too.
test-metal:
runs-on: macos-15
permissions:
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ homepage = "https://crates.io/crates/fastembed"
include = ["src/**/*", "tests/**/*", "Cargo.toml", "README.md", "LICENSE"]

[package.metadata.docs.rs]
features = ["qwen3", "nomic-v2-moe"]
features = ["qwen3", "nomic-v2-moe", "bert-text"]
rustdoc-args = ["--cfg", "docsrs"]

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
Expand Down
55 changes: 35 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
<div align="center">
<h1><a href="https://crates.io/crates/fastembed">FastEmbed-rs 🦀</a></h1>
<h3>Rust library for generating vector embeddings, reranking locally!</h3>
<a href="https://www.atlascloud.ai/?ref=FCWMKG"><img src="https://www.atlascloud.ai/oss-program/powered-by-atlas-cloud.svg" alt="Powered by Atlas Cloud" width="222" height="28"/></a>
<a href="https://www.greptile.com/?utm_source=oss_badge&utm_medium=readme&utm_campaign=greptile_for_open_source"><img src="https://www.greptile.com/badge.svg" alt="Greptile for Open Source" width="210" height="28"/></a>
</div>

## Features

- Supports synchronous usage. No dependency on Tokio.
- Supports synchronous usage. No Tokio runtime needed.
- Uses [@pykeio/ort](https://github.com/pykeio/ort) for performant ONNX inference.
- Uses [@huggingface/tokenizers](https://github.com/huggingface/tokenizers) for fast encodings.

Expand All @@ -32,7 +31,7 @@
- [**sentence-transformers/all-MiniLM-L6-v2**](https://huggingface.co/sentence-transformers/all-MiniLM-L6-v2)
- [**sentence-transformers/all-MiniLM-L12-v2**](https://huggingface.co/sentence-transformers/all-MiniLM-L12-v2)
- [**sentence-transformers/all-mpnet-base-v2**](https://huggingface.co/sentence-transformers/all-mpnet-base-v2)
- [**sentence-transformers/paraphrase-MiniLM-L12-v2**](https://huggingface.co/sentence-transformers/paraphrase-MiniLM-L12-v2)
- [**sentence-transformers/paraphrase-multilingual-MiniLM-L12-v2**](https://huggingface.co/sentence-transformers/paraphrase-multilingual-MiniLM-L12-v2)
- [**sentence-transformers/paraphrase-multilingual-mpnet-base-v2**](https://huggingface.co/sentence-transformers/paraphrase-multilingual-mpnet-base-v2)
- [**nomic-ai/nomic-embed-text-v1**](https://huggingface.co/nomic-ai/nomic-embed-text-v1)
- [**nomic-ai/nomic-embed-text-v1.5**](https://huggingface.co/nomic-ai/nomic-embed-text-v1.5) - pairs with `nomic-embed-vision-v1.5` for image-to-text search
Expand All @@ -58,7 +57,7 @@
- [**snowflake/snowflake-arctic-embed-m-long**](https://huggingface.co/snowflake/snowflake-arctic-embed-m-long)
- [**snowflake/snowflake-arctic-embed-l**](https://huggingface.co/snowflake/snowflake-arctic-embed-l)

Quantized versions are also available for several models above (append `Q` to the model enum variant, e.g., `EmbeddingModel::BGESmallENV15Q`). EmbeddingGemma additionally ships a 4-bit build as `EmbeddingModel::EmbeddingGemma300MQ4`.
Quantized versions are also available for several models above (append `Q` to the model enum variant, e.g., `EmbeddingModel::AllMiniLML6V2Q`). The `Q` variants of the English BGE v1.5 models and of paraphrase-multilingual-MiniLM-L12-v2 are half-precision (fp16) models. EmbeddingGemma additionally ships a 4-bit build as `EmbeddingModel::EmbeddingGemma300MQ4`.

</details>

Expand Down Expand Up @@ -128,17 +127,15 @@ let mut model = TextEmbedding::try_new(
)?;

let documents = vec![
"passage: Hello, World!",
"query: Hello, World!",
"passage: This is an example passage.",
// You can leave out the prefix but it's recommended
"Hello, World!",
"This is an example passage.",
"fastembed-rs is licensed under Apache 2.0"
];

// Generate embeddings with the default batch size, 256
let embeddings = model.embed(documents, None)?;

println!("Embeddings length: {}", embeddings.len()); // -> Embeddings length: 4
println!("Embeddings length: {}", embeddings.len()); // -> Embeddings length: 3
println!("Embedding dimension: {}", embeddings[0].len()); // -> Embedding dimension: 384
```

Expand All @@ -156,13 +153,14 @@ let mut model = SparseTextEmbedding::try_new(
)?;

let documents = vec![
"passage: Hello, World!",
"query: Hello, World!",
"passage: This is an example passage.",
"Hello, World!",
"This is an example passage.",
"fastembed-rs is licensed under Apache 2.0"
];

// Generate embeddings with the default batch size, 256
// Generate embeddings with the default batch size, 256.
// This model emits one score per vocabulary entry per token.
// So keep the batch size small for long documents.
let embeddings: Vec<SparseEmbedding> = model.embed(documents, None)?;
```

Expand All @@ -179,7 +177,7 @@ let mut model = ImageEmbedding::try_new(
ImageInitOptions::new(ImageEmbeddingModel::ClipVitB32).with_show_download_progress(true),
)?;

let images = vec!["assets/image_0.png", "assets/image_1.png"];
let images = vec!["tests/assets/image_0.png", "tests/assets/image_1.png"];

// Generate embeddings with the default batch size, 256
let embeddings = model.embed(images, None)?;
Expand Down Expand Up @@ -262,6 +260,8 @@ Qwen3 embedding models are available behind the `qwen3` feature flag (candle bac
```toml
[dependencies]
fastembed = { version = "7", features = ["qwen3"] }
# The candle version that fastembed uses, for `Device` and `DType`.
candle-core = "0.11"
```

```rust
Expand All @@ -276,10 +276,15 @@ let model = Qwen3TextEmbedding::from_hf(
512,
)?;

// Text-only usage with the Qwen3-VL embedding checkpoint is also supported:
// Text-only usage with the Qwen3-VL embedding checkpoint is also supported. `embed` runs each
// text as given, and `Qwen3VLEmbedding::embed_texts` adds the prompt of the model card.
// let model = Qwen3TextEmbedding::from_hf("Qwen/Qwen3-VL-Embedding-2B", &device, DType::F32, 512)?;

let embeddings = model.embed(&["query: ...", "passage: ..."])?;
// A query carries its task instruction, and a document goes in as it is.
let embeddings = model.embed(&[
"Instruct: Given a web search query, retrieve relevant passages that answer the query\nQuery:What is the capital of China?",
"The capital of China is Beijing.",
])?;
println!("Embeddings length: {}", embeddings.len());
```

Expand All @@ -298,7 +303,7 @@ let model = Qwen3VLEmbedding::from_hf(
)?;

let image_embeddings = model.embed_images(&["tests/assets/image_0.png", "tests/assets/image_1.png"])?;
let text_embeddings = model.embed_texts(&["query: blue cat", "query: red cat"])?;
let text_embeddings = model.embed_texts(&["blue cat", "red cat"])?;

println!("Image embeddings: {}", image_embeddings.len());
println!("Text embeddings: {}", text_embeddings.len());
Expand All @@ -319,7 +324,11 @@ let model = Qwen3TextEmbedding::from_hf_gguf(
512,
)?;

let embeddings = model.embed(&["query: ...", "passage: ..."])?;
// A query carries its task instruction, and a document goes in as it is.
let embeddings = model.embed(&[
"Instruct: Given a web search query, retrieve relevant passages that answer the query\nQuery:What is the capital of China?",
"The capital of China is Beijing.",
])?;
println!("Embeddings length: {}", embeddings.len());
```

Expand All @@ -330,6 +339,7 @@ The [nomic-embed-text-v2-moe](https://huggingface.co/nomic-ai/nomic-embed-text-v
```toml
[dependencies]
fastembed = { version = "7", features = ["nomic-v2-moe"] }
candle-core = "0.11"
```

```rust
Expand All @@ -355,6 +365,7 @@ BERT-family encoders are available behind the `bert-text` feature flag (candle b
```toml
[dependencies]
fastembed = { version = "7", features = ["bert-text"] }
candle-core = "0.11"
```

```rust
Expand Down Expand Up @@ -414,12 +425,14 @@ println!("Sparse non-zero tokens: {}", sparse_emb.indices.len());
println!("ColBERT token count: {}", output.colbert[0].len());
```

`Bgem3Model::BGEM3Q` is dynamically quantized, so the vectors of a text vary slightly with the other texts in its batch.

## Model cache

Models download on first use and load from cache afterwards (no network needed at runtime once cached).

- `FASTEMBED_CACHE_DIR` — cache location (default: `.fastembed_cache`). Equivalent to `TextInitOptions::with_cache_dir`.
- `HF_HOME` — if set, takes precedence over the above.
- `HF_HOME` — if set, models are cached directly in this directory, and it takes precedence over the above.
- `HF_ENDPOINT` — Hugging Face mirror base URL, for restricted networks.
- `HF_TOKEN` — Hugging Face access token, for gated repositories and higher rate limits. Without it, the token saved by `huggingface-cli login` is used when present.

Expand All @@ -430,6 +443,8 @@ To run models on a GPU via DirectML on Windows, enable the `directml` feature:
```toml
[dependencies]
fastembed = { version = "7", features = ["directml"] }
# The ort version that fastembed uses, for the execution provider.
ort = "=2.0.0-rc.15"
```

Then pass a DirectML execution provider when initializing a model:
Expand Down Expand Up @@ -463,7 +478,7 @@ let model = TextEmbedding::try_new(

## Error handling

Fastembed returns a typed [`fastembed::Error`](https://docs.rs/fastembed/latest/fastembed/enum.Error.html). The type is re-exported from the crate root. The enum is `#[non_exhaustive]`. New variants can be added in minor releases without breaking `match` arms.
The ONNX models return a typed [`fastembed::Error`](https://docs.rs/fastembed/latest/fastembed/enum.Error.html). The type is re-exported from the crate root. The enum is `#[non_exhaustive]`. New variants can be added in minor releases without breaking `match` arms. The candle models return `candle_core::Error`.

```rust
use fastembed::{Error, Result, TextEmbedding};
Expand Down
Loading
Loading