pub struct PooledSemanticCache<V = CachedAnswer> { /* private fields */ }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>
impl<V> PooledSemanticCache<V>
Sourcepub fn new(
node: impl Into<String>,
shard: Arc<SemanticCache<V>>,
transport: Arc<dyn CacheTransport<V>>,
config: PoolConfig,
) -> Self
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.
Sourcepub fn with_exact(self, store: Arc<dyn AnswerStore>) -> Self
pub fn with_exact(self, store: Arc<dyn AnswerStore>) -> Self
Shares exact entries too, keeping this node’s in store.
pub fn config(&self) -> &PoolConfig
Sourcepub fn shard(&self) -> &Arc<SemanticCache<V>> ⓘ
pub fn shard(&self) -> &Arc<SemanticCache<V>> ⓘ
The shards this node holds.
Sourcepub fn host(&self) -> SharedCacheHost<V>
pub fn host(&self) -> SharedCacheHost<V>
Serves this node’s shards to the others (see serve).
Sourcepub fn set_nodes<I, S>(&self, nodes: I)
pub fn set_nodes<I, S>(&self, nodes: I)
Replaces the members (usually including this node; without it, this node holds no shards and only asks).
Sourcepub fn join(&self, node: impl Into<String>) -> bool
pub fn join(&self, node: impl Into<String>) -> bool
Adds a member; false when it already was one.
Sourcepub fn plan(&self, shard: impl AsRef<[u8]>) -> Option<ShardPlan>
pub fn plan(&self, shard: impl AsRef<[u8]>) -> Option<ShardPlan>
The home and replica for scope (or an exact key) now.
Sourcepub fn is_down(&self, node: &str) -> bool
pub fn is_down(&self, node: &str) -> bool
node was marked down after a failure and is being skipped.
pub fn stats(&self) -> PoolStats
Sourcepub async fn settle(&self)
pub async fn settle(&self)
Waits until background writes have finished (each is bounded by the write timeout).
Sourcepub async fn lookup(
&self,
scope: &str,
embedding: &[f32],
) -> Result<PoolLookup<V>, SemanticError>
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.
Sourcepub async fn insert(
&self,
scope: &str,
embedding: &[f32],
value: V,
) -> Result<PoolWrite, SemanticError>
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.
Sourcepub async fn remove_scope(&self, scope: &str) -> PoolWrite
pub async fn remove_scope(&self, scope: &str) -> PoolWrite
Drops every entry in scope here and on every member (waited for, bounded).
Sourcepub async fn exact_get(&self, key: &Key) -> Option<Vec<u8>>
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.