embedder

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Mar 22, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Embedder

type Embedder interface {
	// Embed returns a vector embedding for the given text.
	Embed(ctx context.Context, text string) ([]float32, error)

	// EmbedBatch returns vector embeddings for multiple texts.
	EmbedBatch(ctx context.Context, texts []string) ([][]float32, error)

	// Dimension returns the embedding vector dimension.
	Dimension() int
}

Embedder generates vector embeddings from text.

func New added in v0.10.0

func New(ollaCfg config.OllamaConfig, embCfg config.EmbedderConfig, dimension int, logger *slog.Logger) (Embedder, error)

New returns an Embedder implementation selected by embCfg.Provider.

Supported providers:

  • "" or "ollama" → OllamaEmbedder using ollaCfg
  • "lmstudio" → LMStudioEmbedder using embCfg.LMStudio

Any other provider string is an error.

type LMStudioEmbedder added in v0.10.0

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

LMStudioEmbedder implements Embedder using the LM Studio local server's OpenAI-compatible /v1/embeddings endpoint.

func NewLMStudioEmbedder added in v0.10.0

func NewLMStudioEmbedder(baseURL, model string) *LMStudioEmbedder

NewLMStudioEmbedder creates a new LM Studio embedder pointed at baseURL using the given model name.

func (*LMStudioEmbedder) Dimension added in v0.10.0

func (e *LMStudioEmbedder) Dimension() int

Dimension returns 0 — LM Studio does not report dimension at construction time; callers should use the length of the returned slice from Embed.

func (*LMStudioEmbedder) Embed added in v0.10.0

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

Embed returns a vector embedding for the given text by calling the LM Studio /v1/embeddings endpoint.

func (*LMStudioEmbedder) EmbedBatch added in v0.10.0

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

EmbedBatch returns embeddings for multiple texts by calling Embed in a loop.

type OllamaEmbedder

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

OllamaEmbedder implements Embedder using the Ollama HTTP API.

func NewOllamaEmbedder

func NewOllamaEmbedder(baseURL, model string, dimension int, logger *slog.Logger) *OllamaEmbedder

NewOllamaEmbedder creates a new Ollama-based embedder.

func (*OllamaEmbedder) Dimension

func (o *OllamaEmbedder) Dimension() int

Dimension returns the embedding vector dimension.

func (*OllamaEmbedder) Embed

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

Embed returns a vector embedding for the given text using the Ollama API.

func (*OllamaEmbedder) EmbedBatch

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

EmbedBatch embeds multiple texts in a single HTTP call to Ollama's /api/embed endpoint, which accepts an array of inputs and returns all embeddings at once. This is dramatically faster than per-text calls (1 round-trip vs N).

Jump to

Keyboard shortcuts

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