WordPress / WordPress/php-ai-client
Embedding accepts non-finite floating-point values
Nobody has claimed this yet.
- Dominant language
- PHP
- Stars
- 308
- Forks
- 84
- Avg merge
- 7d 21h
- Merged PRs (30d)
- 2
Description
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:
NANINF-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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reading src/Results/DTO/Embedding.php, especially Embedding::isEmbeddingList() and its existing validation. Add regression coverage for NAN, INF, -INF, finite floats, and integers; done means non-finite values are rejected while valid numeric embeddings remain accepted.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php
- Domain
- backend-api-design
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 78/100