Documentation
¶
Overview ¶
Package vector abstracts the vector store used by the semantic cache of mod_ai_cache.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ItemID ¶
ItemID returns the deterministic record id for a (tenant, question) pair: sha256(tenant + "\n" + question) in hex. Uploading the same pair twice overwrites the same record, which makes the write-back idempotent.
func NewChromaProvider ¶
NewChromaProvider connects to a Chroma server: it probes the heartbeat, gets or creates the collection (cosine space) and returns the provider. Any failure is returned to the caller, which is expected to disable the semantic cache (fail-open).
Types ¶
type Config ¶
type Config struct {
ServiceHost string
ServicePort int
ApiKey string // bearer credential, never logged
Collection string
TimeoutMs int
}
Config carries the connection info of a Chroma server.
type Item ¶
type Item struct {
ID string // deterministic id: sha256(tenant + "\n" + question), upsert is idempotent
Tenant string // = ClientKeyId
Question string // question text
Answer string // final answer (stored inline, returned on semantic hit)
Embedding []float32
CreatedAt time.Time
}
Item is a single cache record written to the vector store.
type Result ¶
type Result struct {
ID string
Question string
Answer string
Score float64 // native score of the store (distance or similarity)
Similarity float64 // normalized to [0,1], the higher the more similar, for logging only
}
Result is a single nearest neighbor returned by the vector store.
type VectorProvider ¶
type VectorProvider interface {
// Query returns at most topK nearest records of the embedding. The
// results must be limited to the tenant, and only records whose
// created_at is within ttl may be returned (ttl <= 0 means no expiry).
// Results are ordered best-first; only the first result is judged
// against the threshold by the caller.
Query(embedding []float32, tenant string, topK int, ttl time.Duration) ([]Result, error)
// Upload inserts or updates a record (same id overwrites).
Upload(item Item) error
}
VectorProvider abstracts a vector store backend. Implementations must enforce the configured timeout internally.