class PendingEmbeddingsGeneration

Traits

Constants

DEFAULT_CACHE_SECONDS

Properties

protected array<string, string>|SerializableClosure $headers from  ResolvesProviderOptions
protected array<string, mixed>|SerializableClosure $providerOptions from  ResolvesProviderOptions
protected int|null $dimensions
protected int|null $cacheSeconds
protected bool|null $shouldCache
protected bool|null $cacheIndividually
protected int $timeout

Methods

mixed
when(mixed $value = null, callable|null $callback = null, callable|null $default = null)

Apply the callback if the given "value" is (or resolves to) truthy.

mixed
unless(mixed $value = null, callable|null $callback = null, callable|null $default = null)

Apply the callback if the given "value" is (or resolves to) falsy.

withHeaders(array|Closure $headers)

Specify HTTP headers for the request. Closures may only capture serializable values.

withProviderOptions(array|Closure $options)

Specify provider-specific options for the request.

array
resolveProviderOptionsAndHeaders(Provider $provider)

Resolve the request body options and HTTP headers for the given provider.

array
queuedProviderOptions()

Get the serializable provider options recorded by queued fakes.

__construct(array $inputs)

Create a new pending embeddings generation instance.

dimensions(int $dimensions)

Specify the dimensions for the embeddings.

cache(int|null $seconds = null, bool|null $individually = null)

Enable or disable caching for this embedding request.

timeout(int $seconds = 30)

Specify the timeout (in seconds) for the embeddings generation.

generate(Provider|Lab|array|string|null $provider = null, string|null $model = null)

Generate the embeddings.

generateWithSharedCaching(EmbeddingProvider $provider, string $model, int $dimensions, array $providerOptions, array|null $identity)

Generate the embeddings, caching the entire response under a single shared key.

generateWithIndividualCaching(EmbeddingProvider $provider, string $model, int $dimensions, array $providerOptions, array $identity)

Generate the embeddings, caching each input's embedding individually.

generateFromCache(string $key)

Generate the embeddings from a cached response if possible.

void
cacheEmbeddings(string $key, EmbeddingsResponse $response)

Cache the given embeddings response under a single shared key.

array
cachedIndividualEmbeddings(array $keys)

Get the individually cached embeddings for the inputs, keyed by input index.

void
cacheIndividualEmbeddings(array $keys, array $embeddings)

Cache the given embeddings individually, keyed by input index.

array
cacheIdentity(EmbeddingProvider $provider, string $model, int $dimensions, array $providerOptions)

Resolve the scope and effective provider identity for a cached attempt.

string
cacheKey(array $identity)

Get the shared cache key for the entire embeddings request.

string
individualCacheKey(array $identity, mixed $input)

Get the cache key for an individual embeddings input.

string
fingerprintProviderOptions(array $providerOptions)

Fingerprint the normalized provider options.

mixed
normalizeForFingerprint(mixed $value)

Recursively sort associative keys so the fingerprint is insensitive to key order.

array
normalizeInputForCache(mixed $input)

Normalize an embeddings input into a deterministic cache representation.

queue(Provider|Lab|array|string|null $provider = null, string|null $model = null)

Queue the generation of the embeddings.

cacheStore()

Get the cache store for embeddings.

bool
shouldCache()

Determine if embeddings should be cached.

bool
shouldCacheIndividually()

Determine if embeddings should be cached individually per input.

Details

in Conditionable at line 23
mixed when(mixed $value = null, callable|null $callback = null, callable|null $default = null)

Apply the callback if the given "value" is (or resolves to) truthy.

Parameters

mixed $value
callable|null $callback
callable|null $default

Return Value

mixed

in Conditionable at line 56
mixed unless(mixed $value = null, callable|null $callback = null, callable|null $default = null)

Apply the callback if the given "value" is (or resolves to) falsy.

Parameters

mixed $value
callable|null $callback
callable|null $default

Return Value

mixed

ResolvesProviderOptions withHeaders(array|Closure $headers)

Specify HTTP headers for the request. Closures may only capture serializable values.

Parameters

array|Closure $headers

Return Value

ResolvesProviderOptions

ResolvesProviderOptions withProviderOptions(array|Closure $options)

Specify provider-specific options for the request.

Parameters

array|Closure $options

Return Value

ResolvesProviderOptions

protected array resolveProviderOptionsAndHeaders(Provider $provider)

Resolve the request body options and HTTP headers for the given provider.

Unlike upstream, accept the contract so custom provider implementations need not extend the base class.

Parameters

Provider $provider

Return Value

array

protected array queuedProviderOptions()

Get the serializable provider options recorded by queued fakes.

Return Value

array

at line 62
__construct(array $inputs)

Create a new pending embeddings generation instance.

Parameters

array $inputs

Exceptions

InvalidArgumentException

at line 93
PendingEmbeddingsGeneration dimensions(int $dimensions)

Specify the dimensions for the embeddings.

Parameters

int $dimensions

Return Value

PendingEmbeddingsGeneration

at line 103
PendingEmbeddingsGeneration cache(int|null $seconds = null, bool|null $individually = null)

Enable or disable caching for this embedding request.

Parameters

int|null $seconds
bool|null $individually

Return Value

PendingEmbeddingsGeneration

at line 123
PendingEmbeddingsGeneration timeout(int $seconds = 30)

Specify the timeout (in seconds) for the embeddings generation.

Parameters

int $seconds

Return Value

PendingEmbeddingsGeneration

at line 135
EmbeddingsResponse generate(Provider|Lab|array|string|null $provider = null, string|null $model = null)

Generate the embeddings.

Parameters

Provider|Lab|array|string|null $provider
string|null $model

Return Value

EmbeddingsResponse

Exceptions

FailoverableException

at line 185
protected EmbeddingsResponse generateWithSharedCaching(EmbeddingProvider $provider, string $model, int $dimensions, array $providerOptions, array|null $identity)

Generate the embeddings, caching the entire response under a single shared key.

Parameters

EmbeddingProvider $provider
string $model
int $dimensions
array $providerOptions
array|null $identity

null when caching is disabled

Return Value

EmbeddingsResponse

at line 211
protected EmbeddingsResponse generateWithIndividualCaching(EmbeddingProvider $provider, string $model, int $dimensions, array $providerOptions, array $identity)

Generate the embeddings, caching each input's embedding individually.

Parameters

EmbeddingProvider $provider
string $model
int $dimensions
array $providerOptions
array $identity

Return Value

EmbeddingsResponse

Exceptions

EmbeddingsCountMismatchException

at line 246
protected EmbeddingsResponse|null generateFromCache(string $key)

Generate the embeddings from a cached response if possible.

Parameters

string $key

Return Value

EmbeddingsResponse|null

at line 265
protected void cacheEmbeddings(string $key, EmbeddingsResponse $response)

Cache the given embeddings response under a single shared key.

Parameters

string $key
EmbeddingsResponse $response

Return Value

void

at line 280
protected array cachedIndividualEmbeddings(array $keys)

Get the individually cached embeddings for the inputs, keyed by input index.

Parameters

array $keys

Return Value

array

at line 305
protected void cacheIndividualEmbeddings(array $keys, array $embeddings)

Cache the given embeddings individually, keyed by input index.

Parameters

array $keys
array $embeddings

Return Value

void

at line 325
protected array cacheIdentity(EmbeddingProvider $provider, string $model, int $dimensions, array $providerOptions)

Resolve the scope and effective provider identity for a cached attempt.

Parameters

EmbeddingProvider $provider
string $model
int $dimensions
array $providerOptions

Return Value

array

at line 348
protected string cacheKey(array $identity)

Get the shared cache key for the entire embeddings request.

Parameters

array $identity

Return Value

string

at line 361
protected string individualCacheKey(array $identity, mixed $input)

Get the cache key for an individual embeddings input.

Parameters

array $identity
mixed $input

Return Value

string

at line 374
protected string fingerprintProviderOptions(array $providerOptions)

Fingerprint the normalized provider options.

Parameters

array $providerOptions

Return Value

string

at line 388
protected mixed normalizeForFingerprint(mixed $value)

Recursively sort associative keys so the fingerprint is insensitive to key order.

Parameters

mixed $value

Return Value

mixed

at line 406
protected array normalizeInputForCache(mixed $input)

Normalize an embeddings input into a deterministic cache representation.

Parameters

mixed $input

Return Value

array

at line 454
QueuedEmbeddingsResponse queue(Provider|Lab|array|string|null $provider = null, string|null $model = null)

Queue the generation of the embeddings.

Parameters

Provider|Lab|array|string|null $provider
string|null $model

Return Value

QueuedEmbeddingsResponse

at line 477
protected Repository cacheStore()

Get the cache store for embeddings.

Return Value

Repository

at line 485
protected bool shouldCache()

Determine if embeddings should be cached.

Return Value

bool

at line 497
protected bool shouldCacheIndividually()

Determine if embeddings should be cached individually per input.

Return Value

bool