nexus

package module
v1.9.3 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package nexus is a weave embedder that sends every request through a nexus gateway, so embedding spend lands on the same usage records, keys and budgets as the rest of your model traffic.

It lives in its own module, github.com/xraph/weave/embedder/nexus, so the root weave module never pulls in nexus. Build it with:

emb := nexus.New(ext.Gateway, "text-embedding-3-small", 1536,
	nexus.WithProvider("knowledge"))

Every call needs a weave tenant on the context (weave.WithTenant). The spend goes to the nexus tenant on the context when the host set one with nexus's pipeline.WithTenantID, and otherwise to the weave tenant passed through WithTenantMapper (by default, unchanged).

Every request asks for exactly the configured dimensions, so the provider nexus routes to has to be able to shorten vectors for the model. On OpenAI's own endpoint that means text-embedding-3-small or text-embedding-3-large.

Index

Constants

This section is empty.

Variables

View Source
var ErrGatewayUnavailable = errors.New("weave: nexus gateway not available")

ErrGatewayUnavailable is returned while gw() still answers nil, and while the gateway it answered is not initialized yet (wrapping nexus.ErrNotInitialized). Both clear up once nexus has started, so a host can retry.

Functions

func New

func New(gw func() *nexusgw.Gateway, model string, dimensions int, opts ...Option) embedder.Embedder

New returns an embedder that calls gw's engine with model and asks for vectors of exactly dimensions numbers. It does not call gw. The first Embed resolves it and caches the first non-nil gateway, so a host can pass nexus's extension method value (ext.Gateway) before nexus has started.

Types

type Embedder

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

Embedder embeds texts through a nexus gateway. Build it with New.

func (*Embedder) Describe

func (e *Embedder) Describe() weave.ComponentInfo

Describe reports the nexus embedder, its model and dimensions, and the provider when WithProvider named one.

func (*Embedder) Dimensions

func (e *Embedder) Dimensions() int

Dimensions returns the configured vector size.

func (*Embedder) Embed

func (e *Embedder) Embed(ctx context.Context, texts []string) ([]embedder.EmbedResult, error)

Embed returns one vector per text, in input order, sending at most the batch size per nexus request. It needs a weave tenant on ctx; see the package documentation for who the spend is charged to.

type Option

type Option func(*Embedder)

Option configures the nexus embedder.

func WithBatchSize

func WithBatchSize(n int) Option

WithBatchSize caps the texts per nexus request (default 256). A value below 1 keeps the default.

func WithProvider

func WithProvider(name string) Option

WithProvider names the nexus provider every request goes to, by its registered name (EmbeddingRequest.Provider). Without it nexus routes by model, which picks the wrong provider and key when a chat provider also lists the embedding model.

func WithTenantMapper

func WithTenantMapper(fn func(ctx context.Context, weaveTenant string) (string, error)) Option

WithTenantMapper turns the weave tenant into the nexus tenant ID the request is attributed to. The default passes it through unchanged, which suits hosts whose weave tenants are nexus tenant IDs. A mapper that returns "" refuses the call with weave.ErrTenantRequired, and its error comes back wrapped. A nil fn keeps the default.

Jump to

Keyboard shortcuts

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