Skip to main content

Crate fastembed

Crate fastembed 

Source
Expand description

FastEmbed - Library for generating vector embeddings and reranking locally.

§What’s here

These run on ONNX Runtime and need the onnx feature, which is on by default and which every ort-* feature turns on.

Qwen3 and Nomic v2 MoE embeddings are available behind the qwen3 and nomic-v2-moe feature flags (candle backend). A build with default-features = false and only those features compiles no ONNX Runtime. qwen3 is qwen3-text (the text embedding model and the reranker, loaded from local files or GGUF) plus qwen3-vl (the Qwen3-VL image and text model) plus hf-hub (the from_hf loaders); qwen3-text alone pulls neither hf-hub nor the image crates.

§Model cache

Models download to ./.fastembed_cache on first use, then load from there. Override the location with the FASTEMBED_CACHE_DIR env var or TextInitOptions::with_cache_dir. HF_HOME takes precedence over both. Set HF_ENDPOINT to pull from a mirror.

§Instantiating TextEmbedding

use fastembed::{TextEmbedding, TextInitOptions, EmbeddingModel};

// With default TextInitOptions
let model = TextEmbedding::try_new(Default::default())?;

// List all supported models
dbg!(TextEmbedding::list_supported_models());

// With custom TextInitOptions
let model = TextEmbedding::try_new(
       TextInitOptions::new(EmbeddingModel::AllMiniLML6V2).with_show_download_progress(true),
)?;

Find more info about the available options in the TextInitOptions documentation.

§Embeddings generation

 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
    "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

Re-exports§

pub use crate::output::EmbeddingOutput;onnx
pub use crate::output::OutputKey;onnx
pub use crate::output::OutputPrecedence;onnx
pub use crate::output::SingleBatchOutput;onnx

Modules§

outputonnx
Utilities to help with the embeddings output.
similarity
Similarity helpers for comparing embeddings.

Structs§

BaseInitOptionsonnx
Bgem3Embeddingonnx
Rust representation of the BGE-M3 joint embedding model
Bgem3EmbeddingOutputonnx
Output of Bgem3Embedding: dense, sparse (lexical), and ColBERT (multi-vector) representations from a single pass.
ExecutionProviderDispatchonnx
Dynamic execution provider container, used to provide a list of multiple types of execution providers when configuring execution providers for a SessionBuilder or EnvironmentBuilder.
ImageEmbeddingimage-models
ImageInitOptionsUserDefinedimage-models
Options for initializing UserDefinedImageEmbeddingModel
ImagePreprocessorimage-models
A model-specific image preprocessor that can be shared with CPU worker threads.
InitOptionsUserDefinedonnx
Options for initializing a user-defined embedding model.
InitOptionsWithLengthonnx
ModelInfoonnx
Data struct about the available models
NomicBertModelnomic-v2-moe
NomicConfignomic-v2-moe
NomicV2MoeTextEmbeddingnomic-v2-moe
Qwen3Configqwen3-text
Qwen3Modelqwen3-text
Qwen3Rerankerqwen3-text
Qwen3-Reranker (for example Qwen/Qwen3-Reranker-0.6B): the probability that a document answers a query under an instruction, read as the model’s “yes” against “no” at the last position, as the model card computes it.
Qwen3TextEmbeddingqwen3-text
High-level embedding wrapper around Qwen3Model that handles tokenization, batching, mean-pooling, and L2-normalization.
Qwen3VLEmbeddingqwen3-text and qwen3-vl
Multimodal embedding wrapper for Qwen3-VL embedding checkpoints.
RerankInitOptionsUserDefinedonnx
Options for initializing a user-defined reranking model.
RerankResultonnx
Rerank result.
RerankerModelInfoonnx
Data struct about the available reranker models
SparseEmbedding
SparseTextEmbeddingonnx
Rust representation of the SparseTextEmbedding model
TextEmbeddingonnx
Rust representation of the TextEmbedding model
TextRerankonnx
TokenizerFiles
UserDefinedBgem3Modelonnx
Struct for “bring your own” BGE-M3 models
UserDefinedEmbeddingModelonnx
Struct for “bring your own” embedding models
UserDefinedImageEmbeddingModelimage-models
Struct for “bring your own” embedding models
UserDefinedRerankingModelonnx
Struct for “bring your own” reranking models
UserDefinedSparseModelonnx
Struct for “bring your own” sparse embedding models

Enums§

Bgem3Modelonnx
EmbeddingModelonnx
Error
Error type returned by fastembed.
ImageEmbeddingModelonnx
OnnxSourceonnx
Enum for the source of the onnx file
Poolingonnx
QuantizationModeonnx
Enum for quantization mode.
RerankerModelonnx
SparseModelonnx

Constants§

QWEN3_RERANKER_DEFAULT_INSTRUCTIONqwen3-text
The instruction the Qwen3-Reranker model card uses when none is given.

Traits§

ModelTraitonnx

Functions§

get_cache_dir

Type Aliases§

Bgem3InitOptionsonnx
Options for initializing the Bgem3Embedding model
Embedding
Type alias for the embedding vector
ImageInitOptionsimage-models
Options for initializing the ImageEmbedding model
InitOptionsDeprecatedonnx
RerankInitOptionsonnx
Options for initializing the reranking models
Result
Type alias for Result returning the fastembed Error type.
SparseInitOptionsonnx
Options for initializing the SparseTextEmbedding model
TextInitOptionsonnx
Options for initializing the TextEmbedding model