UNPKG

ai-zero-shot-classifier

Version:

🧠 powerful JavaScript library that leverages advanced AI embeddings to perform zero-shot text classification. Whether you're dealing with unlabelled data or seeking to classify text against dynamic and user-defined labels, this library provides a seamles

33 lines (30 loc) • 950 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = dotProductSimilarity; /** * Computes the dot product similarity between two numerical vectors. * * @param {number[]} a - The first input vector. * @param {number[]} b - The second input vector. * @returns {number} - The dot product similarity between vectors `a` and `b`. * Returns 0 if both vectors are zero. * * @complexity * Time Complexity: O(n) * - The function processes each element of the vectors `a` and `b` exactly once in a single loop. * * Space Complexity: O(1) * - The function uses a constant amount of extra space regardless of the input size. */ function dotProductSimilarity(a, b) { var dotProduct = 0; // Compute the dot product for (var i = 0; i < a.length; i += 1) { dotProduct += a[i] * b[i]; } // If dotProduct is zero, fallback to 0 return dotProduct; } //# sourceMappingURL=dotProduct.js.map