reranker-ts
reranker-ts is a lightweight TypeScript library for re-ranking search results from retreival systems.
Installation
Install rerank using npm:
npm install rerank
Algorithms
LLM Re-Rankers
Available Providers:
ProviderGroq
ProviderOpenAI
Example Usage:
import { LLMReranker, ProviderGroq } from "rerank";
const provider = new ProviderGroq("llama3-8b-8192", API_KEY);
const reranker = new LLMReranker(provider);
const list = [
{ key: "bc8fe338", value: "I hate vegetables" },
{ key: "236386f2", value: "I love mangoes" },
];
const query = "I love apples";
const result = await reranker.rerank(list, "key", "value", query);
Reciprocal RankFusion
Combine multiple rank lists by assigning scores based on reciprocal ranks, effectively prioritizing higher-ranked items across all lists.
Paper
Example Usage:
import { reciprocalRankFusion } from "rerank";
interface ImageSearchResult {
url: string;
width: string;
height: string;
score: number;
}
const rankedLists: ImageSearchResult[][] = await Promise.all([
searchIndex("imageEmbeddingIndex", "person riding skateboard"),
searchIndex("imageEmbeddingIndex", "person skating on the sidewalk"),
searchIndex("imageIndex", "skateboard trick"),
]);
const rankedURLs = reciprocalRankFusion(rankedLists, "url");
const resultsMap = new Map<string, ImageSearchResult>();
rankedLists.flat().forEach((result) => {
resultsMap.set(result.url, result);
});
const sortedResults = Array.from(rankedUrls.keys()).map((url) => {
return resultsMap.get(url);
});