similarity

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Feb 18, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

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

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.

func CosineSimilarity

func CosineSimilarity(a, b []float32) float64

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. Both vectors must have the same length.

Types

type FakeEmbeddingClient

type FakeEmbeddingClient struct {
	// contains filtered or unexported fields
}

FakeEmbeddingClient is a deterministic embedding client for testing. It hashes input text with SHA-256 and uses the hash as a seed to generate reproducible float32 vectors. The vectors are L2-normalized to unit length.

func NewFakeEmbeddingClient

func NewFakeEmbeddingClient(dimension int) *FakeEmbeddingClient

NewFakeEmbeddingClient creates a FakeEmbeddingClient that produces vectors of the given dimension.

func (*FakeEmbeddingClient) Close

func (*FakeEmbeddingClient) Close() error

Close is a no-op for the fake client.

func (*FakeEmbeddingClient) Embed

func (f *FakeEmbeddingClient) Embed(_ context.Context, text string) ([]float32, error)

Embed returns a deterministic, unit-normalized vector for the given text.

func (*FakeEmbeddingClient) EmbedBatch

func (f *FakeEmbeddingClient) EmbedBatch(ctx context.Context, texts []string) ([][]float32, error)

EmbedBatch returns deterministic embeddings for each input text.

Jump to

Keyboard shortcuts

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