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.
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 ¶
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) Embed ¶
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.
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 ¶
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.