Skip to main content

EmbedderGate

Struct EmbedderGate 

Source
pub struct EmbedderGate { /* private fields */ }
Expand description

The embedder, the policy for its failures, and whether it may be called.

One implementation, deliberately, because there are two callers and they must not drift: a read-write crate::Database embeds inside its verbs, and a wrapper over a zero-copy crate::ReadOnlyDatabase embeds the query itself (the reader carries no provider by design). Before this type the second path had no policy at all — a dead provider failed every read in exactly the surface where the memory is only ever read.

Implementations§

Source§

impl EmbedderGate

Source

pub fn new( provider: Option<Arc<dyn Embedder>>, policy: EmbedErrorPolicy, retry: EmbedRetry, ) -> Self

A gate over provider (which may be None — then it does nothing but answer EmbedderState::Absent).

Source

pub fn policy(&self) -> EmbedErrorPolicy

What a caller does when the provider cannot be reached.

Source

pub fn state(&self) -> EmbedderState

Whether there is a provider, and whether it is usable right now.

Source

pub fn suspend(&self)

Stops calling the provider until Self::resume. Idempotent, and a no-op when there is no provider.

Source

pub fn resume(&self)

Calls the provider again. Nothing is verified here: the next embedding finds out, and suspends it again if it is still down.

Source

pub fn provider(&self) -> Option<Arc<dyn Embedder>>

The configured provider, whether or not it is suspended. For the paths that must tell “suspended” from “never configured”.

Source

pub fn embed_one( &self, text: &str, check_space: impl FnOnce(&str) -> Result<(), HostError>, ) -> Result<Option<Embedded>, HostError>

Embeds one text. Ok(None) = carry on without a vector: no provider, a suspended one, or - under EmbedErrorPolicy::Degrade - one that just failed.

check_space runs after the provider is chosen and before it is called, with the space id it would produce. It is where a caller refuses a vector that does not belong in its database, and it is deliberately outside the policy: a space mismatch is never degraded.

Source

pub fn embed_many( &self, texts: &[&str], check_space: impl FnOnce(&str) -> Result<(), HostError>, ) -> Result<Option<EmbeddedBatch>, HostError>

Embeds a whole batch in one provider call. Ok(None) means the same as in Self::embed_one, and means it for the whole batch: a degraded bulk write stores every fact vectorless rather than some of them.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.