embeddings

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Jul 18, 2026 License: MIT Imports: 5 Imported by: 0

README

embeddings

model := embeddings.ModelRef{Provider: "local", Name: "demo", Dim: 3}
key := embeddings.CacheKey(model, "hello")
err := embeddings.ValidateDimensions([]embeddings.Vector{{1, 2, 3}}, model.Dim)

embeddings is the provider-neutral contract for embedding requests and dense vectors.

The package does not call models, choose providers, or own vector-space policy. Callers pass an Embedder implementation and keep model identity, dimensions, fallback behavior, and cache invalidation explicit.

Documentation

Overview

Package embeddings defines provider-neutral embedding model, request, result, vector, cache-key, and dimension-validation contracts. Provider clients and model policy stay in adapters or applications.

Package embeddings defines provider-neutral embedding contracts.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func CacheKey

func CacheKey(model ModelRef, input string) string

CacheKey returns a stable cache identity for one model/input pair.

func ValidateDimensions

func ValidateDimensions(vectors []Vector, dims int) error

ValidateDimensions checks that every vector has dims values.

Example
model := embeddings.ModelRef{Provider: "local", Name: "demo", Dim: 3}
err := embeddings.ValidateDimensions([]embeddings.Vector{{1, 2, 3}}, model.Dim)
fmt.Println(err == nil)
Output:
true

Types

type Embedder

type Embedder interface {
	Embed(ctx context.Context, request Request) (Result, error)
}

Embedder embeds text into vectors.

type ModelRef

type ModelRef struct {
	Provider string
	Name     string
	Version  string
	Revision string
	Dim      int
}

ModelRef identifies an embedding model and vector space.

func (ModelRef) Identity

func (m ModelRef) Identity() string

Identity returns the stable model identity used for cache keys.

type Request

type Request struct {
	Model  ModelRef
	Inputs []string
}

Request is a batch embedding request.

type Result

type Result struct {
	Model   ModelRef
	Vectors []Vector
}

Result is a batch embedding result.

type Vector

type Vector []float32

Vector is a dense embedding vector.

Jump to

Keyboard shortcuts

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