Crate fastembed

Source
Expand description

FastEmbed - Fast, light, accurate library built for retrieval embedding generation.

The library provides the TextEmbedding struct to interface with text embedding models.

§Instantiating TextEmbedding

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

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

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

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

Find more info about the available options in the InitOptions 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 MIT"
    ];

 // 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;
pub use crate::output::OutputKey;
pub use crate::output::OutputPrecedence;
pub use crate::output::SingleBatchOutput;

Modules§

output
Utilities to help with the embeddings output.

Structs§

ExecutionProviderDispatch
Dynamic execution provider container, used to provide a list of multiple types of execution providers when configuring execution providers for a SessionBuilder or EnvironmentBuilder.
ImageEmbedding
Rust representation of the ImageEmbedding model
ImageInitOptions
Options for initializing the ImageEmbedding model
ImageInitOptionsUserDefined
Options for initializing UserDefinedImageEmbeddingModel
InitOptions
Options for initializing the TextEmbedding model
InitOptionsUserDefined
Options for initializing UserDefinedEmbeddingModel
ModelInfo
Data struct about the available models
RerankInitOptions
Options for initializing the reranking model
RerankInitOptionsUserDefined
Options for initializing UserDefinedRerankerModel
RerankResult
Rerank result.
RerankerModelInfo
Data struct about the available reranker models
SparseEmbedding
SparseInitOptions
Options for initializing the SparseTextEmbedding model
SparseTextEmbedding
Rust representation of the SparseTextEmbedding model
TextEmbedding
Rust representation of the TextEmbedding model
TextRerank
TokenizerFiles
UserDefinedEmbeddingModel
Struct for “bring your own” embedding models
UserDefinedImageEmbeddingModel
Struct for “bring your own” embedding models
UserDefinedRerankingModel
Struct for “bring your own” reranking models
UserDefinedSparseModel
Struct for “bring your own” embedding models

Enums§

EmbeddingModel
ImageEmbeddingModel
OnnxSource
Enum for the source of the onnx file
Pooling
QuantizationMode
Enum for quantization mode.
RerankerModel
SparseModel

Constants§

DEFAULT_CACHE_DIR

Functions§

read_file_to_bytes
Public function to read a file to bytes. To be used when loading local model files.

Type Aliases§

Embedding
Type alias for the embedding vector
Error
Type alias for the error type