pub struct OpenAICompatibleEmbeddingEngine { /* private fields */ }Expand description
Embedding engine that calls an OpenAI-compatible /v1/embeddings HTTP endpoint.
Works with:
- OpenAI (
https://api.openai.com) - Azure OpenAI (set
api_versionin config) - vLLM, llama.cpp, TEI, LocalAI (any OpenAI-compatible server)
§URL normalisation
The base_url is derived from config.endpoint and is always normalised to
end with /v1 so that the final request URL is {base_url}/embeddings.
The following transformations are applied in order:
- Strip a trailing
/ - If the URL ends with
/v1/embeddings, strip the/embeddingssuffix. - If the URL does not end with
/v1, append/v1.
§Retry behaviour
Transient errors (HTTP 429, 5xx, network errors) are retried with
exponential back-off (starting at 2 s, doubling up to 128 s, plus
a uniform random jitter in [0, wait_secs)) for up to 128 s total.
Implementations§
Source§impl OpenAICompatibleEmbeddingEngine
impl OpenAICompatibleEmbeddingEngine
Sourcepub fn new(config: &EmbeddingConfig) -> EmbeddingResult<Self>
pub fn new(config: &EmbeddingConfig) -> EmbeddingResult<Self>
Construct a new engine from the given EmbeddingConfig.
Returns EmbeddingError::ConfigError if the reqwest client cannot
be built (e.g. invalid TLS configuration).
Trait Implementations§
Source§impl EmbeddingEngine for OpenAICompatibleEmbeddingEngine
impl EmbeddingEngine for OpenAICompatibleEmbeddingEngine
Source§fn embed<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
texts: &'life1 [&'life2 str],
) -> Pin<Box<dyn Future<Output = EmbeddingResult<Vec<Vec<f32>>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn embed<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
texts: &'life1 [&'life2 str],
) -> Pin<Box<dyn Future<Output = EmbeddingResult<Vec<Vec<f32>>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Embed a batch of text strings into normalized vectors Read more
Source§fn dimension(&self) -> usize
fn dimension(&self) -> usize
Get the dimensionality of embeddings produced by this engine Read more
Source§fn batch_size(&self) -> usize
fn batch_size(&self) -> usize
Get the optimal batch size for this engine Read more
Source§fn max_sequence_length(&self) -> usize
fn max_sequence_length(&self) -> usize
Get the maximum sequence length (in tokens) supported Read more
Auto Trait Implementations§
impl !RefUnwindSafe for OpenAICompatibleEmbeddingEngine
impl !UnwindSafe for OpenAICompatibleEmbeddingEngine
impl Freeze for OpenAICompatibleEmbeddingEngine
impl Send for OpenAICompatibleEmbeddingEngine
impl Sync for OpenAICompatibleEmbeddingEngine
impl Unpin for OpenAICompatibleEmbeddingEngine
impl UnsafeUnpin for OpenAICompatibleEmbeddingEngine
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more