embedder

package
v0.0.0-...-9acc999 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2026 License: MIT Imports: 12 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 embedder provides text embedding using Hugging Face transformers via hugot. It uses ONNX models for efficient, native Go embeddings without external processes.

Index

Constants

This section is empty.

Variables

View Source
var ErrClosed = errors.New("embedder is closed")
View Source
var ErrLocalModelMissing = errors.New("local embedding model missing")

ErrLocalModelMissing means no model.onnx exists under the explicit directory.

Functions

This section is empty.

Types

type Embedder

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

Embedder generates text embeddings using hugot (Hugging Face ONNX runtime).

func New

func New(modelName string, modelsDir string) (*Embedder, error)

New creates a new Embedder. It downloads (if needed) and loads the model. If modelsDir is empty, it uses the bundled model in ./models/onnx/.

func NewLocal

func NewLocal(modelName, modelsDir string) (*Embedder, error)

NewLocal loads only from modelsDir/model.onnx or modelsDir/onnx/model.onnx. It never probes the process working directory or downloads a model.

func (*Embedder) Close

func (e *Embedder) Close()

Close releases hugot session resources.

func (*Embedder) CreateEmbedding

func (e *Embedder) CreateEmbedding(ctx context.Context, text string) ([]float32, error)

CreateEmbedding generates a float32 vector for given text.

func (*Embedder) CreateEmbeddings

func (e *Embedder) CreateEmbeddings(ctx context.Context, texts []string) ([][]float32, error)

CreateEmbeddings batch-embeds multiple texts in a single forward pass. It processes texts in chunks of 64 (recommended by hugot) and handles shape mismatches by falling back to single embeddings when needed.

func (*Embedder) Dimension

func (e *Embedder) Dimension() int

Dimension returns the size of vectors produced by this embedder.

func (*Embedder) Identity

func (e *Embedder) Identity() Identity

Identity returns the semantic fingerprint of this embedder.

type Identity

type Identity struct {
	Model      string    `json:"model"`
	Dimension  int       `json:"dimension"`
	Metric     string    `json:"metric"`
	Normalize  bool      `json:"normalize"`
	Provider   string    `json:"provider"`
	Version    string    `json:"version"`
	CapturedAt time.Time `json:"captured_at"`
}

Identity represents the exact characteristics of the embedding model used, to ensure vectors can be matched correctly in the database.

Jump to

Keyboard shortcuts

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