Help us shape the future of Go! Take the 2026 Go Developer Survey

embedding

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	OllamaDefaultURL   = "http://localhost:11434"
	OllamaDefaultModel = "nomic-embed-text"
	VoyageDefaultModel = "voyage-3"
)

Defaults used by each backend when embedding.model or embedding.base_url is not set. core.ResolveBackends applies them.

Variables

This section is empty.

Functions

func Dimension added in v0.5.1

func Dimension(model string) (int, bool)

Dimension returns the vector size of a known embedding model. Ollama's "name:latest" is the same model as "name".

Types

type Adapter

type Adapter interface {
	// Embed converts text to a normalised float32 vector.
	Embed(ctx context.Context, text string) ([]float32, error)
}

Adapter defines the contract for all embedding backends. Implementations: voyage.go, ollama.go.

Implementations MUST return L2-normalised vectors (‖v‖₂ = 1). The search layer assumes this when interpreting distance scores — an L2 distance threshold of 1.0 corresponds to cos_sim ≈ 0.5 only for unit vectors. Both Voyage AI and Ollama nomic-embed-text return normalised vectors by default; any new adapter that does not must normalise before returning.

All embeddings in the DB must use the same model and dimensions.

type OllamaAdapter

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

OllamaAdapter implements EmbeddingAdapter using a local Ollama server.

func NewOllamaEmbeddingAdapter

func NewOllamaEmbeddingAdapter(baseURL, modelName string) *OllamaAdapter

NewOllamaEmbeddingAdapter creates an adapter pointed at the given Ollama base URL.

func (*OllamaAdapter) Embed

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

Embed returns the embedding vector for the given text.

type VoyageAdapter

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

VoyageAdapter implements EmbeddingAdapter using the Voyage AI REST API.

func NewVoyageAdapter

func NewVoyageAdapter(apiKey, model string) *VoyageAdapter

NewVoyageAdapter creates a new Voyage AI embedding adapter.

func (*VoyageAdapter) Embed

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

Embed converts text to a float32 vector using Voyage AI. voyage-3 produces 1024-dimensional vectors.

Jump to

Keyboard shortcuts

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