import { createLogger } from "../logger.js";
const log = createLogger("providers");
let cached = null;
function getRerankProvider() {
  if (cached) return cached;
  cached = import("../search/reranker/transformers-rerank-provider.js").then(async (m) => {
    const p = new m.TransformersRerankProvider();
    await p.warmup();
    log.info("rerank provider ready", {
      provider: "rerank",
      impl: "transformers",
      modelId: p.modelId
    });
    return p;
  }).catch((err) => {
    cached = null;
    throw err;
  });
  return cached;
}
function _resetRerankProviderForTest() {
  cached = null;
}
async function disposeRerankProvider() {
  if (!cached) return;
  try {
    const provider = await cached;
    const disposable = provider;
    if (typeof disposable.dispose === "function") await disposable.dispose();
  } catch (err) {
    log.debug("rerank dispose failed", { error: err instanceof Error ? err.message : String(err) });
  } finally {
    cached = null;
  }
}
export {
  _resetRerankProviderForTest,
  disposeRerankProvider,
  getRerankProvider
};
//# sourceMappingURL=rerank-provider.js.map