use std::fmt;
use crate::FastEmbedOptions;
#[derive(Debug)]
pub enum FastEmbedError {
UnsupportedTarget,
UnknownModel(String),
Init(String),
Embed(String),
MutexPoisoned(String),
TaskPanicked(String),
}
impl fmt::Display for FastEmbedError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::UnsupportedTarget => write!(
f,
"fastembed backend unavailable on this target (no ort-sys \
prebuilt); use the tract backend via blazen-embed"
),
Self::UnknownModel(msg) => write!(f, "unknown fastembed model: {msg}"),
Self::Init(msg) => write!(f, "fastembed init failed: {msg}"),
Self::Embed(msg) => write!(f, "fastembed embed failed: {msg}"),
Self::MutexPoisoned(msg) => write!(f, "fastembed mutex poisoned: {msg}"),
Self::TaskPanicked(msg) => write!(f, "fastembed blocking task panicked: {msg}"),
}
}
}
impl std::error::Error for FastEmbedError {}
#[derive(Debug, Clone)]
pub struct FastEmbedResponse {
pub embeddings: Vec<Vec<f32>>,
pub model: String,
}
pub struct FastEmbedModel {
_never: std::convert::Infallible,
}
impl FastEmbedModel {
pub fn from_options(_opts: FastEmbedOptions) -> Result<Self, FastEmbedError> {
tracing::warn!(
"FastEmbedModel::from_options called on a target without an \
ort-sys prebuilt (e.g. x86_64-apple-darwin) — returning \
UnsupportedTarget. Switch to blazen-embed-tract."
);
Err(FastEmbedError::UnsupportedTarget)
}
#[must_use]
pub fn model_id(&self) -> &str {
match self._never {}
}
#[must_use]
pub fn dimensions(&self) -> usize {
match self._never {}
}
pub async fn embed(&self, _texts: &[String]) -> Result<FastEmbedResponse, FastEmbedError> {
match self._never {}
}
}