PendingEmbeddingsGeneration
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
Apply the callback if the given "value" is (or resolves to) truthy.
Apply the callback if the given "value" is (or resolves to) falsy.
Specify HTTP headers for the request. Closures may only capture serializable values.
Resolve the request body options and HTTP headers for the given provider.
Get the serializable provider options recorded by queued fakes.
Create a new pending embeddings generation instance.
Specify the dimensions for the embeddings.
Enable or disable caching for this embedding request.
Specify the timeout (in seconds) for the embeddings generation.
Generate the embeddings, caching the entire response under a single shared key.
Generate the embeddings, caching each input's embedding individually.
Generate the embeddings from a cached response if possible.
Cache the given embeddings response under a single shared key.
Get the individually cached embeddings for the inputs, keyed by input index.
Cache the given embeddings individually, keyed by input index.
Resolve the scope and effective provider identity for a cached attempt.
Get the shared cache key for the entire embeddings request.
Get the cache key for an individual embeddings input.
Fingerprint the normalized provider options.
Recursively sort associative keys so the fingerprint is insensitive to key order.
Normalize an embeddings input into a deterministic cache representation.
Get the cache store for embeddings.
Determine if embeddings should be cached.
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.
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.
in
ResolvesProviderOptions at line 24
ResolvesProviderOptions
withHeaders(array|Closure $headers)
Specify HTTP headers for the request. Closures may only capture serializable values.
in
ResolvesProviderOptions at line 38
ResolvesProviderOptions
withProviderOptions(array|Closure $options)
Specify provider-specific options for the request.
in
ResolvesProviderOptions at line 54
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.
in
ResolvesProviderOptions at line 67
protected array
queuedProviderOptions()
Get the serializable provider options recorded by queued fakes.
at line 62
__construct(array $inputs)
Create a new pending embeddings generation instance.
at line 93
PendingEmbeddingsGeneration
dimensions(int $dimensions)
Specify the dimensions for the embeddings.
at line 103
PendingEmbeddingsGeneration
cache(int|null $seconds = null, bool|null $individually = null)
Enable or disable caching for this embedding request.
at line 123
PendingEmbeddingsGeneration
timeout(int $seconds = 30)
Specify the timeout (in seconds) for the embeddings generation.
at line 135
EmbeddingsResponse
generate(Provider|Lab|array|string|null $provider = null, string|null $model = null)
Generate the embeddings.
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.
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.
at line 246
protected EmbeddingsResponse|null
generateFromCache(string $key)
Generate the embeddings from a cached response if possible.
at line 265
protected void
cacheEmbeddings(string $key, EmbeddingsResponse $response)
Cache the given embeddings response under a single shared key.
at line 280
protected array
cachedIndividualEmbeddings(array $keys)
Get the individually cached embeddings for the inputs, keyed by input index.
at line 305
protected void
cacheIndividualEmbeddings(array $keys, array $embeddings)
Cache the given embeddings individually, keyed by input index.
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.
at line 348
protected string
cacheKey(array $identity)
Get the shared cache key for the entire embeddings request.
at line 361
protected string
individualCacheKey(array $identity, mixed $input)
Get the cache key for an individual embeddings input.
at line 374
protected string
fingerprintProviderOptions(array $providerOptions)
Fingerprint the normalized provider options.
at line 388
protected mixed
normalizeForFingerprint(mixed $value)
Recursively sort associative keys so the fingerprint is insensitive to key order.
at line 406
protected array
normalizeInputForCache(mixed $input)
Normalize an embeddings input into a deterministic cache representation.
at line 454
QueuedEmbeddingsResponse
queue(Provider|Lab|array|string|null $provider = null, string|null $model = null)
Queue the generation of the embeddings.
at line 477
protected Repository
cacheStore()
Get the cache store for embeddings.
at line 485
protected bool
shouldCache()
Determine if embeddings should be cached.
at line 497
protected bool
shouldCacheIndividually()
Determine if embeddings should be cached individually per input.