import fetch from "node-fetch";
export class VoyageReranker {
    params;
    name = "voyage";
    constructor(params) {
        this.params = params;
    }
    async rerank(query, chunks) {
        const resp = await fetch("https://api.voyageai.com/v1/rerank", {
            method: "POST",
            headers: {
                "Content-Type": "application/json",
                Authorization: `Bearer ${this.params.apiKey}`,
            },
            body: JSON.stringify({
                query,
                documents: chunks.map((chunk) => chunk.content),
                model: this.params.model ?? "rerank-lite-1",
            }),
        });
        const data = await resp.json();
        const results = data.data.sort((a, b) => a.index - b.index);
        return results.map((result) => result.relevance_score);
    }
}
