vector

package
v1.8.9 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2026 License: Apache-2.0 Imports: 10 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

func ItemID(tenant, question string) string

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

func NewChromaProvider(cfg Config) (*chromaProvider, error)

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.

Jump to

Keyboard shortcuts

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