embed

package
v0.6.1 Latest Latest
Warning

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

Go to latest
Published: Jul 3, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package embed provides an OpenAI-compatible embeddings client and the similarity + fusion primitives for hybrid (BM25 + vector) catalog retrieval.

It is the in-house alternative to a Python embedding sidecar or a vector-DB dependency: embeddings are served by the same OpenAI-compatible endpoint as the model (in-cluster vLLM, Ollama, OpenAI), and similarity is brute-force cosine over the (small) catalog — no new datastore, still a single static binary.

This package is the foundation only; wiring hybrid retrieval into the catalog index and the recall gates is an eval-validated follow-up (the BM25-tuned recall thresholds must be re-measured for fused scores, not guessed).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Cosine

func Cosine(a, b []float32) float64

Cosine returns the cosine similarity of two equal-length vectors, in [-1, 1]. Mismatched-length or zero-norm vectors return 0 ("no signal").

Types

type Client

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

Client calls an OpenAI-compatible /embeddings endpoint.

func New

func New(baseURL, model, apiKey string) *Client

New builds an embeddings client. apiKey may be empty (keyless vLLM/Ollama).

func (*Client) Embed

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

Embed returns one vector per input text, in input order. Empty input → nil.

type Fused

type Fused struct {
	ID    string
	Score float64
}

Fused is an id with its fused relevance score.

func FuseRRF

func FuseRRF(k float64, rankings ...[]string) []Fused

FuseRRF combines several rankings of the same id space by Reciprocal Rank Fusion: score(id) = Σ 1/(k + rank), rank 0-based within each ranking; an id absent from a ranking contributes nothing. RRF is scale-free — it fuses BM25 and cosine rankings without their different score magnitudes distorting the result. k dampens low ranks (60 is the common default). Results are sorted by descending fused score, ties broken by id for determinism.

Jump to

Keyboard shortcuts

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