UNPKG

mongodb-rag-core

Version:

Common elements used by MongoDB Chatbot Framework components.

24 lines (22 loc) 1.27 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.computeNormalizedLogisticalExecutionTime = void 0; const assert_1 = require("assert"); /** Computes a normalized execution time score comparing a generated query's execution time to a reference execution time. The score ranges from 0 to 1, where: - 1 means the generated query is as fast or faster than the reference - 0 means the generated query is significantly slower - Score is computed using a logistical function with a configurable alpha parameter @param generatedTimeMs - Execution time of the generated query in milliseconds @param referenceTimeMs - Reference (ideal) execution time in milliseconds @returns A score between 0 and 1 */ function computeNormalizedLogisticalExecutionTime(generatedTimeMs, referenceTimeMs, alpha = 1) { (0, assert_1.strict)(generatedTimeMs > 0 && referenceTimeMs > 0, "Execution times must be greater than 0"); const ratio = generatedTimeMs / referenceTimeMs; const score = 1 / (1 + alpha * (ratio - 1)); return Math.max(0, Math.min(1, score)); } exports.computeNormalizedLogisticalExecutionTime = computeNormalizedLogisticalExecutionTime; //# sourceMappingURL=computeNormalizedLogisticalExecutionTime.js.map