import { createLogger } from "../logger.js";
const log = createLogger("search");
function reciprocalRankFusion(lists, k = 60) {
  try {
    const scores = /* @__PURE__ */ new Map();
    for (const list of lists) {
      for (const [url, rank] of list) {
        const contribution = 1 / (k + rank);
        scores.set(url, (scores.get(url) ?? 0) + contribution);
      }
    }
    log.debug("RRF fusion complete", {
      inputLists: lists.length,
      uniqueUrls: scores.size
    });
    return scores;
  } catch (err) {
    log.error("RRF fusion failed", { error: String(err) });
    return /* @__PURE__ */ new Map();
  }
}
function sortByRRFScore(scores) {
  return [...scores.entries()].sort((a, b) => b[1] - a[1]);
}
function buildRankMap(urls) {
  const rankMap = /* @__PURE__ */ new Map();
  for (let i = 0; i < urls.length; i++) {
    if (!rankMap.has(urls[i])) {
      rankMap.set(urls[i], i + 1);
    }
  }
  return rankMap;
}
export {
  buildRankMap,
  reciprocalRankFusion,
  sortByRRFScore
};
//# sourceMappingURL=rrf.js.map