embed

package
v0.0.0-...-f4dd804 Latest Latest
Warning

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

Go to latest
Published: May 31, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package embed provides BGE-small-en-v1.5 text embedding via ONNX Runtime. Vectors are L2-normalized so dot product == cosine similarity.

Index

Constants

View Source
const (

	// EmbeddingDim is the output dimension of BGE-small-en-v1.5.
	EmbeddingDim = 384

	// BGEQueryPrefix is prepended to queries (not documents) for asymmetric
	// retrieval per the BGE-small-en-v1.5 paper recommendation.
	// Docs: https://huggingface.co/BAAI/bge-small-en-v1.5
	BGEQueryPrefix = "Represent this sentence for searching relevant passages: "
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Embedder

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

Embedder wraps an ONNX session and a HuggingFace tokenizer.

func New

func New(modelDir, ortLibPath string, numThreads int) (*Embedder, error)

New loads the ONNX model and tokenizer from modelDir. ortLibPath is the path to onnxruntime.so; pass "" to use the system default. numThreads controls intra-op parallelism; 0 = use min(4, NumCPU). modelDir must contain: model.onnx, tokenizer.json

func (*Embedder) BenchmarkSingle

func (e *Embedder) BenchmarkSingle(text string) (tokenize, inference, total time.Duration, err error)

BenchmarkSingle embeds a single short text and returns phase timings for the sift bench command. Returns (tokenizeMs, inferenceMs, totalMs, error).

func (*Embedder) Close

func (e *Embedder) Close()

Close releases the ONNX session and tokenizer.

func (*Embedder) Embed

func (e *Embedder) Embed(texts []string) ([][]float32, error)

Embed embeds a batch of document texts (no instruction prefix). Use this for indexing document chunks.

func (*Embedder) EmbedQuery

func (e *Embedder) EmbedQuery(query string) ([]float32, error)

EmbedQuery embeds a single query string with the BGE instruction prefix. Always use this for search queries — never for document chunks. The prefix "Represent this sentence for searching relevant passages: " is recommended by the BGE authors for asymmetric retrieval tasks.

Jump to

Keyboard shortcuts

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