similarity

package
v0.69.0 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2026 License: Apache-2.0 Imports: 12 Imported by: 0 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 similarity provides vector distance functions for semantic search.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CosineDistance

func CosineDistance(a, b []float32) (float64, error)

CosineDistance computes the cosine distance between two vectors. Returns a value in [0, 2] where 0 means identical direction and 2 means opposite direction. Lower values indicate more similar vectors. Vectors of different lengths return an error (see CosineSimilarity).

func CosineSimilarity

func CosineSimilarity(a, b []float32) (float64, error)

CosineSimilarity computes the cosine similarity between two vectors. Returns a value in [-1, 1] where 1 means identical direction, 0 means orthogonal, and -1 means opposite direction.

Vectors of different lengths return an error. The guard lives here rather than at the call sites because the loop below indexes both slices positionally: a shorter b would panic and a longer b would silently ignore its tail, and a caller that forgets its own check gets one or the other.

func NewEmbeddingClient added in v0.10.1

func NewEmbeddingClient(cfg *types.OptimizerConfig) (types.EmbeddingClient, error)

NewEmbeddingClient creates an EmbeddingClient from the given optimizer configuration, selecting the backend implementation from EmbeddingProvider. It returns (nil, nil) if cfg is nil or no embedding service URL is configured, meaning semantic search will be disabled.

Types

This section is empty.

Jump to

Keyboard shortcuts

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