mongodb-rag-core
Version:
Common elements used by MongoDB Chatbot Framework components.
23 lines • 1.16 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.makeBoostOnAtlasSearchFilter = void 0;
/**
Boost certain results in search results from Atlas Search.
*/
function makeBoostOnAtlasSearchFilter({ findNearestNeighborsOptions, totalMaxK, shouldBoostFunc, }) {
if (findNearestNeighborsOptions.k > totalMaxK) {
throw new Error(`findNearestNeighborsOptions.k (${findNearestNeighborsOptions.k}) must be less than or equal to totalMaxK (${totalMaxK})`);
}
return {
shouldBoost: shouldBoostFunc,
boost: async function ({ embedding, store, existingResults, }) {
const boostedResults = await store.findNearestNeighbors(embedding, findNearestNeighborsOptions);
const newResults = existingResults.filter((result) => boostedResults.every((manualResult) => manualResult.text !== result.text));
return [...boostedResults, ...newResults]
.sort((a, b) => b.score - a.score)
.slice(0, totalMaxK);
},
};
}
exports.makeBoostOnAtlasSearchFilter = makeBoostOnAtlasSearchFilter;
//# sourceMappingURL=BoostOnAtlasSearchFilter.js.map