embeddings

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Apr 8, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ProbeDimension

func ProbeDimension(ctx context.Context, e Embedder) (int, error)

ProbeDimension sends a test string to the embedder and returns the vector dimension.

Types

type Config

type Config struct {
	Provider string // "ollama" (default), "openai"
	URL      string // Provider-specific URL
	APIKey   string // API key (required for cloud providers)
	Model    string // Model name (optional, provider has defaults)
}

Config holds embedding provider configuration from environment variables.

type Embedder

type Embedder interface {
	Embed(ctx context.Context, texts []string) ([][]float32, error)
	EmbedOne(ctx context.Context, text string) ([]float32, error)
}

Embedder converts text into vector embeddings. Implementations: Ollama (local), OpenAI, Voyage AI, etc.

func New

func New(cfg Config) (Embedder, error)

New creates an Embedder from the given configuration.

type OllamaClient

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

func NewOllamaClient

func NewOllamaClient(baseURL string) *OllamaClient

func (*OllamaClient) Embed

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

func (*OllamaClient) EmbedOne

func (c *OllamaClient) EmbedOne(ctx context.Context, text string) ([]float32, error)

type OpenAIClient

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

OpenAIClient implements Embedder using the OpenAI embeddings API. Compatible with any OpenAI-compatible endpoint (OpenAI, Azure, Mistral, etc).

func NewOpenAIClient

func NewOpenAIClient(apiKey string, opts ...OpenAIOption) *OpenAIClient

func (*OpenAIClient) Embed

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

func (*OpenAIClient) EmbedOne

func (c *OpenAIClient) EmbedOne(ctx context.Context, text string) ([]float32, error)

type OpenAIOption

type OpenAIOption func(*OpenAIClient)

func WithOpenAIModel

func WithOpenAIModel(model string) OpenAIOption

func WithOpenAIURL

func WithOpenAIURL(url string) OpenAIOption

Jump to

Keyboard shortcuts

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