File tree 2 files changed +8
-8
lines changed
2 files changed +8
-8
lines changed Original file line number Diff line number Diff line change @@ -448,7 +448,7 @@ console.log('Squared Euclidean Distance:', distance);
448
448
```
449
449
450
450
Other numeric types and precision levels are supported as well.
451
- For double-precsion floating-point numbers, use ` Float64Array ` :
451
+ For double-precision floating-point numbers, use ` Float64Array ` :
452
452
453
453
``` js
454
454
const vectorA = new Float64Array ([1.0 , 2.0 , 3.0 ]);
@@ -457,11 +457,11 @@ const distance = cosine(vectorA, vectorB);
457
457
```
458
458
459
459
When doing machine learning and vector search with high-dimensional vectors you may want to quantize them to 8-bit integers.
460
- You may want to project values from the $[ -1, 1] $ range to the $[ -100, 100 ] $ range and then cast them to ` Uint8Array ` :
460
+ You may want to project values from the $[ -1, 1] $ range to the $[ -127, 127 ] $ range and then cast them to ` Int8Array ` :
461
461
462
462
``` js
463
- const quantizedVectorA = new Uint8Array (vectorA .map (v => (v * 100 )));
464
- const quantizedVectorB = new Uint8Array (vectorB .map (v => (v * 100 )));
463
+ const quantizedVectorA = new Int8Array (vectorA .map (v => (v * 127 )));
464
+ const quantizedVectorB = new Int8Array (vectorB .map (v => (v * 127 )));
465
465
const distance = cosine (quantizedVectorA, quantizedVectorB);
466
466
```
467
467
Original file line number Diff line number Diff line change @@ -83,20 +83,20 @@ export const jaccard = (a: Uint8Array, b: Uint8Array): number => {
83
83
} ;
84
84
85
85
/**
86
- * @brief Computes the kullbackleibler similarity coefficient between two vectors.
86
+ * @brief Computes the Kullback-Leibler divergence between two vectors.
87
87
* @param {Float64Array|Float32Array } a - The first vector.
88
88
* @param {Float64Array|Float32Array } b - The second vector.
89
- * @returns {number } The Jaccard similarity coefficient between vectors a and b.
89
+ * @returns {number } The Kullback-Leibler divergence between vectors a and b.
90
90
*/
91
91
export const kullbackleibler = ( a : Float64Array | Float32Array , b : Float64Array | Float32Array ) : number => {
92
92
return compiled . kullbackleibler ( a , b ) ;
93
93
} ;
94
94
95
95
/**
96
- * @brief Computes the jensenshannon similarity coefficient between two vectors.
96
+ * @brief Computes the Jensen-Shannon divergence between two vectors.
97
97
* @param {Float64Array|Float32Array } a - The first vector.
98
98
* @param {Float64Array|Float32Array } b - The second vector.
99
- * @returns {number } The Jaccard similarity coefficient between vectors a and b.
99
+ * @returns {number } The Jensen-Shannon divergence between vectors a and b.
100
100
*/
101
101
export const jensenshannon = ( a : Float64Array | Float32Array , b : Float64Array | Float32Array ) : number => {
102
102
return compiled . jensenshannon ( a , b ) ;
You can’t perform that action at this time.
0 commit comments