Skip to content

Commit 50e0b71

Browse files
Update demos/embeddings/search.js
Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>
1 parent 3d760e0 commit 50e0b71

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

demos/embeddings/search.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,13 @@ class SemanticSearch {
5959
throw new Error('Vectors must have the same length');
6060
}
6161

62+
// Validate that all elements are finite numbers
63+
for (let i = 0; i < vecA.length; i++) {
64+
if (!Number.isFinite(vecA[i]) || !Number.isFinite(vecB[i])) {
65+
throw new Error('Vectors must not contain NaN or infinite values');
66+
}
67+
}
68+
6269
let dotProduct = 0;
6370
let normA = 0;
6471
let normB = 0;

0 commit comments

Comments
 (0)