mod mock;
mod openai;
mod provider;
#[cfg(feature = "local-embeddings")]
mod local;
pub use openai::OpenAIEmbedder;
pub use provider::EmbeddingProvider;
#[allow(unused_imports)]
pub use mock::MockEmbedder;
#[allow(unused_imports)]
pub use provider::EmbeddingResult;
#[cfg(feature = "local-embeddings")]
pub use local::LocalEmbedder;
use crate::config::{EmbeddingConfig, EmbeddingProvider as ProviderType};
use anyhow::Result;
use std::sync::Arc;
pub fn create_provider(
config: &EmbeddingConfig,
verbose: bool,
) -> Result<Arc<dyn EmbeddingProvider>> {
match config.provider {
ProviderType::OpenAI => {
let api_key = config.get_api_key()?;
Ok(Arc::new(OpenAIEmbedder::new(
&api_key,
&config.openai.model,
&config.openai.base_url,
config.dimensions,
)))
}
ProviderType::Voyage => {
let api_key = config.get_api_key()?;
Ok(Arc::new(OpenAIEmbedder::new(
&api_key,
&config.voyage.model,
&config.voyage.base_url,
config.dimensions,
)))
}
#[cfg(feature = "local-embeddings")]
ProviderType::Local => Ok(Arc::new(LocalEmbedder::new(
&config.local.model,
&config.local.cache_dir,
verbose,
)?)),
#[cfg(not(feature = "local-embeddings"))]
ProviderType::Local => {
anyhow::bail!(
"Local embeddings are not enabled. Rebuild with --features local-embeddings"
)
}
}
}