export const normalize = (vector) => {
    let sum = 0;
    for (let i = 0; i < vector.length; i++) {
        sum += vector[i] * vector[i];
    }
    return Math.sqrt(sum);
};
export const dotProduct = (arr1, arr2) => {
    let sum = 0;
    for (let i = 0; i < arr1.length; i++) {
        sum += arr1[i] * arr2[i];
    }
    return sum;
};
export const normalizedCosineSimilarity = (vector1, norm1, vector2, norm2) => {
    return dotProduct(vector1, vector2) / (norm1 * norm2);
};
export const splitArray = (input, maxLength, maxTokens, countTokens) => {
    const result = [];
    let currentSubArray = [];
    let currentTokens = 0;
    for (const str of input) {
        const strTokens = countTokens(str);
        if (currentSubArray.length + 1 > maxLength || currentTokens + strTokens > maxTokens) {
            result.push(currentSubArray);
            currentSubArray = [str];
            currentTokens = strTokens;
        }
        else {
            currentSubArray.push(str);
            currentTokens += strTokens;
        }
    }
    if (currentSubArray.length > 0) {
        result.push(currentSubArray);
    }
    return result;
};
