Skip to main content

mem7_embedding/
lib.rs

1mod openai;
2
3pub use openai::OpenAICompatibleEmbedding;
4
5use std::sync::Arc;
6
7use async_trait::async_trait;
8use mem7_config::EmbeddingConfig;
9use mem7_error::{Mem7Error, Result};
10
11#[async_trait]
12pub trait EmbeddingClient: Send + Sync {
13    async fn embed(&self, texts: &[String]) -> Result<Vec<Vec<f32>>>;
14}
15
16/// Create an embedding client from config. All OpenAI-compatible providers
17/// (OpenAI, Ollama, vLLM, LM Studio, DeepSeek, etc.) share the same client.
18pub fn create_embedding(config: &EmbeddingConfig) -> Result<Arc<dyn EmbeddingClient>> {
19    match config.provider.as_str() {
20        "openai" | "ollama" | "vllm" | "lmstudio" | "deepseek" => {
21            Ok(Arc::new(OpenAICompatibleEmbedding::new(config.clone())))
22        }
23        other => Err(Mem7Error::Config(format!(
24            "unknown embedding provider: {other}"
25        ))),
26    }
27}