From 12b512b0dd1276ff8ddfc9c205e66b850f4a3ffe Mon Sep 17 00:00:00 2001 From: Henry Perkins Date: Wed, 15 Jul 2026 02:47:18 -0500 Subject: [PATCH 1/2] Add regression coverage for non-finite embeddings --- tests/unit/Results/DTO/EmbeddingTest.php | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/tests/unit/Results/DTO/EmbeddingTest.php b/tests/unit/Results/DTO/EmbeddingTest.php index 00d17aa5..172dfb91 100644 --- a/tests/unit/Results/DTO/EmbeddingTest.php +++ b/tests/unit/Results/DTO/EmbeddingTest.php @@ -73,4 +73,27 @@ public function testValuesMustBeNumeric(): void new Embedding([0.1, '0.2'], 2); } + + /** + * @dataProvider nonFiniteValueProvider + */ + public function testValuesMustBeFinite(float $value): void + { + $this->expectException(InvalidArgumentException::class); + $this->expectExceptionMessage('Embedding values must be finite numbers.'); + + new Embedding([0.1, $value], 2); + } + + /** + * @return array + */ + public static function nonFiniteValueProvider(): array + { + return [ + 'NAN' => [NAN], + 'INF' => [INF], + '-INF' => [-INF], + ]; + } } From 1cd9a52081851f4f8f4a81ce16d3205925481836 Mon Sep 17 00:00:00 2001 From: Henry Perkins Date: Wed, 15 Jul 2026 02:48:52 -0500 Subject: [PATCH 2/2] Reject non-finite embedding vector values --- src/Results/DTO/Embedding.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/Results/DTO/Embedding.php b/src/Results/DTO/Embedding.php index 076109c6..4dbfb4b4 100644 --- a/src/Results/DTO/Embedding.php +++ b/src/Results/DTO/Embedding.php @@ -54,6 +54,12 @@ public function __construct(array $values, int $dimensions) throw new InvalidArgumentException('Embedding values must be integers or floats.'); } + foreach ($values as $value) { + if (is_float($value) && !is_finite($value)) { + throw new InvalidArgumentException('Embedding values must be finite numbers.'); + } + } + if (count($values) !== $dimensions) { throw new InvalidArgumentException('Embedding vector length must match dimensions.'); }