skills/llm/iterative-candidate-reranking/SKILL.md
Narrows a large candidate pool through multiple LLM voting rounds, each presenting a sliding window of candidates plus the current best pick.
npx skillsauth add wenmin-wu/ds-skills llm-iterative-candidate-rerankingInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
When retrieval returns many candidates (25+), a single LLM reranking pass can't compare them all at once due to context limits. Instead, iterate in rounds: each round presents a sliding window of ~8 new candidates plus the surviving best pick from the previous round. The LLM votes for the best, and the winner carries forward. After several rounds, the final survivor is the top-ranked candidate.
import numpy as np
def iterative_rerank(indices, llm, df, tokenizer, n_rounds=3, window=8):
"""indices: (N_queries, N_candidates) sorted by retrieval score."""
survivors = indices[:, -1:] # start with last (worst) as initial survivor
for i in range(n_rounds):
# sliding window: 8 new candidates + current survivor
start = -window * (i + 1) - 1
end = -window * i - 1
c_indices = np.concatenate([indices[:, start:end], survivors], axis=1)
# Build prompts with numbered candidates, ask LLM to pick best
prompts = build_prompts(df, c_indices, tokenizer)
responses = llm.generate(prompts, sampling_params)
choices = parse_choices(responses) # integer index into c_indices
# Update survivors
survivors = np.array([
c[choice] for choice, c in zip(choices, c_indices)
]).reshape(-1, 1)
return survivors.flatten()
data-ai
Scaled Pinball Loss (SPL) metric for evaluating quantile forecasts, normalized by mean absolute successive differences of training data
data-ai
Walk backward through a time series and multiplicatively rescale segments when jumps exceed a fraction of the running mean to correct data collection anomalies
testing
Transform forecasting target to next/current ratio minus one so that optimizing MAE or squared error implicitly minimizes SMAPE
tools
Convert point forecasts to prediction intervals by scaling with logit-transformed quantile ratios passed through a Normal CDF