pub trait Embedder: Send + Sync {
// Required methods
fn id(&self) -> &str;
fn capabilities(&self, model: &ModelId) -> Option<EmbeddingCapabilities>;
fn embed<'life0, 'async_trait>(
&'life0 self,
request: EmbedRequest,
) -> Pin<Box<dyn Future<Output = Result<Embeddings>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
// Provided method
fn validate<'life0, 'life1, 'async_trait>(
&'life0 self,
_model: &'life1 ModelId,
) -> Pin<Box<dyn Future<Output = Access> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait { ... }
}embeddings only.Expand description
Something that can turn text into vectors.
§Implementing one
Four rules, and the first two are the ones that fail quietly.
- The reply is index for index with the request. Sort by whatever index field the vendor sends rather than trusting arrival order. Getting this wrong pairs every document with another document’s vector, and every later query still returns results.
- Every
Embeddingcarries the model that served it, from the reply rather than from the request. It is what stops two embedding spaces being compared as one. - Do not invent usage.
Usage::absentwhen the provider reported nothing, andUsage::embeddingwhen it reported prompt tokens — never zeros. embedtakes&self, so anything shared must be immutable after construction or behind an atomic, exactly as forcrate::Provider.
Required Methods§
Sourcefn capabilities(&self, model: &ModelId) -> Option<EmbeddingCapabilities>
fn capabilities(&self, model: &ModelId) -> Option<EmbeddingCapabilities>
What this model can do when reached through this embedder.
None for a model it does not recognise, which is a different answer from one it
knows and has nothing to offer for.
Sourcefn embed<'life0, 'async_trait>(
&'life0 self,
request: EmbedRequest,
) -> Pin<Box<dyn Future<Output = Result<Embeddings>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn embed<'life0, 'async_trait>(
&'life0 self,
request: EmbedRequest,
) -> Pin<Box<dyn Future<Output = Result<Embeddings>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Turns some text into vectors.
§Errors
See crate::Error. A reply the provider sent and this crate could not read is an
crate::Error::Unreadable, never a short list of vectors: a batch that comes back
with fewer vectors than it had inputs cannot be lined up, and guessing which input
was dropped is worse than failing.
Provided Methods§
Sourcefn validate<'life0, 'life1, 'async_trait>(
&'life0 self,
_model: &'life1 ModelId,
) -> Pin<Box<dyn Future<Output = Access> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn validate<'life0, 'life1, 'async_trait>(
&'life0 self,
_model: &'life1 ModelId,
) -> Pin<Box<dyn Future<Output = Access> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Whether a request for this model would be accepted, without sending one.
The same two rules as crate::Provider::validate: it must not cost anything, and it
must not report a rejected credential as Access::Unknown. The default answers
Unknown, which is the honest answer for an embedder with nothing free to ask.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".
Implementors§
impl Embedder for GeminiEmbeddings
gemini only.impl Embedder for OpenAiEmbeddings
openai and (crate features cli or openai) only.