Documentation
¶
Overview ¶
Package embed is the public embedding boundary, the twin of pkg/llm for vectors (20260902-114838-d-tac-cov): one two-method interface over pure request and result types, sharing Identity, Usage, and the call record with the chat side, plus the same three decorators. Provider adapters and the configuration that selects them stay at each host's composition site.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Embedder ¶
type Embedder interface {
Embed(ctx context.Context, req Request) (Result, error)
Fingerprint() string
}
Embedder is the single port. Embed returns exactly len(req.Texts) vectors in order and fills Result.Identity on success; a failed call may attribute itself through *llm.Error. Fingerprint identifies the vector space the embedder produces and must be stable across calls: two embedders whose document vectors are comparable share it, two whose vectors are not, do not.
func Batched ¶
Batched decorates an Embedder so one request is served as calls of at most size texts each, in order, with the vectors concatenated and the usage summed. Batch size is a composition value like a deadline or a rate, so an adapter can stay a transport that sends exactly one request per Embed: decorators inside Batched then apply per round-trip, decorators outside apply per call. Identity is taken from the first call; the first failure aborts the rest and is returned as is.
func Bounded ¶
Bounded decorates an Embedder with a per-call deadline over the whole Embed, however many transport round-trips the adapter makes for it.
func Observed ¶
Observed decorates an Embedder so every call hands one llm.CallStat to sink, with Items set to the batch size and Usage taken from the result. Failure attribution and the nil-sink behaviour match llm.Observed.
func RateLimited ¶
RateLimited decorates an Embedder with a token-bucket limiter of rps calls per second. The burst is one second's worth of calls, at least one.
type EmbedderFunc ¶
EmbedderFunc adapts a function to Embedder for test doubles and stubs; Space is what Fingerprint returns.
func (EmbedderFunc) Fingerprint ¶
func (f EmbedderFunc) Fingerprint() string
type Purpose ¶
type Purpose string
Purpose names which side of retrieval a batch serves. Instruction-tuned encoders want different prefixes on documents and queries, so an adapter selects its template by purpose; the value doubles as the observability dimension, the same as a chat Purpose.