forked from Anush008/fastembed-rs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlib.rs
89 lines (81 loc) · 2.77 KB
/
lib.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
//! [FastEmbed](https://github.com/Anush008/fastembed-rs) - Fast, light, accurate library built for retrieval embedding generation.
//!
//! The library provides the TextEmbedding struct to interface with text embedding models.
//!
#![cfg_attr(
feature = "online",
doc = r#"
### Instantiating [TextEmbedding](crate::TextEmbedding)
```
use fastembed::{TextEmbedding, InitOptions, EmbeddingModel};
# fn model_demo() -> anyhow::Result<()> {
// 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),
)?;
# Ok(())
# }
```
"#
)]
//! Find more info about the available options in the [InitOptions](crate::InitOptions) documentation.
//!
#![cfg_attr(
feature = "online",
doc = r#"
### Embeddings generation
```
# use fastembed::{TextEmbedding, InitOptions, EmbeddingModel};
# fn embedding_demo() -> anyhow::Result<()> {
# let model: TextEmbedding = TextEmbedding::try_new(Default::default())?;
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
# Ok(())
# }
```
"#
)]
mod common;
mod image_embedding;
mod models;
pub mod output;
mod pooling;
mod reranking;
mod sparse_text_embedding;
mod text_embedding;
pub use ort::execution_providers::ExecutionProviderDispatch;
pub use crate::common::{
read_file_to_bytes, Embedding, Error, SparseEmbedding, TokenizerFiles, DEFAULT_CACHE_DIR,
};
pub use crate::image_embedding::{
ImageEmbedding, ImageInitOptions, ImageInitOptionsUserDefined, UserDefinedImageEmbeddingModel,
};
pub use crate::models::image_embedding::ImageEmbeddingModel;
pub use crate::models::reranking::{RerankerModel, RerankerModelInfo};
pub use crate::models::{
model_info::ModelInfo, quantization::QuantizationMode, text_embedding::EmbeddingModel,
};
pub use crate::output::{EmbeddingOutput, OutputKey, OutputPrecedence, SingleBatchOutput};
pub use crate::pooling::Pooling;
pub use crate::reranking::{
OnnxSource, RerankInitOptions, RerankInitOptionsUserDefined, RerankResult, TextRerank,
UserDefinedRerankingModel,
};
pub use crate::sparse_text_embedding::{
SparseInitOptions, SparseTextEmbedding, UserDefinedSparseModel,
};
pub use crate::text_embedding::{
InitOptions, InitOptionsUserDefined, TextEmbedding, UserDefinedEmbeddingModel,
};