Documentation
¶
Index ¶
Constants ¶
const ( LibraryName = "scriptling.similarity" LibraryDesc = "String matching and similarity utilities including fuzzy search and MinHash" )
Variables ¶
var ( ErrDimensionMismatch = errors.New("vectors must have the same length") ErrEmptyVector = errors.New("vectors must not be empty") )
Functions ¶
func CosineSimilarity ¶ added in v0.17.0
CosineSimilarity computes the cosine of the angle between two vectors. Returns 0.0 if either vector has zero magnitude.
func ToFloat64Slice ¶ added in v0.17.0
ToFloat64Slice converts a scriptling Object (FloatArray or List of numbers) to a []float64. Shared by ai and similarity libraries.
func VectorFromText ¶ added in v0.17.0
VectorFromText produces a fixed-dimensional vector from text using the feature-hashing trick (the "hashing trick"). Each token is mapped to a dimension via FNV-1a and contributes +1 or −1 based on a sign hash. The resulting vector is L2-normalised so it can be compared directly with CosineSimilarity. This is a fast, deterministic, CPU-only method that captures lexical overlap — similar texts produce similar vectors.
Types ¶
type ScoredVector ¶ added in v0.17.0
ScoredVector is a ranked result from MostSimilar.
func MostSimilar ¶ added in v0.17.0
func MostSimilar(query []float64, vectors [][]float64, topK int) []ScoredVector
MostSimilar ranks vectors by cosine similarity to query, returning the top-k results sorted by descending score. If topK <= 0 all results are returned.