embed

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Aug 8, 2026 License: MIT Imports: 16 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package embed turns text into dense vectors for semantic search. It offers two fully local backends behind one interface: in-process ONNX (default, no external process) and a local Ollama daemon. Neither backend calls a third-party cloud service.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Embedder

type Embedder interface {
	// Embed returns one vector per input string, in order. All vectors have
	// length Dim.
	Embed(ctx context.Context, texts []string) ([][]float32, error)
	// Dim reports the embedding dimensionality.
	Dim() int
	// Model reports the model identifier, persisted with the index so a later
	// run can detect an incompatible model.
	Model() string
	// Close releases any resources (model session, connections).
	Close() error
}

Embedder produces embeddings for text. Implementations discover their own dimensionality at construction, so Dim is authoritative for sizing storage.

func New

func New(ctx context.Context, cfg *config.Config) (Embedder, error)

New constructs the Embedder selected by cfg.EmbedProvider.

type ONNX

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

ONNX embeds text with an ONNX transformer model running in-process via hugot's pure-Go backend. No CGO and no external ONNX Runtime shared library are required; the model is downloaded once from HuggingFace and cached locally, after which embedding is fully offline.

func NewONNX

func NewONNX(ctx context.Context, modelID, modelDir, onnxFile string) (_ *ONNX, err error)

NewONNX loads modelID (a HuggingFace repo id, e.g. "sentence-transformers/all-MiniLM-L6-v2"), caching it under modelDir. onnxFile is the repo-relative path of the .onnx variant to use (e.g. "onnx/model.onnx"), required for models that ship several; pass "" to let hugot pick when a model has exactly one. It downloads the model only when it is not already cached, then warms up the pipeline to discover the embedding dimensionality.

func (*ONNX) Close

func (o *ONNX) Close() error

Close implements Embedder.

func (*ONNX) Dim

func (o *ONNX) Dim() int

Dim implements Embedder.

func (*ONNX) Embed

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

Embed implements Embedder. It first tries the whole batch at the proactive cap; if that fails (a chunk still tokenized past the model limit), it falls back to embedding each input individually, hard-truncating only the ones that fail. This keeps full quality for normal chunks while guaranteeing every input yields a vector.

func (*ONNX) Model

func (o *ONNX) Model() string

Model implements Embedder.

type Ollama

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

Ollama embeds text via a local Ollama daemon's /api/embed endpoint. It is the config-selectable alternative to the in-process ONNX backend and is still fully local (Ollama runs on the same machine).

func NewOllama

func NewOllama(ctx context.Context, host, model string) (*Ollama, error)

NewOllama connects to the Ollama daemon at host (e.g. "http://localhost:11434") for the given model, verifying reachability and discovering the embedding dimensionality with a warmup request.

func (*Ollama) Close

func (o *Ollama) Close() error

Close implements Embedder. Ollama holds no client-side resources.

func (*Ollama) Dim

func (o *Ollama) Dim() int

Dim implements Embedder.

func (*Ollama) Embed

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

Embed implements Embedder.

func (*Ollama) Model

func (o *Ollama) Model() string

Model implements Embedder.

Jump to

Keyboard shortcuts

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