fastembed/
lib.rs

1//! [FastEmbed](https://github.com/Anush008/fastembed-rs) - Fast, light, accurate library built for retrieval embedding generation.
2//!
3//! The library provides the TextEmbedding struct to interface with text embedding models.
4//!
5#![cfg_attr(
6    feature = "hf-hub",
7    doc = r#"
8 ### Instantiating [TextEmbedding](crate::TextEmbedding)
9 ```
10 use fastembed::{TextEmbedding, InitOptions, EmbeddingModel};
11
12# fn model_demo() -> anyhow::Result<()> {
13 // With default InitOptions
14 let model = TextEmbedding::try_new(Default::default())?;
15
16 // List all supported models
17 dbg!(TextEmbedding::list_supported_models());
18
19 // With custom InitOptions
20 let model = TextEmbedding::try_new(
21        InitOptions::new(EmbeddingModel::AllMiniLML6V2).with_show_download_progress(true),
22 )?;
23 # Ok(())
24 # }
25 ```
26"#
27)]
28//! Find more info about the available options in the [InitOptions](crate::InitOptions) documentation.
29//!
30#![cfg_attr(
31    feature = "hf-hub",
32    doc = r#"
33 ### Embeddings generation
34```
35# use fastembed::{TextEmbedding, InitOptions, EmbeddingModel};
36# fn embedding_demo() -> anyhow::Result<()> {
37# let mut model: TextEmbedding = TextEmbedding::try_new(Default::default())?;
38 let documents = vec![
39    "passage: Hello, World!",
40    "query: Hello, World!",
41    "passage: This is an example passage.",
42    // You can leave out the prefix but it's recommended
43    "fastembed-rs is licensed under MIT"
44    ];
45
46 // Generate embeddings with the default batch size, 256
47 let embeddings = model.embed(documents, None)?;
48
49 println!("Embeddings length: {}", embeddings.len()); // -> Embeddings length: 4
50 # Ok(())
51 # }
52 ```
53"#
54)]
55
56mod common;
57
58#[cfg(feature = "image-models")]
59mod image_embedding;
60mod init;
61mod models;
62pub mod output;
63mod pooling;
64mod reranking;
65mod sparse_text_embedding;
66mod text_embedding;
67
68pub use ort::execution_providers::ExecutionProviderDispatch;
69
70pub use crate::common::{get_cache_dir, Embedding, Error, SparseEmbedding, TokenizerFiles};
71pub use crate::models::{
72    model_info::ModelInfo, model_info::RerankerModelInfo, quantization::QuantizationMode,
73};
74pub use crate::output::{EmbeddingOutput, OutputKey, OutputPrecedence, SingleBatchOutput};
75pub use crate::pooling::Pooling;
76
77// For all Embedding
78pub use crate::init::{InitOptions as BaseInitOptions, InitOptionsWithLength};
79pub use crate::models::ModelTrait;
80
81// For Text Embedding
82pub use crate::models::text_embedding::EmbeddingModel;
83#[deprecated(note = "use `TextInitOptions` instead")]
84pub use crate::text_embedding::TextInitOptions as InitOptions;
85pub use crate::text_embedding::{
86    InitOptionsUserDefined, TextEmbedding, TextInitOptions, UserDefinedEmbeddingModel,
87};
88
89// For Sparse Text Embedding
90pub use crate::models::sparse::SparseModel;
91pub use crate::sparse_text_embedding::{
92    SparseInitOptions, SparseTextEmbedding, UserDefinedSparseModel,
93};
94
95// For Image Embedding
96#[cfg(feature = "image-models")]
97pub use crate::image_embedding::{
98    ImageEmbedding, ImageInitOptions, ImageInitOptionsUserDefined, UserDefinedImageEmbeddingModel,
99};
100pub use crate::models::image_embedding::ImageEmbeddingModel;
101
102// For Reranking
103pub use crate::models::reranking::RerankerModel;
104pub use crate::reranking::{
105    OnnxSource, RerankInitOptions, RerankInitOptionsUserDefined, RerankResult, TextRerank,
106    UserDefinedRerankingModel,
107};
108
109// For Qwen3 (candle backend)
110#[cfg(feature = "qwen3")]
111pub use crate::models::qwen3::{Config as Qwen3Config, Qwen3TextEmbedding};