Expand description
Answer cache for Weirdnet inference nodes.
An inference node asks an AnswerCache before it routes a prompt and offers it the finished
answer afterwards. The cache decides what it keeps and when a stored answer may stand in.
-
AnswerCache: the seam (get,put) overweirdnet-agentinfer/2Requests. -
AnswerStore: where cached answers live, as opaque bytes under 32-byte keys, so a store can be in memory, on disk or shared.MemoryStoreis bounded and least-recently-used. -
ExactCache: answers only requests identical to a stored one that are deterministic (temperature 0, no tools, inline messages) for the same model, and keeps only answers that finished (stoporlength). -
NoCache: caches nothing. -
may_read/may_store: the request’s ownCacheMode(weirdnet-agent0.5.1):bypassneither reads nor stores,refreshskips the read and stores the fresh answer.ExactCachehonours both. -
Revisions:
AnswerCache::get_rev/AnswerCache::put_revandexact_key_revkey an answer on the model’s weights as well as its id, so a fine-tuned model under the same id doesn’t replay answers from the old weights. -
SemanticCache: similarity lookup by embedding. The caller embeds the prompt; the nearest stored embedding in the same scope (seescope_key) stands in when its cosine similarity reaches the threshold. Bounded and least-recently-used, with an optional TTL and a CBORsnapshot/restore.
Pool mode, several inference nodes sharing one cache (since 0.2.3):
ShardRing/ShardPlan: rendezvous hashing of a scope (or an exactKey) to a home node and one replica; joins and leaves move only the shards they must.SharedCacheReq/SharedCacheResp: the CBOR lookup / insert / remove protocol (PROTOCOL), andSharedCacheHost, which answers it from a node’s own cache.- With the
poolfeature,pool::PooledSemanticCache(L1, the home, the replica on failure, bounded timeouts, background replica writes, a miss whenever peers fail) over apool::CacheTransport, andpool::serve/pool::DialerTransportoverweirdnet-agentchannels.
Modules§
- pool
pool - Pool mode: inference nodes sharing one cache (
PooledSemanticCache), over anyCacheTransport(DialerTransportforweirdnet-agentchannels, served byserve).
Structs§
- Cached
Answer - A stored answer, replayed instead of running the model.
- Exact
Cache - Exact-match cache for deterministic requests over an
AnswerStore. - Host
Limits - What a
SharedCacheHostaccepts from other nodes. - Memory
Store - In-memory store holding at most
max_entries, evicting the least recently used. - NoCache
- Caches nothing.
- Semantic
Cache - Embedding-similarity cache: the nearest stored embedding in the same scope, by cosine similarity, stands in when it reaches the threshold.
- Semantic
Config - How a
SemanticCachematches and evicts. - Semantic
Stats - Counters since the cache was made or last
cleared. - Shard
Plan - The home node and replica for one shard, from
ShardRing::plan. - Shard
Ring - The inference nodes that share a cache, and which of them holds each shard.
- Shared
Cache Host - Answers shared-cache requests from this node’s own cache: the shards it holds.
Enums§
- Lookup
- The result of
SemanticCache::lookup. - Semantic
Error - Why a
SemanticCachecall was refused. - Shared
Cache Req - A shared-cache request, sent to the node that holds the shard.
- Shared
Cache Resp - The answer to a
SharedCacheReq.
Constants§
- DEFAULT_
THRESHOLD - Similarity a lookup needs to hit when none is configured.
- PROTOCOL
- The protocol name nodes serve the shared cache on.
- WIRE_
VERSION - The message version this crate writes and reads.
Traits§
- Answer
Cache - What an inference node asks before and after routing a prompt.
- Answer
Store - Where cached answers live. Values are opaque bytes; a store may drop entries at any time.
Functions§
- cosine_
similarity - Cosine similarity of two embeddings, or
Nonewhen either is empty, not finite or zero, or their dimensions differ. - deterministic
- Requests an exact cache may answer: temperature 0, no tools, inline messages.
- exact_
key - The key for
requestonmodel, orNonewhen it is notdeterministic. The same asexact_key_revwith no revision. - exact_
key_ rev - The key for
requestonmodelat weightsrevision, orNonewhen it is notdeterministic. With no revision the key is the 0.2.0 one (v: 1), so stored answers still hit; with one it is av: 2key that includes it. The request’sCacheModeis not part of the key, sorefreshoverwrites the entryusereads. - may_
read - The request lets a cache answer it (
CacheMode::Use). - may_
store - The request lets a cache keep its answer (
CacheMode::UseorCacheMode::Refresh). - normalize
embeddingscaled to unit length, after checking it is non-empty, finite and not zero.- scope_
key - A stable scope for
SemanticCache: hex SHA-256 over the length-prefixedparts, such as the model id, its revision and a hash of the system prompt. Different parts (or the same text split differently) give different scopes.
Type Aliases§
- Key
- A cache key: SHA-256 over the model and the parts of the request that shape the answer.