Documentation
¶
Index ¶
Constants ¶
const EnvPrefix = "VLSH"
Variables ¶
var ( ErrEmptyVector = errors.New("empty vector") ErrWrongDimension = errors.New("vector dimension does not match config") )
Functions ¶
func EstimateCosine ¶
EstimateCosine estimates cosine similarity from two binary (hyperplane) signatures. P(same sign) = 1 - angle/pi → cosine = cos(pi * (1 - matchFraction)).
func ExactCosine ¶
ExactCosine computes the exact cosine similarity between two vectors.
Types ¶
type Config ¶
type Config struct {
lsh.Config
VectorDimensions int `env:"_VECTOR_DIMENSIONS" envDefault:"20"`
CosineThreshold float64 `env:"_COS_THRESHOLD" envDefault:"0.5"`
}
func GetConfigFromEnv ¶
func (*Config) CalculateApproximateThreshold ¶
CalculateApproximateThreshold returns the cosine similarity where the LSH collision probability transitions sharply for the given Bands/Rows config.
P(one band) = (1 - arccos(s)/pi)^R P(any band) = 1 - (1 - P(one band))^B
We find s where P(any band) ~ 0.5 using binary search.
func (*Config) HashVersion ¶
HashVersion computes a deterministic prefix from group + all config fields.
type Hasher ¶
type Hasher struct {
// contains filtered or unexported fields
}
func (*Hasher) ComputeSignature ¶
ComputeSignature produces a binary signature from a feature vector. Each bit = sign of dot product with a random hyperplane.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
func NewService ¶
func NewService(repo repositories.Storage, config *Config) (*Service, error)
func (*Service) GetNewID ¶
GetNewID returns a deterministic ID derived from the vector content (SHA256, base64url).
func (*Service) Upsert ¶
Upsert assigns a behavioural ID to the given vector. Returns the existing representative's ID if cosine >= threshold, or a new ID if novel.
func (*Service) WithMetrics ¶
func (s *Service) WithMetrics(m *lsh.Instruments)
WithMetrics injects pre-built OpenTelemetry instruments. If not called, metrics are silently skipped.