mem0_rust/embeddings/
mod.rs1mod mock;
10mod traits;
11mod huggingface;
12
13pub use mock::MockEmbedder;
14pub use traits::Embedder;
15pub use huggingface::HuggingFaceEmbedder;
16
17#[cfg(feature = "openai")]
18mod openai;
19#[cfg(feature = "openai")]
20pub use openai::OpenAIEmbedder;
21
22#[cfg(feature = "ollama")]
23mod ollama;
24#[cfg(feature = "ollama")]
25pub use ollama::OllamaEmbedder;
26
27use crate::config::EmbedderConfig;
28use crate::errors::EmbeddingError;
29use std::sync::Arc;
30
31pub fn create_embedder(config: &EmbedderConfig) -> Result<Arc<dyn Embedder>, EmbeddingError> {
33 match config {
34 EmbedderConfig::Mock(cfg) => Ok(Arc::new(MockEmbedder::new(cfg.dimensions))),
35
36 #[cfg(feature = "openai")]
37 EmbedderConfig::OpenAI(cfg) => Ok(Arc::new(OpenAIEmbedder::new(cfg.clone())?)),
38
39 #[cfg(feature = "ollama")]
40 EmbedderConfig::Ollama(cfg) => Ok(Arc::new(OllamaEmbedder::new(cfg.clone()))),
41
42 EmbedderConfig::HuggingFace(cfg) => {
43 Ok(Arc::new(HuggingFaceEmbedder::new(cfg.clone())?))
44 }
45 }
46}