import {
  DEFAULT_PPR_DAMPING,
  DEFAULT_PPR_ITERATIONS,
  buildGraphFromMemories,
  queryGraph
} from "./chunk-64NJRYU2.js";

// src/graph-recall.ts
function runGraphRecall(config, options) {
  if (!config.recallGraphEnabled) {
    return {
      ran: false,
      results: [],
      graph: null,
      reason: "disabled",
      iterations: 0,
      converged: true
    };
  }
  const topK = typeof config.recallGraphTopK === "number" && Number.isFinite(config.recallGraphTopK) ? config.recallGraphTopK : 50;
  if (topK <= 0) {
    return {
      ran: false,
      results: [],
      graph: null,
      reason: "topk-zero",
      iterations: 0,
      converged: true
    };
  }
  if (options.memories.length === 0) {
    return {
      ran: false,
      results: [],
      graph: null,
      reason: "empty-input",
      iterations: 0,
      converged: true
    };
  }
  const graph = buildGraphFromMemories(options.memories);
  const damping = typeof config.recallGraphDamping === "number" && Number.isFinite(config.recallGraphDamping) ? config.recallGraphDamping : DEFAULT_PPR_DAMPING;
  const iterations = typeof config.recallGraphIterations === "number" && Number.isFinite(config.recallGraphIterations) ? config.recallGraphIterations : DEFAULT_PPR_ITERATIONS;
  const ppr = queryGraph(graph, options.seedIds, {
    damping,
    iterations,
    seedWeights: options.seedWeights
  });
  const memoryResults = [];
  for (const node of ppr.rankedNodes) {
    const graphNode = graph.nodes.get(node.id);
    if (!graphNode || graphNode.type !== "memory") continue;
    memoryResults.push({ id: node.id, score: node.score });
    if (memoryResults.length >= topK) break;
  }
  return {
    ran: true,
    results: memoryResults,
    graph,
    reason: "ran",
    iterations: ppr.iterations,
    converged: ppr.converged
  };
}

export {
  runGraphRecall
};
//# sourceMappingURL=chunk-DGVM5SFL.js.map