semantic

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Jun 22, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package semantic provides a Redis Stack (RediSearch) vector store used by the semantic cache plugin to look up and persist responses by embedding similarity, scoped per rule via a hashed tag.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Candidate

type Candidate struct {
	Response   string
	Similarity float64
}

Candidate is a cache hit returned by Lookup.

type Entry

type Entry struct {
	RuleID    string
	Embedding *embedding.Embedding
	Response  string
	TTL       time.Duration
}

Entry is a response to persist for future similarity lookups.

type Option

type Option func(*RedisStore)

Option customizes a RedisStore.

func WithIndexName

func WithIndexName(name string) Option

WithIndexName overrides the RediSearch index name.

type RedisStore

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

RedisStore implements Store against Redis Stack RediSearch.

func NewRedisStore

func NewRedisStore(client *redis.Client, logger *slog.Logger, opts ...Option) *RedisStore

NewRedisStore builds a vector store over the given Redis client.

func (*RedisStore) EnsureIndex

func (s *RedisStore) EnsureIndex(ctx context.Context, dimension int) error

EnsureIndex creates the vector index once, tolerating a pre-existing index.

func (*RedisStore) Lookup

func (s *RedisStore) Lookup(ctx context.Context, ruleID string, emb *embedding.Embedding, topK int) ([]Candidate, error)

Lookup returns the topK nearest cached responses for the rule, ordered by descending similarity. A query error degrades to no candidates so the caller can fall through to the upstream.

func (*RedisStore) Store

func (s *RedisStore) Store(ctx context.Context, entry Entry) error

Store persists a response keyed by its embedding under the rule's tag.

type Store

type Store interface {
	EnsureIndex(ctx context.Context, dimension int) error
	Lookup(ctx context.Context, ruleID string, emb *embedding.Embedding, topK int) ([]Candidate, error)
	Store(ctx context.Context, entry Entry) error
}

Store is the vector cache backing the semantic cache plugin.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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