llm

package
v0.4.5 Latest Latest
Warning

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

Go to latest
Published: Jul 26, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package llm provides embedding clients for the configured provider. It is ported and trimmed from Seam v1 internal/ai: the chat completion, ChromaDB, and async task-queue machinery are gone; only text -> vector embedding remains, since P1 needs brute-force cosine search over locally stored vectors.

OpenAI is the first-class provider; Ollama is the local/dev provider (no API cost). Anthropic has no embeddings API and is rejected by the factory.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrUnavailable indicates the embedding backend could not be reached.
	ErrUnavailable = errors.New("embedding provider unavailable")
	// ErrAuth indicates authentication with the provider failed.
	ErrAuth = errors.New("embedding provider authentication failed")
	// ErrRateLimited indicates the provider throttled the request.
	ErrRateLimited = errors.New("embedding provider rate limited")
	// ErrConfig indicates the client itself is misconfigured: the request could
	// not be built at all, so no provider was contacted and no retry can help.
	// The factories below reject a bad base_url up front, so a client that
	// exists should never produce this at request time.
	ErrConfig = errors.New("llm client misconfigured")
)

Provider-agnostic sentinel errors. Callers (e.g. recall) use errors.Is to decide whether to degrade to lexical-only search when embedding is unavailable.

The split that matters is remote vs local. ErrUnavailable, ErrAuth, and ErrRateLimited all describe a provider that answered badly or not at all: nothing in this process is wrong, so degrading to lexical-only search is honest and the condition may clear on its own. ErrConfig describes a client that could not even form the request -- degrading on that would hide a local defect behind quietly worse results for as long as the daemon runs.

Functions

This section is empty.

Types

type Chat

type Chat interface {
	Complete(ctx context.Context, system, user string) (string, error)
	Model() string
}

Chat turns a system + user prompt into a single text completion. It backs the gardener's session digests; it is intentionally minimal (no streaming, no tool use). Implementations are safe for concurrent use.

func NewChatClient

func NewChatClient(cfg config.LLM) (Chat, error)

NewChatClient builds the chat client selected by cfg.Provider. Unlike embeddings, every provider offers chat, so all three are supported.

type Embedder

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

Embedder turns text into a dense vector. Implementations are safe for concurrent use. Model identifies which model produced the vectors so the store can scope a cosine search to a single model space.

func NewEmbedder

func NewEmbedder(cfg config.LLM) (Embedder, error)

NewEmbedder builds the embedder selected by cfg.Provider. Chat-only providers (Anthropic) are rejected: embeddings must come from OpenAI or Ollama.

type OllamaEmbedder

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

OllamaEmbedder calls a local Ollama server's POST /api/embed. Ported from Seam v1 internal/ai/ollama.go (embedding path only).

func NewOllamaEmbedder

func NewOllamaEmbedder(baseURL, model string) *OllamaEmbedder

NewOllamaEmbedder returns an embedder for a local Ollama model. An empty baseURL uses the default localhost endpoint.

func (*OllamaEmbedder) Embed

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

Embed returns the embedding vector for text.

func (*OllamaEmbedder) Model

func (c *OllamaEmbedder) Model() string

Model returns the embedding model name.

type OpenAIEmbedder

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

OpenAIEmbedder calls POST {baseURL}/embeddings. It is compatible with OpenAI, Azure OpenAI, and any OpenAI-compatible endpoint. Ported from Seam v1 internal/ai/openai_embedder.go.

func NewOpenAIEmbedder

func NewOpenAIEmbedder(apiKey, baseURL, model string, dims int) *OpenAIEmbedder

NewOpenAIEmbedder returns an OpenAI embeddings client. An empty baseURL uses the default endpoint. dims of 0 omits the dimensions field.

func (*OpenAIEmbedder) Embed

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

Embed returns the embedding vector for text.

func (*OpenAIEmbedder) Model

func (c *OpenAIEmbedder) Model() string

Model returns the embedding model name.

Jump to

Keyboard shortcuts

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