Attributes#
| Attribute | Type | Description |
|---|---|---|
resolver | RequestResolver[EmbeddingRequest, E.AiError] |
Functions#
__init__#
__init__(resolver, _embed_many) -> None| Parameter | Type | Description |
|---|---|---|
resolver | RequestResolver[EmbeddingRequest, E.AiError] | |
_embed_many | EmbedMany |
embed#
embed(input) -> Effect[EmbedResponse, E.AiError]The vector of input. Concurrent calls (with the same
batch_key) share one provider call; fails with the provider's
AiError, or an InvalidOutputError one when the provider
returns another number of vectors than it was given inputs.
| Parameter | Type | Description |
|---|---|---|
input | str |
Returns Effect[EmbedResponse, E.AiError]
def embed(self, input: str) -> Effect[EmbedResponse, E.AiError]:
"""The vector of ``input``. Concurrent calls (with the same
``batch_key``) share one provider call; fails with the provider's
``AiError``, or an ``InvalidOutputError`` one when the provider
returns another number of vectors than it was given inputs."""
return _request(EmbeddingRequest(input), self.resolver).with_span("EmbeddingModel.embed")embed_many#
embed_many(inputs) -> Effect[EmbedManyResponse, E.AiError]The vectors of inputs in order, with the provider's token
usage, from one provider call (none for no inputs). Fails with the
provider's AiError, or an InvalidOutputError one when the
provider returns another number of vectors.
| Parameter | Type | Description |
|---|---|---|
inputs | Sequence[str] |
Returns Effect[EmbedManyResponse, E.AiError]
def embed_many(self, inputs: Sequence[str]) -> Effect[EmbedManyResponse, E.AiError]:
"""The vectors of ``inputs`` in order, with the provider's token
usage, from one provider call (none for no inputs). Fails with the
provider's ``AiError``, or an ``InvalidOutputError`` one when the
provider returns another number of vectors."""
inputs = tuple(inputs)
if not inputs:
return fx.succeed(EmbedManyResponse(())).with_span("EmbeddingModel.embedMany")
return (
fx.suspend(lambda: self._embed_many(ProviderOptions(inputs)))
.flat_map(
lambda response: _vectors(len(inputs), response).map(
lambda embeddings: EmbedManyResponse(
embeddings, EmbeddingUsage(response.input_tokens)
)
)
)
.with_span("EmbeddingModel.embedMany")
)