Skip to content

Reject non-finite values in embedding vectors#263

Open
henryperkins wants to merge 2 commits into
WordPress:trunkfrom
henryperkins:fix/embedding-finite-values
Open

Reject non-finite values in embedding vectors#263
henryperkins wants to merge 2 commits into
WordPress:trunkfrom
henryperkins:fix/embedding-finite-values

Conversation

@henryperkins

@henryperkins henryperkins commented Jul 15, 2026

Copy link
Copy Markdown

Summary

  • Reject NAN, INF, and -INF at the Embedding constructor boundary.
  • Preserve the existing behavior for finite floats and integers.
  • Add regression coverage for each non-finite value.

Fixes #262.

Why

Non-finite values satisfy PHP's is_float() check but cannot be represented in JSON. Rejecting them when constructing an Embedding prevents an invalid result object from failing later during serialization, logging, caching, persistence, or custom provider handling.

Testing

A test-only commit first demonstrated the gap: all three new cases failed because no InvalidArgumentException was thrown.

After the implementation commit:

  • Unit tests pass on PHP 7.4, 8.0, 8.4, and 8.5.
  • The PHP 8.4 coverage job passes.
  • Composer validation, PHPStan, and PHPCS pass.

AI assistance

  • AI assistance: Yes
  • Tool: OpenAI Codex
  • Used for: Repository inspection, regression-test design, implementation, and verification. Henry reviewed the scope and remains responsible for the contribution.

@codecov

codecov Bot commented Jul 15, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 86.50%. Comparing base (a31b0ec) to head (1cd9a52).

Additional details and impacted files
@@            Coverage Diff            @@
##              trunk     #263   +/-   ##
=========================================
  Coverage     86.49%   86.50%           
- Complexity     1327     1330    +3     
=========================================
  Files            68       68           
  Lines          4295     4298    +3     
=========================================
+ Hits           3715     3718    +3     
  Misses          580      580           
Flag Coverage Δ
unit 86.50% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@henryperkins
henryperkins marked this pull request as ready for review July 15, 2026 07:56
@github-actions

Copy link
Copy Markdown

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: henryperkins <htperkins@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@henryperkins
henryperkins marked this pull request as draft July 15, 2026 11:33
@henryperkins
henryperkins marked this pull request as ready for review July 15, 2026 11:34

Copy link
Copy Markdown
Author

One downstream coordination note: WordPress/wordpress-develop#12530 currently imports PHP AI Client 1.4.0 for the WordPress 7.1 embedding API, so its vendored Embedding.php contains this same validation gap.

If this fix looks right, would a 1.4.1 patch release followed by updating #12530 to that tag be the cleanest path? I’m not suggesting this should block the Core wrapper review—just flagging the dependency while the import is still open.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Embedding accepts non-finite floating-point values

1 participant