Documentation
¶
Overview ¶
Package vector provides vector embedding utilities and text embedding within the ProjectMemory service.
Index ¶
Constants ¶
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 ¶
BytesToFloat32Slice converts a byte slice to a slice of float32.
func CosineSimilarity ¶
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 ¶
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.