Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ComputeKey ¶
func ComputeKey(apiKeyID string, configVersion int64, req *pb.GenerateTextRequest) string
ComputeKey returns a deterministic hash key for an exact-match request. The key includes the calling client's APIKeyID (tenant isolation), the configuration snapshot version (invalidation on rule changes), and canonical request parameters.
func SemanticText ¶
func SemanticText(req *pb.GenerateTextRequest) (string, bool)
SemanticText returns the utterance compared in latent space: the final user message, or the request instruction when there are no messages. Requests ending in tool traffic or non-text parts are not semantically cacheable.
Types ¶
type Cache ¶
type Cache struct {
// contains filtered or unexported fields
}
Cache provides encrypted exact-match caching for LLM completions in Redis.
func New ¶
func New(client *redis.Client, keyring *crypto.Keyring, ttl time.Duration, maxBytes int, prefix string) *Cache
New creates a new Cache instance.
type SemanticCache ¶
type SemanticCache struct {
// contains filtered or unexported fields
}
SemanticCache serves responses for prompts that mean the same thing as an earlier one. Everything except the final user utterance must match exactly (the bucket); only that utterance is compared in latent space.
func NewSemantic ¶
func NewSemantic(client *redis.Client, keyring *crypto.Keyring, enc latent.Encoder, opts SemanticOptions) *SemanticCache
NewSemantic builds a semantic cache over Redis; vectors and responses are encrypted at rest like the exact-match cache, since embeddings can be inverted.
func (*SemanticCache) Get ¶
func (c *SemanticCache) Get(ctx context.Context, apiKeyID string, configVersion int64, req *pb.GenerateTextRequest) (*pb.GenerateTextResponse, float32, bool, error)
Get returns the cached response whose prompt is most similar to req, with its similarity, when that similarity reaches the threshold.
func (*SemanticCache) Set ¶
func (c *SemanticCache) Set(ctx context.Context, apiKeyID string, configVersion int64, req *pb.GenerateTextRequest, resp *pb.GenerateTextResponse) error
Set indexes resp under the latent vector of req's utterance. Responses with tool calls are skipped: their arguments echo specifics of the exact prompt.
type SemanticOptions ¶
type SemanticOptions struct {
// Threshold is the minimum cosine similarity that counts as a hit.
Threshold float64
// MaxEntries bounds how many vectors one bucket keeps and a lookup scans.
MaxEntries int
TTL time.Duration
MaxBytes int
Prefix string
}
SemanticOptions tunes the latent-space cache.