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
impl EmbedderGate
Sourcepub fn new(
provider: Option<Arc<dyn Embedder>>,
policy: EmbedErrorPolicy,
retry: EmbedRetry,
) -> Self
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).
Sourcepub fn policy(&self) -> EmbedErrorPolicy
pub fn policy(&self) -> EmbedErrorPolicy
What a caller does when the provider cannot be reached.
Sourcepub fn state(&self) -> EmbedderState
pub fn state(&self) -> EmbedderState
Whether there is a provider, and whether it is usable right now.
Sourcepub fn suspend(&self)
pub fn suspend(&self)
Stops calling the provider until Self::resume. Idempotent, and a
no-op when there is no provider.
Sourcepub fn resume(&self)
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.
Sourcepub fn provider(&self) -> Option<Arc<dyn Embedder>>
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”.
Sourcepub fn embed_one(
&self,
text: &str,
check_space: impl FnOnce(&str) -> Result<(), HostError>,
) -> Result<Option<Embedded>, HostError>
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.
Sourcepub fn embed_many(
&self,
texts: &[&str],
check_space: impl FnOnce(&str) -> Result<(), HostError>,
) -> Result<Option<EmbeddedBatch>, HostError>
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.