Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CacheStats ¶
type CacheStats struct {
Hits int64 `json:"hits"`
Misses int64 `json:"misses"`
Size int `json:"size"`
HitRate float64 `json:"hit_rate"`
}
CacheStats represents the basic metrics of cache
type Embedding ¶
type Embedding struct {
// contains filtered or unexported fields
}
Embedding prevents the recomputation for repeated texts
func NewEmbedding ¶
NewEmbedding creates a new instance of Embedding
func (*Embedding) Get ¶
Get retrieves the embedding for the given text from the cache. It returns the embedding and a boolean indicating if the key was found.
func (*Embedding) Stats ¶
func (c *Embedding) Stats() CacheStats
type ResponseCache ¶
type ResponseCache struct {
// contains filtered or unexported fields
}
ResponseCache stores the complete responses by normalized hash
func NewResponseCache ¶
func NewResponseCache(ttl, cleanup time.Duration, maxItems int) *ResponseCache
NewResponseCache creates a new instance of ResponseCache
func (*ResponseCache) Get ¶
func (c *ResponseCache) Get(text, historyKey string) (*models.ChatResponse, bool)
Get retrieves the cached response for a given text and history key. It returns the cloned response and a boolean indicating if the key was found.
func (*ResponseCache) Invalidate ¶
func (c *ResponseCache) Invalidate(pattern string)
Invalidate removes items from the cache that match a specific pattern. If the pattern is empty, it flushes the entire cache.
func (*ResponseCache) Set ¶
func (c *ResponseCache) Set( text string, historyKey string, resp *models.ChatResponse, shortTools, mediumTools map[string]struct{}, )
Set stores the response for the given text and history key in the cache. It handles eviction if the cache size exceeds maxItems and determines TTL based on tool usage.
func (*ResponseCache) Stats ¶
func (c *ResponseCache) Stats() CacheStats
Stats returns the current metrics of the response cache.