-
Notifications
You must be signed in to change notification settings - Fork 87
Reject non-finite values in embedding vectors #263
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: trunk
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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.'); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm wondering if this should be May be nice to return the index and value so a user can track down where things went wrong though |
||
| } | ||
| } | ||
|
|
||
| if (count($values) !== $dimensions) { | ||
| throw new InvalidArgumentException('Embedding vector length must match dimensions.'); | ||
| } | ||
|
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We could likely have better test coverage here. For instance, no new tests for |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As is mentioned elsewhere, I'd move this into
isEmbeddingListso we aren't iterating over everything twice. Those iterations add up when dealing with 3072 dimension vector, for instance