Skip to main content

PooledSemanticCache

Struct PooledSemanticCache 

Source
pub struct PooledSemanticCache<V = CachedAnswer> { /* private fields */ }
Available on crate feature pool only.
Expand description

One inference node’s view of the pool’s shared semantic cache (and, with with_exact, of its exact entries).

  • lookup: L1, then the shard’s home (this node’s own cache when it is the home), then the replica if the home is unreachable. Never fails because of a peer.
  • insert: this node’s own cache when it holds the shard, the home (waited for, bounded), the replica in the background, and L1.
  • remove_scope: everywhere, every member (so entries left behind by a membership change go too).

Members come from the app (set_nodes, join, leave), for example the pool’s inference nodes from the roster; every node must use the same ids, and must use the same embedding model and revision. Serve host on PROTOCOL so the others can reach this node’s shards.

Implementations§

Source§

impl<V> PooledSemanticCache<V>
where V: Clone + Serialize + DeserializeOwned + Send + Sync + 'static,

Source

pub fn new( node: impl Into<String>, shard: Arc<SemanticCache<V>>, transport: Arc<dyn CacheTransport<V>>, config: PoolConfig, ) -> Self

This node is node (its id in the ring), keeps the shards it holds in shard, and reaches the others over transport. The ring starts with this node alone.

Source

pub fn with_exact(self, store: Arc<dyn AnswerStore>) -> Self

Shares exact entries too, keeping this node’s in store.

Source

pub fn node(&self) -> &str

This node’s id.

Source

pub fn config(&self) -> &PoolConfig

Source

pub fn shard(&self) -> &Arc<SemanticCache<V>> ⓘ

The shards this node holds.

Source

pub fn host(&self) -> SharedCacheHost<V>

Serves this node’s shards to the others (see serve).

Source

pub fn ring(&self) -> ShardRing

The current members.

Source

pub fn set_nodes<I, S>(&self, nodes: I)
where I: IntoIterator<Item = S>, S: Into<String>,

Replaces the members (usually including this node; without it, this node holds no shards and only asks).

Source

pub fn join(&self, node: impl Into<String>) -> bool

Adds a member; false when it already was one.

Source

pub fn leave(&self, node: &str) -> bool

Removes a member; false when it wasn’t one.

Source

pub fn plan(&self, shard: impl AsRef<[u8]>) -> Option<ShardPlan>

The home and replica for scope (or an exact key) now.

Source

pub fn is_down(&self, node: &str) -> bool

node was marked down after a failure and is being skipped.

Source

pub fn stats(&self) -> PoolStats

Source

pub async fn settle(&self)

Waits until background writes have finished (each is bounded by the write timeout).

Source

pub async fn lookup( &self, scope: &str, embedding: &[f32], ) -> Result<PoolLookup<V>, SemanticError>

The most similar entry for embedding in scope, wherever in the pool it lives. Errors only for an embedding no cache would take (empty, not finite, zero, wrong dimension for this node’s own cache); peer failures are misses.

Source

pub async fn insert( &self, scope: &str, embedding: &[f32], value: V, ) -> Result<PoolWrite, SemanticError>

Stores value under embedding in scope on the shard’s owners. Errors only for an embedding no cache would take; peer failures show in the PoolWrite.

Source

pub async fn remove_scope(&self, scope: &str) -> PoolWrite

Drops every entry in scope here and on every member (waited for, bounded).

Source

pub async fn exact_get(&self, key: &Key) -> Option<Vec<u8>>

The exact entry under key (see exact_key_rev) from its home, or its replica when the home is unreachable. None without with_exact.

Source

pub async fn exact_put(&self, key: &Key, value: Vec<u8>) -> PoolWrite

Stores an exact entry on its home (waited for, bounded) and replica (in the background). Nothing is stored without with_exact.

Trait Implementations§

Source§

impl<V> Debug for PooledSemanticCache<V>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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> 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> Same for T

Source§

type Output = T

Should always be Self
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.