embedding

package
v0.0.0-...-2493bd8 Latest Latest
Warning

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

Go to latest
Published: May 15, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultLocalProvider = "local"
	DefaultLocalModel    = "local-hash-v1"
)
View Source
const (
	OllamaProvider     = "ollama"
	DefaultOllamaModel = "nomic-embed-text"
	DefaultOllamaHost  = "http://localhost:11434"
)
View Source
const (
	OpenRouterProvider     = "openrouter"
	DefaultOpenRouterModel = "openai/text-embedding-3-small"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type LocalProvider

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

func NewLocalProvider

func NewLocalProvider(model string) LocalProvider

func (LocalProvider) Embed

func (p LocalProvider) Embed(_ context.Context, text string) ([]float64, error)

func (LocalProvider) Model

func (p LocalProvider) Model() string

func (LocalProvider) Name

func (p LocalProvider) Name() string

type OllamaEmbeddingProvider

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

OllamaEmbeddingProvider runs embeddings against a locally hosted Ollama server. No API key required; the only configuration is the base URL (default http://localhost:11434, overridable via OLLAMA_HOST) and the model name (default nomic-embed-text — 137M params, 768-d, widely available, decent retrieval quality).

This intentionally talks to Ollama's native /api/embed endpoint rather than its OpenAI-compatible /v1/embeddings endpoint because the native shape is simpler and supports batching directly.

func NewOllamaProvider

func NewOllamaProvider(model string) (OllamaEmbeddingProvider, error)

NewOllamaProvider builds the provider, reading OLLAMA_HOST from the env when set. We don't probe the server here — defer that to first Embed call so the provider is cheap to construct (matches LocalProvider's behavior).

func (OllamaEmbeddingProvider) Embed

func (p OllamaEmbeddingProvider) Embed(ctx context.Context, text string) ([]float64, error)

func (OllamaEmbeddingProvider) Model

func (p OllamaEmbeddingProvider) Model() string

func (OllamaEmbeddingProvider) Name

type OpenRouterEmbeddingProvider

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

OpenRouterEmbeddingProvider talks to OpenRouter's OpenAI-compatible /v1/embeddings endpoint. The API key comes from OPENROUTER_API_KEY; the model is configurable (default: openai/text-embedding-3-small, the cheap 1536-d model that benchmarks well on retrieval).

func NewOpenRouterProvider

func NewOpenRouterProvider(model string) (OpenRouterEmbeddingProvider, error)

NewOpenRouterProvider constructs the provider, reading the API key from the environment. Returns an error if OPENROUTER_API_KEY is unset — callers can then fall back to the local provider or surface the error to the operator.

func (OpenRouterEmbeddingProvider) Embed

Embed sends a single string to OpenRouter and returns the vector. We use the single-input form (input: "string") because the Provider interface is one-text-at-a-time; the batch path lives in the bench harness, which talks to OpenRouter directly when it needs throughput.

func (OpenRouterEmbeddingProvider) Model

func (OpenRouterEmbeddingProvider) Name

type Provider

type Provider interface {
	Name() string
	Model() string
	Embed(ctx context.Context, text string) ([]float64, error)
}

Jump to

Keyboard shortcuts

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