← Back

Rerank

April 5, 2026

Rerank runs the same document through three different summarization methods (TextRank, LexRank, and BART) and lets you compare their output side by side instead of committing to whichever one a library happens to default to. TextRank and LexRank aren't wrappers around an existing package; they're implemented directly in TypeScript and run entirely client-side, scoring sentences by how similar they are to every other sentence in the document.

Both build a sentence-similarity matrix from cosine similarity over tokenized sentences, then treat it as a graph and rank nodes the way PageRank ranks web pages: a sentence is "important" if it's similar to other important sentences. TextRank's version runs the classic damped iteration to convergence:

const scores = new Array(sentences.length).fill(1);
const damping = 0.85;
const iterations = 50;

for (let iter = 0; iter < iterations; iter++) {
  const newScores = [...scores];
  for (let i = 0; i < sentences.length; i++) {
    let sum = 0;
    for (let j = 0; j < sentences.length; j++) {
      if (i !== j) {
        const totalSim = similarityMatrix[j].reduce((a, b) => a + b, 0);
        if (totalSim > 0) {
          sum += (similarityMatrix[j][i] / totalSim) * scores[j];
        }
      }
    }
    newScores[i] = (1 - damping) + damping * sum;
  }
  scores.splice(0, scores.length, ...newScores);
}

LexRank instead thresholds the similarity matrix before row-normalizing it into a proper transition matrix, which is the main mathematical difference between the two approaches. BART, being an actual transformer model, calls out to a hosted inference API and falls back to an extractive method if that request fails, so a summary always comes back, even offline.