vector

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrLibraryNotFound = errors.New("llama.cpp shared library not found")

ErrLibraryNotFound is returned when the shared library cannot be located.

Functions

func ChunkBySentencesExported

func ChunkBySentencesExported(text string, maxWords int) []string

ChunkBySentencesExported is the exported wrapper for chunkBySentences, used in integration and e2e tests.

func CleanText

func CleanText(text string) string

CleanText runs the full cleaning pipeline on raw input text:

  1. Strip HTML / XML tags, inserting spaces between adjacent text nodes
  2. Remove emoji and non-printable / control characters
  3. Collapse whitespace and trim

func CosineSimilarity

func CosineSimilarity(a, b []float32) float64

CosineSimilarity computes the cosine similarity between two embedding vectors.

func DotProduct

func DotProduct(a, b []float32) float64

DotProduct computes the dot product between two normalized embedding vectors.

func FindLibrary

func FindLibrary(name, goos string) (string, error)

FindLibrary is exported for testing.

func IsLibraryAvailable

func IsLibraryAvailable() bool

IsLibraryAvailable checks if the llama.cpp library can be found without loading it.

func LibDirs

func LibDirs(goos string) []string

LibDirs returns the list of directories searched for the shared library. Exported for testing.

func LibraryNotFoundError

func LibraryNotFoundError(err error) bool

LibraryNotFoundError is a sentinel check.

func Normalize

func Normalize(v []float32)

Normalize normalizes a vector in-place to unit length.

func ResolveLibraryError

func ResolveLibraryError(err error) string

ResolveLibraryError returns a user-friendly error message when library is not found.

Types

type Vectorizer

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

Vectorizer represents a loaded GGUF embedding model.

func NewVectorizer

func NewVectorizer(modelPath string, gpuLayers int, embedContextSize uint32) (*Vectorizer, error)

NewVectorizer loads a GGUF model file and returns a ready-to-use vectorizer. gpuLayers controls how many model layers are offloaded to GPU (0 = CPU only). embedContextSize sets the llama.cpp context window; 0 defaults to 512.

func (*Vectorizer) Close

func (v *Vectorizer) Close() error

Close releases all resources held by the vectorizer.

func (*Vectorizer) EmbedDim

func (v *Vectorizer) EmbedDim() int

EmbedDim returns the dimensionality of the model's embedding vectors.

func (*Vectorizer) EmbedText

func (v *Vectorizer) EmbedText(text string) ([]float32, error)

EmbedText cleans the input text and converts it into a float32 embedding vector. If the text exceeds the model's token budget it is split into sentence-boundary-aware chunks and the embeddings are averaged.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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