embeddings

package
v0.1.61 Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2026 License: GPL-3.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CosineSimilarity

func CosineSimilarity(a, b []float32) float32

CosineSimilarity computes the cosine similarity between two vectors. Returns a value between -1 and 1, where 1 means identical direction.

func DeserializeFloat32

func DeserializeFloat32(b []byte) []float32

DeserializeFloat32 decodes a little-endian byte slice into a float32 slice.

func SerializeFloat32

func SerializeFloat32(v []float32) []byte

SerializeFloat32 encodes a float32 slice as a little-endian byte slice.

Types

type Commander

type Commander interface {
	Run(ctx context.Context, name string, args ...string) ([]byte, error)
}

Commander abstracts shell command execution for testability.

type Embedder

type Embedder interface {
	// Embed returns embedding vectors for the given texts.
	Embed(ctx context.Context, texts []string) ([][]float32, error)
	// Dimensions returns the number of dimensions in the embedding vectors.
	Dimensions() int
}

Embedder generates vector embeddings from text.

type ExecCommander

type ExecCommander struct{}

ExecCommander implements Commander using os/exec.

func (*ExecCommander) Run

func (c *ExecCommander) Run(ctx context.Context, name string, args ...string) ([]byte, error)

Run executes a command and returns its combined stdout/stderr output.

type HTTPClient

type HTTPClient interface {
	Do(req *http.Request) (*http.Response, error)
}

HTTPClient abstracts HTTP calls for testability.

type OllamaEmbedder

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

OllamaEmbedder generates embeddings using Ollama running in a Docker container.

func NewOllamaEmbedder

func NewOllamaEmbedder(opts ...OllamaOption) *OllamaEmbedder

NewOllamaEmbedder creates an Ollama embedder that manages a Docker container.

func (*OllamaEmbedder) Dimensions

func (e *OllamaEmbedder) Dimensions() int

func (*OllamaEmbedder) Embed

func (e *OllamaEmbedder) Embed(ctx context.Context, texts []string) ([][]float32, error)

Embed starts the Ollama container if needed, ensures the model is pulled, and returns embeddings for the given texts.

func (*OllamaEmbedder) RunIdleMonitor

func (e *OllamaEmbedder) RunIdleMonitor(ctx context.Context)

RunIdleMonitor periodically checks the marker file and stops the Ollama container when it has been idle for longer than ollamaIdleTimeout. Blocks until ctx is cancelled. Run this as a goroutine in the daemon.

func (*OllamaEmbedder) Stop

func (e *OllamaEmbedder) Stop()

Stop removes the Ollama container. Call during daemon shutdown.

type OllamaOption

type OllamaOption func(*OllamaEmbedder)

OllamaOption configures an OllamaEmbedder.

func WithOllamaCommander

func WithOllamaCommander(c Commander) OllamaOption

WithOllamaCommander sets the command executor.

func WithOllamaHTTPClient

func WithOllamaHTTPClient(c HTTPClient) OllamaOption

WithOllamaHTTPClient sets the HTTP client.

func WithOllamaIdleCheckInterval

func WithOllamaIdleCheckInterval(d time.Duration) OllamaOption

WithOllamaIdleCheckInterval overrides the idle check interval (for testing).

func WithOllamaLogger

func WithOllamaLogger(l *slog.Logger) OllamaOption

WithOllamaLogger sets the logger.

func WithOllamaLoopDir

func WithOllamaLoopDir(dir string) OllamaOption

WithOllamaLoopDir sets the loop directory for the idle-timeout marker file.

func WithOllamaModel

func WithOllamaModel(model string) OllamaOption

WithOllamaModel sets the embedding model name.

func WithOllamaStartupWait

func WithOllamaStartupWait(d time.Duration) OllamaOption

WithOllamaStartupWait overrides the container startup wait duration (for testing).

func WithOllamaURL

func WithOllamaURL(url string) OllamaOption

WithOllamaURL sets the Ollama API URL.

Jump to

Keyboard shortcuts

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