dotProduct function exported ✓ 100.0%
Last updated: 2026-02-24T19:46:21.789Z
Location
Metrics
LOC: 6
Complexity: 2
Params: 2
Coverage: 100.0% (4/4 lines, 3x executed)
Signature
dotProduct(a: Float32Array, b: Float32Array): : number
Summary
Computes the dot product between two L2-normalised vectors. Since vectors are expected to be L2-normalised beforehand, the dot product is equivalent to cosine similarity. Returns a similarity score in range [-1, 1]. For frequency-based n-gram vectors, the range will typically be [0, 1].
Source Code
export function dotProduct(a: Float32Array, b: Float32Array): number {
let sum = 0;
const len = Math.min(a.length, b.length);
for (let i = 0; i < len; i++) sum += a[i] * b[i];
return sum;
}
No outgoing dependencies.
Impact (Incoming)
| Source | Type |
|---|---|
| PretrainedState | uses |
| resetModelMock | uses |