semantic_cache

package
v0.0.0-...-30b4b00 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 5, 2026 License: AGPL-3.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CacheKeyFromBody

func CacheKeyFromBody(model string, body []byte, userGroup string) string

CacheKeyFromBody generates cache key from model, request body and user group

func Init

func Init(cfg *Config)

Init initializes the global semantic cache instance with the given config. If cfg is nil, the default config will be used. Uses its own once so it always takes effect regardless of GetSemanticCacheV2 call order.

func Lookup

func Lookup(ctx context.Context, model string, body []byte, userGroup string) ([]byte, bool)

Lookup performs semantic cache lookup (package-level wrapper)

func Store

func Store(ctx context.Context, model string, body []byte, response []byte, userGroup string)

Store saves a response to the semantic cache (package-level wrapper)

Types

type CacheStats

type CacheStats struct {
	Hits   int64
	Misses int64
	L1Hits int64
	L2Hits int64
	// contains filtered or unexported fields
}

CacheStats tracks cache performance

type Config

type Config struct {
	Enabled             bool
	SimilarityThreshold float32
	TTL                 int64
	MaxEntries          int64
	// BypassModels lists models that should skip semantic cache
	BypassModels map[string]bool
	// CacheOnlyModels if non-empty, ONLY these models use semantic cache
	CacheOnlyModels map[string]bool
}

Config holds semantic cache configuration

func DefaultConfig

func DefaultConfig() *Config

DefaultConfig returns default configuration

func GetConfig

func GetConfig() *Config

GetConfig returns the current semantic cache configuration

type SemanticCacheV2

type SemanticCacheV2 struct {
	// contains filtered or unexported fields
}

SemanticCacheV2 provides hybrid semantic caching L1: Redis exact match (fast) L2: Vector similarity search (accurate)

func GetSemanticCacheV2

func GetSemanticCacheV2() *SemanticCacheV2

GetSemanticCacheV2 returns the default hybrid cache instance

func NewSemanticCacheV2

func NewSemanticCacheV2(cfg *Config, redisClient *redis.Client) *SemanticCacheV2

NewSemanticCacheV2 creates a new hybrid semantic cache

func (*SemanticCacheV2) GetStats

func (c *SemanticCacheV2) GetStats() map[string]interface{}

GetStats returns cache statistics

func (*SemanticCacheV2) Lookup

func (c *SemanticCacheV2) Lookup(ctx context.Context, model string, body []byte, userGroup string) ([]byte, bool)

Lookup checks both L1 and L2 cache

func (*SemanticCacheV2) Stop

func (c *SemanticCacheV2) Stop()

Stop gracefully stops background goroutines.

func (*SemanticCacheV2) Store

func (c *SemanticCacheV2) Store(ctx context.Context, model string, body []byte, response []byte, userGroup string) error

Store saves a response to both cache layers

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL