Embeddings¶
The embedding port, a callable embedder and its cache. Concepts: Embeddings.
Embeddings: the EmbeddingPort, CallableEmbedder for any host function, and its cache.
CallableEmbedder
¶
Wraps fn(texts) with batching, an optional per-text cache, a ledger entry and events.
A sync fn runs in a worker thread with the caller's contextvars. timeout_s bounds each
fn call; a timed-out thread is abandoned, not stopped.
Raises:
| Type | Description |
|---|---|
ConfigError
|
a bad |
ToolUsageError
|
|
embed(texts, *, ctx=None)
async
¶
Vectors for texts, in order; repeated texts are embedded once.
Raises:
| Type | Description |
|---|---|
ToolUsageError
|
|
ModelTimeout
|
one |
ModelOutputInvalid
|
|
ModelError
|
|
EmbeddingCache
¶
EmbeddingPort
¶
Bases: Protocol
Turns texts into vectors; raises ModelError subclasses.
EmbeddingResult
¶
Bases: BaseModel
Vectors in input order, the model that made them, its usage and the cache hits.
embed_key(namespace, text, *, provider, model)
¶
Key for one text's vector; the text appears only as a digest.