Documentation
¶
Overview ¶
Package cache wraps a types.Embedder with a hot-path LRU cache so repeated embed calls on the same text return without paying the model cost.
Use case: the agent issues semantic_search with the same intent multiple times during a multi-hop flow, and explain_match re-embeds the intent to compare each candidate. The cache keeps both hot.
The cache is intentionally in-process and not persisted — the embeddings depend on model identity, which changes when the user swaps backends. Restart clears the cache, which is the correct behavior.
Index ¶
Constants ¶
const DefaultSize = 1024
DefaultSize is the cache capacity when the caller does not specify. 1024 entries × 1024-dim × 4 bytes ≈ 4 MB per cache instance for the stored vectors plus a small per-entry book-keeping overhead.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Cached ¶
type Cached struct {
// contains filtered or unexported fields
}
Cached wraps an inner Embedder. Cache hits return immediately from memory; misses pass through to inner.Embed and store the result.
func (*Cached) Embed ¶
Embed checks the cache for each batch entry, calls the inner embedder only for misses, and stores all results before returning.