embed

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Jul 8, 2026 License: AGPL-3.0 Imports: 11 Imported by: 0

Documentation

Overview

Package embed is the BYOAI embedding layer. Mesh never runs inference itself; it calls a configured endpoint (Ollama, OpenAI, Voyage, any /v1/embeddings server) so vectors stay on the user's sovereign infrastructure. Embeddings are a mechanical transform, not the reasoning AI - the agent is still the librarian.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Cosine

func Cosine(a, b []float32) float64

Cosine returns the cosine similarity of two equal-length vectors. Returns 0 when either is zero or lengths differ.

Types

type Embedder

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

Embedder turns text into vectors. Implementations must be deterministic for a given model so a vault's vectors stay comparable. Dim() is the vector width; it pins the space so a same-named-but-different-width model is caught, not silently cosined across incompatible dimensions.

type HTTP

type HTTP struct {
	BaseURL string
	ModelID string
	Key     string // bearer token; empty for keyless local endpoints
	Client  *http.Client
	// contains filtered or unexported fields
}

HTTP is an OpenAI-compatible embeddings client. It speaks the POST {BaseURL}/embeddings {model, input:[...]} -> {data:[{embedding:[...]}]} shape that Ollama (via /v1), OpenAI, Voyage, LiteLLM, and most local servers expose. BaseURL should include the version prefix, e.g. http://localhost:11434/v1 or https://api.openai.com/v1.

func NewHTTP

func NewHTTP(baseURL, model, key string) *HTTP

func (*HTTP) Dim

func (h *HTTP) Dim() int

Dim returns the embedding width. It is cached from the first Embed; if Dim is asked before any Embed it probes once with a sentinel string (no /embeddings endpoint exposes dim metadata, so a probe is the only honest option). Returns 0 if the endpoint is unreachable.

func (*HTTP) Embed

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

func (*HTTP) Model

func (h *HTTP) Model() string

type Stub

type Stub struct{ D int }

Stub is a deterministic, network-free embedder for tests and offline demos. It hashes tokens into a fixed-dimension bag-of-words vector (L2-normalized). It is NOT semantic: it exists to exercise vector storage, cosine, and fusion plumbing, never to prove retrieval quality.

func (Stub) Dim

func (s Stub) Dim() int

func (Stub) Embed

func (s Stub) Embed(_ context.Context, texts []string) ([][]float32, error)

func (Stub) Model

func (s Stub) Model() string

Jump to

Keyboard shortcuts

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