embedding

package
v0.2.13 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2026 License: Apache-2.0 Imports: 9 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 embedding turns text into normalized vectors with a transformer model on the CPU. Model files are acquired and verified by the model registry before an engine loads them.

Index

Constants

View Source
const MaxInputTokens = 512

MaxInputTokens is the model window, special tokens and prefix included.

Variables

View Source
var ErrTooLong = fmt.Errorf("embedding input exceeds the %d-token window", MaxInputTokens)

ErrTooLong reports an input that exceeds the model window. Inputs are never truncated.

Functions

This section is empty.

Types

type Engine

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

Engine is one loaded embedding model. It is not safe for concurrent use.

func Load

func Load(definition *protocol.ModelsDefinition, directory string) (*Engine, error)

Load opens the model of a registered definition from its verified files.

func (*Engine) Close

func (engine *Engine) Close()

Close releases the model.

func (*Engine) Dimension

func (engine *Engine) Dimension() int

Dimension is the length of every vector.

func (*Engine) Encode

func (engine *Engine) Encode(input Input, texts []string) ([][]float32, error)

Encode returns one unit-length vector per text. An output of zeros stays zero.

func (*Engine) Offsets

func (engine *Engine) Offsets(text string) ([][2]int, error)

Offsets returns the byte range of every token of text, without special tokens or truncation.

type Input

type Input uint8

Input selects the prefix a definition prescribes for a text.

const (
	Query Input = iota
	Document
)

Directories

Path Synopsis
Package tokenizer reads the Hugging Face tokenizer.json components the pinned granite-multi embedding model uses and reproduces tokenizers 0.23.2 for them: added tokens, Split (Isolated) followed by ByteLevel pre-tokenization, BPE with ignore_merges and TemplateProcessing.
Package tokenizer reads the Hugging Face tokenizer.json components the pinned granite-multi embedding model uses and reproduces tokenizers 0.23.2 for them: added tokens, Split (Isolated) followed by ByteLevel pre-tokenization, BPE with ignore_merges and TemplateProcessing.

Jump to

Keyboard shortcuts

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