rank-gpt
LLM-as-reranker patterns. RankGPT listwise / pairwise / pointwise prompting, sliding window for long candidate lists, cost-latency vs Cohere Rerank, calibration tricks, structured output for rank lists. Code uses the Anthropic SDK. USE WHEN: user mentions "LLM reranker", "RankGPT", "listwise reranking", "pairwise reranking", "pointwise reranking", "GPT reranker", "Claude reranker" DO NOT USE FOR: standard cross-encoder reranking - use `rag/reranking`; fine-tuning cross-encoders - use `retrieval/cross-encoder-training`; ColBERT - use `retrieval/colbert-retrieval`
What this skill does
# RankGPT: LLM-as-Reranker
## Why and When
LLM rerankers win when:
- The query contains instructions ("prefer recent docs", "exclude deprecated APIs").
- The corpus is too niche for pretrained rerankers (internal jargon, proprietary ontology).
- The system needs explanations alongside rankings.
- You have very few labeled examples — an LLM needs zero.
They lose on:
- Latency: 300-2000 ms vs 50-300 ms for cross-encoders.
- Cost: $3-30 per 1k queries vs <$2 for Cohere Rerank.
- Throughput: rate limits cap QPS without batching.
## Three Prompting Styles
| Style | Prompt shape | Cost | Quality |
|---|---|---|---|
| Pointwise | Score each doc independently (0-10) | O(n) calls, cheapest | Mid |
| Pairwise | Ask which of two docs is better | O(n log n) calls, priciest | High but slow |
| Listwise | Rank the whole batch in one call | One call per window | Best quality-to-cost |
Listwise is the RankGPT default.
## Listwise Reranking with Claude
```python
# pip install anthropic
from anthropic import Anthropic
import json, re
client = Anthropic()
MODEL = "claude-haiku-4-5-20250929" # cheap, fast; upgrade to sonnet for hard queries
LISTWISE_PROMPT = """You rank passages by relevance to a user query.
Query: {query}
Passages (each starts with its index in brackets):
{passages}
Return a JSON object with a single field "ranking": an array of passage indexes
ordered from most to least relevant. Include every index exactly once.
No other text, no explanations."""
def format_passages(docs: list[str]) -> str:
return "\n\n".join(f"[{i}] {d}" for i, d in enumerate(docs))
def listwise_rank(query: str, docs: list[str]) -> list[int]:
msg = client.messages.create(
model=MODEL,
max_tokens=1024,
messages=[{
"role": "user",
"content": LISTWISE_PROMPT.format(query=query, passages=format_passages(docs)),
}],
)
text = msg.content[0].text
match = re.search(r"\{[\s\S]*\}", text)
data = json.loads(match.group(0))
ranking = data["ranking"]
# Safety: fill missing indexes at the end
seen = set(ranking)
missing = [i for i in range(len(docs)) if i not in seen]
return ranking + missing
```
## Sliding Window for Long Candidate Lists
Claude handles > 100 passages in one prompt but prompt length grows quickly. The RankGPT paper uses a sliding window:
```
[0..19] rank -> keep top 10
[10..29] rank (seeded with previous top 10) -> keep top 10
[20..39] ...
```
```python
def sliding_rerank(query: str, docs: list[str], window: int = 20,
step: int = 10, keep: int = 10) -> list[int]:
n = len(docs)
if n <= window:
return listwise_rank(query, docs)[:keep]
# Start from the end so the best candidates bubble to position 0
order = list(range(n))
start = n - window
while start >= 0:
end = start + window
slice_docs = [docs[i] for i in order[start:end]]
local = listwise_rank(query, slice_docs)
order[start:end] = [order[start + idx] for idx in local]
start -= step
return order[:keep]
```
End-to-start scan is the trick: the strongest document reaches the front of the list as windows slide back.
## Pairwise (Highest Quality, Most Expensive)
Pairwise calls scale as O(n log n) with merge-sort style comparisons:
```python
PAIRWISE_PROMPT = """Given the query, which passage is more relevant? Answer with "A" or "B" only.
Query: {query}
Passage A:
{a}
Passage B:
{b}
Answer:"""
def pairwise_compare(query: str, a: str, b: str) -> int:
msg = client.messages.create(
model=MODEL,
max_tokens=5,
messages=[{"role": "user",
"content": PAIRWISE_PROMPT.format(query=query, a=a, b=b)}],
)
return -1 if msg.content[0].text.strip().upper().startswith("A") else 1
import functools
def merge_sort_rerank(query: str, docs: list[str]) -> list[int]:
idx = list(range(len(docs)))
def cmp(i, j):
return pairwise_compare(query, docs[i], docs[j])
return sorted(idx, key=functools.cmp_to_key(cmp))
```
Avoid naive bubble-sort (O(n^2) calls). Use merge-sort or tournament bracket.
## Pointwise (Cheapest, Most Parallel)
```python
import asyncio
from anthropic import AsyncAnthropic
aclient = AsyncAnthropic()
POINTWISE_PROMPT = """Rate the relevance of the passage to the query from 0 to 10.
Return a JSON object: {{"score": <number>}}
Query: {query}
Passage: {passage}"""
async def point_score(query: str, passage: str) -> float:
msg = await aclient.messages.create(
model=MODEL, max_tokens=40,
messages=[{"role": "user",
"content": POINTWISE_PROMPT.format(query=query, passage=passage)}],
)
try:
return float(json.loads(re.search(r"\{[^}]*\}", msg.content[0].text).group(0))["score"])
except Exception:
return 0.0
async def pointwise_rerank(query: str, docs: list[str], top_n: int = 5) -> list[int]:
scores = await asyncio.gather(*(point_score(query, d) for d in docs))
return sorted(range(len(docs)), key=lambda i: scores[i], reverse=True)[:top_n]
```
Run calls concurrently with a semaphore to respect rate limits.
## Structured Output for Robustness
Anthropic tool-use forces a JSON shape — no regex needed:
```python
tools = [{
"name": "submit_ranking",
"description": "Submit the ranking of passage indexes from most to least relevant.",
"input_schema": {
"type": "object",
"properties": {
"ranking": {
"type": "array",
"items": {"type": "integer"},
"description": "Passage indexes in descending relevance order",
},
},
"required": ["ranking"],
},
}]
def listwise_structured(query: str, docs: list[str]) -> list[int]:
msg = client.messages.create(
model=MODEL, max_tokens=1024, tools=tools, tool_choice={"type": "tool", "name": "submit_ranking"},
messages=[{"role": "user",
"content": LISTWISE_PROMPT.format(query=query, passages=format_passages(docs))}],
)
for block in msg.content:
if block.type == "tool_use" and block.name == "submit_ranking":
return block.input["ranking"]
raise ValueError("No ranking returned")
```
Always prefer tool-use over regex JSON extraction in production.
## Calibration: Force Consistency
LLMs are sensitive to passage order inside the prompt. Two tricks:
1. Shuffle input order each call; rerank yields a *relative* order, not absolute.
2. Run two passes with different initial orders; fuse with RRF.
```python
import random
def robust_listwise(query: str, docs: list[str], passes: int = 3) -> list[int]:
from collections import defaultdict
scores = defaultdict(float)
for _ in range(passes):
perm = list(range(len(docs)))
random.shuffle(perm)
shuffled = [docs[i] for i in perm]
ranking = listwise_structured(query, shuffled)
for rank, local_idx in enumerate(ranking):
real_idx = perm[local_idx]
scores[real_idx] += 1.0 / (60 + rank + 1) # RRF
return sorted(scores, key=scores.get, reverse=True)
```
## Cost and Latency vs Cohere Rerank
| Reranker | Candidates | Latency | Cost / 1k queries |
|---|---|---|---|
| Cohere Rerank v3.5 | 50 | 100-300 ms | ~$2.00 |
| Claude Haiku listwise | 20 | 300-700 ms | ~$3-5 |
| Claude Haiku listwise sliding (50) | 50 | 600-1500 ms | ~$8-15 |
| Claude Sonnet listwise | 20 | 500-1200 ms | ~$15-25 |
| Claude Haiku pointwise async | 50 | 200-600 ms | ~$5-8 |
| Claude Haiku pairwise merge-sort | 20 | 800-2000 ms | ~$10-20 |
Pick Haiku listwise with sliding window as the default LLM-reranker. Upgrade to Sonnet only for hard queries.
## Prompt Caching for Cost Control
The query + passages prompt has a large fixed header (instructions, passages rarely change across a user session). Cache it via Anthropic's prompt caching:
```python
msg = client.messages.create(
model=MODRelated in Backend & APIs
jfrog
IncludedInteract with the JFrog Platform via the JFrog CLI and REST/GraphQL APIs. Use this skill when the user wants to manage Artifactory repositories, upload or download artifacts, manage builds, configure permissions, manage users and groups, work with access tokens, configure JFrog CLI servers, search artifacts, manage properties, set up replication, manage JFrog Projects, run security audits or scans, look up CVE details, query exposures scan results from JFrog Advanced Security, manage release bundles and lifecycle operations, aggregate or export platform data, or perform any JFrog Platform administration task. Also use when the user mentions jf, jfrog, artifactory, xray, distribution, evidence, apptrust, onemodel, graphql, workers, mission control, curation, advanced security, exposures, or any JFrog product name.
cupynumeric-migration-readiness
IncludedPre-migration readiness assessor for porting NumPy to cuPyNumeric. Use BEFORE substantial porting work begins when the user asks whether code will scale on GPU, whether they should migrate to cuPyNumeric, which NumPy patterns transfer cleanly, what must be refactored before porting, or mentions pre-port assessment, scaling analysis, or refactor planning. Inspect the user's source code, look up NumPy usage, cross-reference the cuPyNumeric API support manifest, and distinguish distributed-scaling-friendly patterns from blockers such as unsupported APIs, scalar synchronization, host round-trips, Python/object-heavy control flow, shape/data-dependent branching, and in-place mutation hazards. Produce a verdict of READY, LIGHT REFACTOR, SIGNIFICANT REFACTOR, or NOT RECOMMENDED, with concrete refactor pointers.
alibabacloud-data-agent-skill
IncludedInvoke Alibaba Cloud Apsara Data Agent for Analytics via CLI to perform natural language-driven data analysis on enterprise databases. Data Agent for Analytics is an intelligent data analysis agent developed by Alibaba Cloud Database team for enterprise users. It automatically completes requirement analysis, data understanding, analysis insights, and report generation based on natural language descriptions. This tool supports: discovering data resources (instances/databases/tables) managed in DMS, initiating query or deep analysis sessions, real-time progress tracking, and retrieving analysis conclusions and generated reports. Use this Skill when users need to query databases, analyze data trends, generate data reports, ask questions in natural language, or mention "Data Agent", "data analysis", "database query", "SQL analysis", "data insights".
token-optimizer
IncludedReduce OpenClaw token usage and API costs through smart model routing, heartbeat optimization, budget tracking, and native 2026.2.15 features (session pruning, bootstrap size limits, cache TTL alignment). Use when token costs are high, API rate limits are being hit, or hosting multiple agents at scale. The 4 executable scripts (context_optimizer, model_router, heartbeat_optimizer, token_tracker) are local-only — no network requests, no subprocess calls, no system modifications. Reference files (PROVIDERS.md, config-patches.json) document optional multi-provider strategies that require external API keys and network access if you choose to use them. See SECURITY.md for full breakdown.
resend-cli
IncludedUse this skill when the task is specifically about operating Resend from an AI agent, terminal session, or CI job via the official resend CLI: installing/authenticating the CLI, sending/listing/updating/cancelling emails, batch sends, domains and DNS, webhooks and local listeners, inbound receiving, contacts, topics, segments, broadcasts, templates, API keys, profiles, or debugging Resend CLI/API failures. Trigger on mentions of Resend CLI, `resend`, `resend doctor`, `resend emails send`, `resend domains`, `resend webhooks listen`, `resend emails receiving`, or agent-friendly terminal automation.
alibabacloud-odps-maxframe-coding
IncludedUse this skill for MaxFrame SDK development and documentation navigation on Alibaba Cloud MaxCompute (ODPS). Helps answer MaxFrame API, concept, official example, and supported pandas API questions; create data processing programs; read/write MaxCompute tables; debug jobs (remote or local); and build custom DPE runtime images. Trigger when users mention MaxFrame, MaxCompute with MaxFrame, ODPS table processing, DPE runtime, MaxFrame docs/examples, DataFrame/Tensor operations, or GPU runtime setup. Works for both English and Chinese queries about Alibaba Cloud data processing with MaxFrame.