Features
- Supports synchronous usage. No Tokio runtime needed.
- Uses @pykeio/ort for performant ONNX inference.
- Uses @huggingface/tokenizers for fast encodings.
Not looking for Rust?
- Python: fastembed
- Go: fastembed-go
- JavaScript: fastembed-js
Supported Models
Text Embedding
- BAAI/bge-small-en-v1.5 - Default
- BAAI/bge-base-en-v1.5
- BAAI/bge-large-en-v1.5
- BAAI/bge-small-zh-v1.5
- BAAI/bge-large-zh-v1.5
- BAAI/bge-m3
- sentence-transformers/all-MiniLM-L6-v2
- sentence-transformers/all-MiniLM-L12-v2
- sentence-transformers/all-mpnet-base-v2
- sentence-transformers/paraphrase-multilingual-MiniLM-L12-v2
- sentence-transformers/paraphrase-multilingual-mpnet-base-v2
- nomic-ai/nomic-embed-text-v1
- nomic-ai/nomic-embed-text-v1.5 - pairs with
nomic-embed-vision-v1.5for image-to-text search - intfloat/multilingual-e5-small
- intfloat/multilingual-e5-base
- intfloat/multilingual-e5-large
- mixedbread-ai/mxbai-embed-large-v1 - also available on the candle backend with the
bert-textfeature - Alibaba-NLP/gte-base-en-v1.5
- Alibaba-NLP/gte-large-en-v1.5
- lightonai/ModernBERT-embed-large
- Qdrant/clip-ViT-B-32-text - pairs with
clip-ViT-B-32-visionfor image-to-text search - jinaai/jina-embeddings-v2-base-code
- jinaai/jina-embeddings-v2-base-en
- google/embeddinggemma-300m
- nomic-ai/nomic-embed-text-v2-moe - requires
nomic-v2-moefeature (candle backend) - Qwen/Qwen3-Embedding-0.6B - requires
qwen3feature (candle backend) - Qwen/Qwen3-Embedding-4B - requires
qwen3feature (candle backend) - Qwen/Qwen3-Embedding-8B - requires
qwen3feature (candle backend) - Qwen/Qwen3-VL-Embedding-2B - requires
qwen3feature (candle backend, multimodal viaQwen3VLEmbedding) - snowflake/snowflake-arctic-embed-xs
- snowflake/snowflake-arctic-embed-s
- snowflake/snowflake-arctic-embed-m
- snowflake/snowflake-arctic-embed-m-long
- snowflake/snowflake-arctic-embed-l
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.
Sparse Text Embedding
- prithivida/Splade_PP_en_v1 - Default
- BAAI/bge-m3
- opensearch-project/opensearch-neural-sparse-encoding-doc-v3-gte - Inference-free
Image Embedding
- Qdrant/clip-ViT-B-32-vision - Default
- Qdrant/resnet50-onnx
- Qdrant/Unicom-ViT-B-16
- Qdrant/Unicom-ViT-B-32
- nomic-ai/nomic-embed-vision-v1.5
Reranking
- BAAI/bge-reranker-base - Default
- BAAI/bge-reranker-v2-m3
- jinaai/jina-reranker-v1-turbo-en
- jinaai/jina-reranker-v2-base-multilingual
✊ Support
To support the library, please donate to our primary upstream dependency, ort - The Rust wrapper for the ONNX runtime.
Installation
Run the following in your project directory:
Or add the following line to your Cargo.toml:
[]
= "7"
Text Embeddings
use ;
// With default options
let mut model = try_new?;
// With custom options
let mut model = try_new?;
let documents = vec!;
// Generate embeddings with the default batch size, 256
let embeddings = model.embed?;
println!; // -> Embeddings length: 3
println!; // -> Embedding dimension: 384
Sparse Text Embeddings
use ;
// With default options
let mut model = try_new?;
// With custom options
let mut model = try_new?;
let documents = vec!;
// 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: = model.embed?;
Image Embeddings
use ;
// With default options
let mut model = try_new?;
// With custom options
let mut model = try_new?;
let images = vec!;
// Generate embeddings with the default batch size, 256
let embeddings = model.embed?;
println!; // -> Embeddings length: 2
println!; // -> Embedding dimension: 512
Candidates Reranking
use ;
// With default options
let mut model = try_new?;
// With custom options
let mut model = try_new?;
let documents = vec!;
// Rerank with the default batch size, 256 and return document contents
let results = model.rerank?;
println!;
Locally Available Models
Alternatively, local model files can be used for inference via the try_new_from_user_defined(...) methods of the respective structs.
Similarity Search
Helpers in the similarity module score and rank the vectors embed returns, so a quick in-memory search needs no extra crate:
use ;
// `embeddings` is the Vec<Embedding> from model.embed(...)
let query = &embeddings;
// Score two vectors directly ([-1.0, 1.0], higher = closer)
let score = cosine_similarity;
// Or rank the corpus: (index, score) pairs, best first
let hits = top_k;
println!;
For larger corpora or persistence, push the vectors to a vector search engine (e.g. Qdrant) and query there.
Inference-free Sparse Embeddings
use ;
let mut model = try_new?;
// This model emits one score per vocabulary entry per token.
// So keep the batch size small.
let documents = model.embed?;
// Queries are from the tokenizer and a precomputed IDF table alone, without any inference.
let queries = model.query_embed?;
Qwen3 Embeddings
Qwen3 embedding models are available behind the qwen3 feature flag (candle backend).
[]
= { = "7", = ["qwen3"] }
# The candle version that fastembed uses, for `Device` and `DType`.
= "0.11"
use ;
use Qwen3TextEmbedding;
let device = Cpu;
let model = from_hf?;
// 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)?;
// A query carries its task instruction, and a document goes in as it is.
let embeddings = model.embed?;
println!;
For multimodal text/image usage with Qwen/Qwen3-VL-Embedding-2B:
use ;
use Qwen3VLEmbedding;
let device = Cpu;
let model = from_hf?;
let image_embeddings = model.embed_images?;
let text_embeddings = model.embed_texts?;
println!;
println!;
Quantized GGUF files (for example from Qwen/Qwen3-Embedding-4B-GGUF or Qwen/Qwen3-Embedding-8B-GGUF) load with the same qwen3 feature. The weights stay quantized in memory, and the tokenizer comes from the original model's repo:
use Device;
use Qwen3TextEmbedding;
let device = Cpu;
let model = from_hf_gguf?;
// A query carries its task instruction, and a document goes in as it is.
let embeddings = model.embed?;
println!;
Nomic Embed Text v2 MoE
The nomic-embed-text-v2-moe model is available behind the nomic-v2-moe feature flag (candle backend). First general-purpose MoE embedding model with 100+ language support.
[]
= { = "7", = ["nomic-v2-moe"] }
= "0.11"
use ;
use NomicV2MoeTextEmbedding;
let device = Cpu;
let model = from_hf?;
let embeddings = model.embed?;
println!;
BERT Embeddings
BERT-family encoders are available behind the bert-text feature flag (candle backend). Any BERT checkpoint with CLS pooling loads through BertTextEmbedding, which returns L2-normalized vectors; mixedbread-ai/mxbai-embed-large-v1 is the tested one.
[]
= { = "7", = ["bert-text"] }
= "0.11"
use ;
use BertTextEmbedding;
let device = Cpu;
let model = from_hf?;
let embeddings = model.embed?;
println!;
println!;
On Apple silicon, enable metal instead (it enables bert-text) and pass &Device::new_metal(0)?. On NVIDIA GPUs enable cuda and pass &Device::new_cuda(0)?. The Metal build runs attention through candle's fused SDPA kernel and fuses the projection bias, residual, LayerNorm and GELU epilogues. CUDA and CPU use plain tensor attention.
BGE-M3 Joint Embeddings
The BGE-M3 model produces dense, sparse, and ColBERT embeddings simultaneously in a single forward pass.
use ;
// With default options
let mut model = try_new?;
// With custom options (supporting custom max length up to 8192 tokens)
let mut model = try_new?;
let documents = vec!;
// Generate all three representations in a single forward pass
let output = model.embed?;
println!; // -> Dense dimension: 1024
let sparse_emb = &output.sparse;
println!;
println!;
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 toTextInitOptions::with_cache_dir.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 byhuggingface-cli loginis used when present.
DirectML (Windows)
To run models on a GPU via DirectML on Windows, enable the directml feature:
[]
= { = "7", = ["directml"] }
# The ort version that fastembed uses, for the execution provider.
= "=2.0.0-rc.15"
Then pass a DirectML execution provider when initializing a model:
use ;
use DirectML;
let model = try_new?;
When DirectML is detected, fastembed automatically disables memory pattern optimization and parallel execution on the ONNX Runtime session, as required by the DirectML execution provider.
Automatic device selection
When no execution provider is registered, ort enables ONNX Runtime's automatic device selection with AutoDevicePolicy::MaxEfficiency, which registers CoreML on macOS. Registering ort::ep::CPU does not prevent this, because the CPU provider is built in and registers nothing. Set a policy to control the selection:
use ;
let model = try_new?;
AutoDevicePolicy::PreferCPU selects a CPU device, which in a standard ONNX Runtime build is the built-in CPU execution provider.
Error handling
The ONNX models return a typed fastembed::Error. 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.
use ;
To handle an error, match on the variant that applies:
use ;
match try_new