Summary
Embedding currently accepts NAN, INF, and -INF. Its internal validation checks only whether each value is an integer or float, so these non-finite floats pass validation even though they cannot be represented in JSON.
I observed this on PHP 8.3 against 860ce29 while #244 was open. The same validation remains in 66fa4d7, the final head that was merged.
Reproduction
use WordPress\AiClient\Results\DTO\Embedding;
foreach ([NAN, INF, -INF] as $value) {
$embedding = new Embedding([$value], 1);
var_dump(json_encode($embedding));
echo json_last_error_msg() . PHP_EOL;
}
Each Embedding constructs successfully, but json_encode() returns false with:
Inf and NaN cannot be JSON encoded
The relevant check is in Embedding::isEmbeddingList().
Expected behavior
I think the safest boundary is for Embedding to reject non-finite floats with InvalidArgumentException, consistent with its existing list, numeric-type, and dimension validation. That prevents an invalid result object from reaching JSON serialization, logging, caching, persistence, or a custom provider integration.
Suggested coverage
Add regression coverage for:
NAN
INF
-INF
- ordinary finite floats and integers continuing to be accepted
A focused check such as is_float($value) && !is_finite($value) would preserve the existing integer behavior.
Context
Embedding support was introduced in #244, which implemented #242.
Summary
Embeddingcurrently acceptsNAN,INF, and-INF. Its internal validation checks only whether each value is an integer or float, so these non-finite floats pass validation even though they cannot be represented in JSON.I observed this on PHP 8.3 against
860ce29while #244 was open. The same validation remains in66fa4d7, the final head that was merged.Reproduction
Each
Embeddingconstructs successfully, butjson_encode()returnsfalsewith:The relevant check is in
Embedding::isEmbeddingList().Expected behavior
I think the safest boundary is for
Embeddingto reject non-finite floats withInvalidArgumentException, consistent with its existing list, numeric-type, and dimension validation. That prevents an invalid result object from reaching JSON serialization, logging, caching, persistence, or a custom provider integration.Suggested coverage
Add regression coverage for:
NANINF-INFA focused check such as
is_float($value) && !is_finite($value)would preserve the existing integer behavior.Context
Embedding support was introduced in #244, which implemented #242.