Documentation
¶
Index ¶
- func CosineSimilarity(a, b []float32) float32
- func DeserializeFloat32(b []byte) []float32
- func SerializeFloat32(v []float32) []byte
- type Commander
- type Embedder
- type ExecCommander
- type HTTPClient
- type OllamaEmbedder
- type OllamaOption
- func WithOllamaCommander(c Commander) OllamaOption
- func WithOllamaHTTPClient(c HTTPClient) OllamaOption
- func WithOllamaIdleCheckInterval(d time.Duration) OllamaOption
- func WithOllamaLogger(l *slog.Logger) OllamaOption
- func WithOllamaLoopDir(dir string) OllamaOption
- func WithOllamaModel(model string) OllamaOption
- func WithOllamaStartupWait(d time.Duration) OllamaOption
- func WithOllamaURL(url string) OllamaOption
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CosineSimilarity ¶
CosineSimilarity computes the cosine similarity between two vectors. Returns a value between -1 and 1, where 1 means identical direction.
func DeserializeFloat32 ¶
DeserializeFloat32 decodes a little-endian byte slice into a float32 slice.
func SerializeFloat32 ¶
SerializeFloat32 encodes a float32 slice as a little-endian byte slice.
Types ¶
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 HTTPClient ¶
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 ¶
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.