modo/embed/backend.rs
1use std::pin::Pin;
2
3use crate::error::Result;
4
5/// Trait for embedding providers.
6///
7/// Implementations call an external embedding API and return the result as a
8/// little-endian f32 byte blob ready for libsql `F32_BLOB` columns.
9///
10/// The built-in providers are [`super::OpenAIEmbedding`],
11/// [`super::GeminiEmbedding`], [`super::MistralEmbedding`], and
12/// [`super::VoyageEmbedding`]. Custom providers implement this trait directly.
13pub trait EmbeddingBackend: Send + Sync {
14 /// Embed a single text string.
15 ///
16 /// Returns a little-endian f32 byte blob of length `dimensions() * 4`.
17 fn embed(&self, input: &str) -> Pin<Box<dyn Future<Output = Result<Vec<u8>>> + Send + '_>>;
18
19 /// Number of dimensions this provider/model produces.
20 fn dimensions(&self) -> usize;
21
22 /// Model identifier string (e.g. `"text-embedding-3-small"`).
23 fn model_name(&self) -> &str;
24}