Documentation
¶
Index ¶
- Constants
- Variables
- func L2NormalizeInPlace(v []float32) error
- func ValidProfile(p Profile) bool
- func ValidateEmbedInput(texts []string) error
- func ValidateGeometry(e Embedder, wantDim int, wantModel string) error
- func ValidateOutputVectors(texts []string, vectors [][]float32, dim int) error
- func VectorL2Norm(v []float32) float64
- type Embedder
- type Profile
- type ProfileDefaults
- type Registry
- type Stub
Constants ¶
const ( MaxBatchTexts = 64 MaxTextBytes = 32 * 1024 // 32 KiB per text )
Input limits for Embed (fail closed before upstream).
Variables ¶
var ( // ErrUnknownProfile is returned for unrecognized or empty profile keys. ErrUnknownProfile = errors.New("unknown embedding profile") // ErrDuplicateProfile is returned when two embedders claim the same profile. ErrDuplicateProfile = errors.New("duplicate embedding profile") // ErrMissingEmbedder is returned when a required profile has no implementation. ErrMissingEmbedder = errors.New("missing embedder implementation") // ErrGeometryMismatch is returned when Dimensions/ModelID do not match expected config. ErrGeometryMismatch = errors.New("embedding geometry mismatch") // ErrEmptyBatch is returned when Embed is called with no texts. ErrEmptyBatch = errors.New("empty embedding batch") // ErrBatchTooLarge is returned when the batch exceeds MaxBatchTexts. ErrBatchTooLarge = errors.New("embedding batch too large") // ErrTextTooLong is returned when a text exceeds MaxTextBytes. ErrTextTooLong = errors.New("embedding text too long") // ErrInvalidVector is returned when a backend yields wrong-length or non-finite vectors. ErrInvalidVector = errors.New("invalid embedding vector") )
Functions ¶
func L2NormalizeInPlace ¶
L2NormalizeInPlace scales v to unit length. Zero vectors become an error.
func ValidProfile ¶
ValidProfile reports whether p is a known deployment profile.
func ValidateEmbedInput ¶
ValidateEmbedInput rejects empty/oversized batches before calling a backend.
func ValidateGeometry ¶
ValidateGeometry fails closed when the embedder's dim/model do not match expected config.
func ValidateOutputVectors ¶
ValidateOutputVectors checks batch length, dim, and finite floats (not L2 — callers may assert separately).
func VectorL2Norm ¶
VectorL2Norm returns the Euclidean norm of v.
Types ¶
type Embedder ¶
type Embedder interface {
// Embed returns one L2-normalized float32 vector per input text.
// Length of the result slice equals len(texts); each vector length equals Dimensions().
Embed(ctx context.Context, texts []string) ([][]float32, error)
// Name returns the backend identifier (e.g. "stub", "tei", "openai", "local").
Name() string
// ModelID returns the model identifier (e.g. "all-MiniLM-L6-v2", "BAAI/bge-m3").
ModelID() string
// Dimensions returns the embedding vector length for this backend.
Dimensions() int
// Profile returns the deployment profile this backend serves.
Profile() Profile
}
Embedder produces embedding vectors for text batches. Implementations must be safe for concurrent use after construction. All vectors from a single Embed call use the same model geometry.
type Profile ¶
type Profile string
Profile is a deployment-time embedding profile key. Profiles are not interchangeable at the vector-search level without migration.
type ProfileDefaults ¶
ProfileDefaults documents the planned default geometry per profile (ADR-0046). M1 does not run TEI/OpenAI; stubs may use these dims for contract tests.
func DefaultGeometry ¶
func DefaultGeometry(p Profile) (ProfileDefaults, error)
DefaultGeometry returns the documented default model/dim for a known profile.
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry maps deployment Profile keys to Embedder implementations (read-only after New).
func NewRegistry ¶
NewRegistry constructs a registry from profile → impl.
func (*Registry) ForProfile ¶
ForProfile returns the embedder for profile or ErrUnknownProfile.
type Stub ¶
type Stub struct {
// contains filtered or unexported fields
}
Stub is a deterministic, L2-normalized embedder for tests and local contract checks. It is not a production inference backend (Name returns "stub").
func NewStubForProfile ¶
NewStubForProfile builds a stub using DefaultGeometry for the profile.