embedding

package
v1.75.1 Latest Latest
Warning

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

Go to latest
Published: May 31, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package embedding provides text embedding generation for memory vector search.

Index

Constants

View Source
const (
	// KindNoop identifies the placeholder provider returned when no
	// embedder is configured. Callers MUST treat KindNoop as
	// "embedding unavailable" and refuse to persist vectors from it.
	KindNoop = "noop"

	// KindOllama identifies the Ollama-backed provider.
	KindOllama = "ollama"
)

Kind values for Provider.Kind. Used by callers (platform wiring, toolkit write paths) to distinguish a real, network-backed embedder from the placeholder noop. A noop returns zero vectors with no error, which is indistinguishable from a "real" embedding at the Embed/EmbedBatch contract level; without an explicit kind, downstream consumers cannot tell whether the vectors they hold are meaningful.

View Source
const DefaultDimension = 768

DefaultDimension is the default embedding dimensionality (nomic-embed-text).

View Source
const DefaultTimeout = 30

DefaultTimeout is the default HTTP timeout in seconds for embedding API calls. Tuned for the singular /api/embeddings path (one text per call), where a CPU-only Ollama with nomic-embed-text typically returns in 1-3 seconds; 30s is a generous ceiling for transient slowness on the request path. Synchronous request-path callers (memory_recall, memory_manage, knowledge capture_insight, apigateway query-vector) share this default so a wedged Ollama fails the tool call at 30s instead of holding an MCP request handler open for minutes.

The batched /api/embed path used by the api-gateway embed-jobs worker needs a much higher ceiling (CPU-only Ollama on a 32-text batch can take 60+ seconds). The worker constructs its own Provider with a longer timeout from apigateway.embed_jobs.embed_timeout — see pkg/platform/apigateway_embed_jobs.go. The default here intentionally does NOT cover the batch case so request-path consumers are not caught up in the worker's longer budget (#445).

Variables

This section is empty.

Functions

func IsConfigured added in v1.64.0

func IsConfigured(p Provider) bool

IsConfigured reports whether p is a real, configured embedding provider whose vectors are safe to persist. Returns false for nil and for the noop placeholder. Used by the platform wiring layer and toolkit write paths as a single-line guard.

func ModelName added in v1.74.0

func ModelName(p Provider) string

ModelName returns p's underlying embedding model identifier when the concrete provider exposes one, else "". The memory write path stamps this on each row (embedding_model) and the indexjobs memory Sink diffs stored rows against the current provider's model to find model-swap gaps, so both sides must read the model the same way. Mirrors the unexported indexjobs.providerModel.

Types

type OllamaConfig

type OllamaConfig struct {
	URL     string
	Model   string
	Timeout time.Duration
}

OllamaConfig configures the Ollama embedding provider.

type Provider

type Provider interface {
	// Embed generates an embedding vector for a single text input.
	Embed(ctx context.Context, text string) ([]float32, error)

	// EmbedBatch generates embedding vectors for multiple text inputs.
	EmbedBatch(ctx context.Context, texts []string) ([][]float32, error)

	// Dimension returns the dimensionality of the generated embeddings.
	Dimension() int

	// Kind returns a short identifier for the provider implementation
	// (KindOllama, KindNoop, ...). Callers use this to refuse to
	// persist vectors from the noop placeholder without depending on
	// concrete type assertions.
	Kind() string
}

Provider generates vector embeddings from text.

func NewNoopProvider

func NewNoopProvider(dim int) Provider

NewNoopProvider creates a no-op embedding provider.

func NewOllamaProvider

func NewOllamaProvider(cfg OllamaConfig) Provider

NewOllamaProvider creates an embedding provider that calls Ollama.

Jump to

Keyboard shortcuts

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