Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Cache ¶
type Cache struct {
// contains filtered or unexported fields
}
Cache provides semantic caching functionality.
func New ¶
func New(cache SemanticCache, opts ...Option) *Cache
New creates a new cache service.
Required: cache. Optional (via options): WithCacheThreshold (default 0.98), WithLogger, WithCollector.
type CheckResult ¶
CheckResult holds the result of a cache check.
type InMemorySemanticCache ¶
type InMemorySemanticCache struct {
// contains filtered or unexported fields
}
InMemorySemanticCache is a lightweight, concurrent-safe semantic cache. For production, this could be backed by Redis + Vector Search (like RedisVL).
func NewInMemorySemanticCache ¶
func NewInMemorySemanticCache() *InMemorySemanticCache
type Option ¶
type Option func(*Cache)
Option configures a Cache instance.
func WithCacheThreshold ¶
WithCacheThreshold sets the similarity threshold for cache hits.
func WithCollector ¶
func WithCollector(collector observability.Collector) Option
WithSemanticCacheCollector sets an observability collector.
func WithLogger ¶
WithSemanticCacheLogger sets a structured logger.
type SemanticCache ¶
type SemanticCache interface {
// Get retrieves a cached response if the semantic distance of the query vector
// is within the given threshold (e.g., Cosine Similarity > 0.98).
Get(ctx context.Context, queryEmbedding []float32, threshold float32) (string, bool, error)
// Set stores the query vector and its corresponding response in the cache.
Set(ctx context.Context, queryEmbedding []float32, response string) error
}
SemanticCache provides caching for queries based on their vector semantic similarity.