vector

package
v0.1.6 Latest Latest
Warning

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

Go to latest
Published: May 18, 2025 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package vector provides vector embedding utilities and text embedding within the ProjectMemory service.

Index

Constants

View Source
const (
	// DefaultEmbeddingDimensions defines the standard size of embedding vectors.
	// 1536 is a common size for modern embedding models.
	DefaultEmbeddingDimensions = 1536

	// DefaultBatchSize defines how many embeddings can be processed in a single batch.
	DefaultBatchSize = 8
)

Variables

This section is empty.

Functions

func BytesToFloat32Slice

func BytesToFloat32Slice(data []byte) ([]float32, error)

BytesToFloat32Slice converts a byte slice to a slice of float32.

func CosineSimilarity

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

CosineSimilarity calculates the cosine similarity between two vectors. The result is a value between -1 and 1, where 1 means the vectors are identical, 0 means they are orthogonal, and -1 means they are opposite.

func Float32SliceToBytes

func Float32SliceToBytes(floats []float32) ([]byte, error)

Float32SliceToBytes converts a slice of float32 to a byte slice.

Types

type Embedder

type Embedder interface {
	// CreateEmbedding converts text into a vector representation.
	CreateEmbedding(text string) ([]float32, error)

	// Initialize sets up the embedder with any required configuration.
	Initialize() error
}

Embedder defines the interface for creating vector embeddings from text.

type MockEmbedder

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

MockEmbedder is a simple implementation of the Embedder interface. It creates deterministic but simplistic embeddings for testing purposes.

func NewMockEmbedder

func NewMockEmbedder(dimensions int) *MockEmbedder

NewMockEmbedder creates a new MockEmbedder with the specified dimensions.

func (*MockEmbedder) CreateEmbedding

func (e *MockEmbedder) CreateEmbedding(text string) ([]float32, error)

CreateEmbedding generates a mock embedding for the given text. It uses a deterministic algorithm based on MD5 hashing to ensure that the same text always produces the same embedding.

func (*MockEmbedder) Initialize

func (e *MockEmbedder) Initialize() error

Initialize sets up the embedder with any required configuration.

Jump to

Keyboard shortcuts

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