Agent skill

Context Ranking

by seb1n in seb1n/awesome-ai-agent-skills

Rank an existing set of context chunks by relevance, diversity, freshness, and utility.

MITAuto-check passedAgent Workflows

Install Context Ranking

skills CLI
$ npx skills add seb1n/awesome-ai-agent-skills --skill context-ranking -a claude-code

Project install by default; add -g for ~/.claude/skills/.

GitHub CLI
$ gh skill install seb1n/awesome-ai-agent-skills context-ranking --agent claude-code

Project scope by default; add --scope user for a personal install. Needs GitHub CLI 2.90.0 or later (public preview).

Manual copy
$ git clone --depth 1 https://github.com/seb1n/awesome-ai-agent-skills.git skills-src && mkdir -p .claude/skills && cp -r skills-src/context-engineering/context-ranking .claude/skills/context-ranking && rm -rf skills-src

Use ~/.claude/skills/ instead of .claude/skills for a personal install. The folder must contain SKILL.md.

Claude Code skills documentation · loads skills from .claude/skills/

Facts

Skill name
context-ranking
GitHub stars
206
Token cost
~2.9k tokens
SKILL.md length
1,495 words
Files
1
Skills in repo
91
Repo updated
First seen
Licence
MIT

At a glance

Rank an existing set of context chunks by relevance, diversity, freshness, and utility.

  • Works in 6 steps: Collect Candidate Chunks: Gather the… → Apply First-Stage Scoring: Score each… → Rerank with a Cross-Encoder: Pass the… → …
  • Retrieval has already produced candidates that must be scored
  • SKILL.md covers Workflow, Key Concepts, Usage and Examples, plus 2 more sections
  • Instructions only: no scripts, shell commands, URLs or credentials in SKILL.md

What it does

Context Ranking is an agent skill from seb1n/awesome-ai-agent-skills. Rank an existing set of context chunks by relevance, diversity, freshness, and utility. Use when retrieval has already produced candidates that must be scored or reranked; use context-retrieval when the source corpus still needs to be searched.

Its SKILL.md is about 2.9k tokens, which your agent loads only when the skill is triggered. It is a single SKILL.md file with no bundled scripts.

It sits in Agent Workflows, covering Context engineering. The repository describes itself as: 103 ready-to-use AI agent skills for Claude Code, OpenAI Codex, Gemini CLI, Cursor, GitHub Copilot, Windsurf, and other Agent Skills-compatible tools. Complete SKILL.md… The licence is MIT.

When your agent uses it

  • Retrieval has already produced candidates that must be scored
  • Use context-retrieval when the source corpus still needs to be searched

Example prompts

  • “/context-ranking”

Workflow steps

6 steps, taken from the first numbered list in SKILL.md.

  1. Collect Candidate Chunks: Gather the initial set of retrieved chunks from the search layer. This is typically the top-k results (k =…
  2. Apply First-Stage Scoring: Score each candidate with a fast, lightweight algorithm. BM25 is the standard choice for keyword relevance…
  3. Rerank with a Cross-Encoder: Pass the top candidates (typically 15-25) from the first stage through a cross-encoder reranker. Unlike…
  4. Apply Diversity Selection: After reranking, the top results may cluster around a single subtopic, leaving other aspects of the query…
  5. Assign Final Scores and Rank: Combine the reranker relevance score with the diversity penalty and any domain-specific boosting signals…
  6. Attach Metadata and Confidence: Annotate each ranked chunk with its final score, source path, and a confidence tier (high / medium / low)…

What it can do on your machine

Read from SKILL.md and the folder at commit 75865a5. It shows what the files ask for, not the result of running them.

  • Tool permissions

    Pre-approves nothing: there is no allowed-tools line, so your agent's usual permission prompts apply.

    From allowed-tools in the SKILL.md frontmatter.

  • Runs code

    No scripts in the folder and no shell commands in SKILL.md.

    From the folder's file list and the shell code blocks in SKILL.md.

  • Network

    No URLs in SKILL.md.

    From URLs in SKILL.md, links to its own repository left out.

  • Credentials

    Names no API keys, tokens, secrets or passwords.

    From names ending in _API_KEY, _TOKEN, _SECRET, _KEY or _PASSWORD in SKILL.md.

Context cost

Context Ranking loads about 2.9k tokens when it runs. Until then it costs about 65 tokens; SKILL.md has 1,495 words of instructions outside code blocks.

Always · name and description, kept in context so the agent knows when to use it
~65
When it runs · the whole SKILL.md, loaded when a task matches
~2.9k

Estimates: characters ÷ 4, the usual rule of thumb; real counts depend on the model's tokenizer. Scripts and assets cost tokens only if the agent reads them.

Safety

Auto-check passed

The automated check found no risky patterns in SKILL.md.

Automated static check — not a guarantee. Review scripts before installing. It scans the text of SKILL.md for risky patterns (piping downloads into a shell, reading credential files, hidden Unicode, destructive commands); files beside SKILL.md are not scanned.

SKILL.md

The full file from seb1n/awesome-ai-agent-skills at commit 75865a5, republished under its MIT licence (© seb1n). 1,495 words, ~2,905 tokens.

Download SKILL.mdSave it as .claude/skills/context-ranking/SKILL.md (or your agent's skills folder).
name
context-ranking
description
Rank an existing set of context chunks by relevance, diversity, freshness, and utility. Use when retrieval has already produced candidates that must be scored or reranked; use context-retrieval when the source corpus still needs to be searched.
license
MIT
metadata.author
awesome-ai-agent-skills
metadata.version
1.0.0

Context Ranking

Context ranking is the process of ordering retrieved text chunks so the most relevant, diverse, and useful information rises to the top. In any retrieval pipeline, the initial search returns a broad set of candidates -- many of which are only tangentially related to the query. Ranking transforms this unordered candidate set into a prioritized list, enabling downstream steps (context assembly, prompt construction) to select the best material and discard the rest. Effective ranking is the difference between a grounded, precise answer and a vague, off-topic one.

Workflow

  1. Collect Candidate Chunks: Gather the initial set of retrieved chunks from the search layer. This is typically the top-k results (k = 15-30) from a vector search, keyword search, or hybrid search. Each chunk arrives with a preliminary score (e.g., cosine similarity or BM25 score) and source metadata.

  2. Apply First-Stage Scoring: Score each candidate with a fast, lightweight algorithm. BM25 is the standard choice for keyword relevance; cosine similarity between the query embedding and chunk embedding is the standard for semantic relevance. In hybrid pipelines, compute both scores and combine them using Reciprocal Rank Fusion (RRF) or a weighted linear combination. This stage is meant to be fast and run over all candidates.

  3. Rerank with a Cross-Encoder: Pass the top candidates (typically 15-25) from the first stage through a cross-encoder reranker. Unlike bi-encoder embeddings that score query and document independently, a cross-encoder processes the query and chunk together with full attention, producing much more accurate relevance scores. Models like Cohere Rerank, bge-reranker-v2-m3, or ColBERTv2 are commonly used. This step is slower but dramatically improves precision.

  4. Apply Diversity Selection: After reranking, the top results may cluster around a single subtopic, leaving other aspects of the query uncovered. Apply Maximal Marginal Relevance (MMR) or a similar diversity algorithm to penalize chunks that are too similar to already-selected chunks. This ensures the final ranked list covers the breadth of the query, not just its most obvious interpretation.

  5. Assign Final Scores and Rank: Combine the reranker relevance score with the diversity penalty and any domain-specific boosting signals (e.g., recency boost, source authority weight) into a final composite score. Sort chunks by this composite score in descending order. The top-n chunks (n = 3-7) form the final ranked context to be injected into the prompt.

  6. Attach Metadata and Confidence: Annotate each ranked chunk with its final score, source path, and a confidence tier (high / medium / low). This metadata helps the downstream prompt assembly step decide how to present the context and allows the model to calibrate its confidence when citing sources.

Key Concepts

  • BM25: A probabilistic keyword-matching algorithm based on term frequency, inverse document frequency, and document length normalization. Excels at matching exact terms and rare keywords. Fast and interpretable, but blind to synonyms and paraphrases. The standard first-stage ranker for keyword search.
  • Cosine Similarity: Measures the angle between two embedding vectors. Values range from -1 to 1, with higher values indicating greater semantic similarity. The standard first-stage ranker for semantic search. Quality depends heavily on the embedding model used.
  • Cross-Encoder Reranking: A transformer model that takes the concatenation of query and document as input and outputs a relevance score. Because it applies full cross-attention between query and document tokens, it captures fine-grained relevance that bi-encoders miss. Typically 5-20x slower than cosine similarity but produces significantly better ranking.
  • Maximal Marginal Relevance (MMR): An algorithm that iteratively selects chunks by balancing relevance to the query against redundancy with already-selected chunks. Controlled by a lambda parameter: lambda = 1.0 selects purely by relevance, lambda = 0.0 selects purely by diversity, and values around 0.5-0.7 balance both. Essential for multi-faceted queries.
  • Reciprocal Rank Fusion (RRF): A score-combining method used in hybrid search. For each chunk, compute 1/(k + rank) for each ranking source, then sum. This produces a fused ranking that is robust to score scale differences between BM25 and cosine similarity.

Usage

Provide a query and a list of candidate text chunks (with optional preliminary scores and metadata). The skill scores, reranks, and diversifies the chunks, returning a ranked list with final scores and confidence tiers. Specify the desired number of output chunks (top-n) and an optional diversity parameter (MMR lambda).

Examples

Example 1: Ranking Code Search Results for a Debugging Query

Query: "Why does the WebSocket connection drop after 60 seconds of inactivity?"

Candidate Chunks (from hybrid search, top-8):

#SourceBM25CosineContent Summary
1src/ws/server.ts:40-6512.40.88WebSocket server config with pingInterval: 30000 and pingTimeout: 60000
2src/ws/server.ts:80-958.10.82Connection cleanup handler that logs "connection timed out"
3docs/websocket.md:15-306.30.79Documentation: "Connections are kept alive via ping/pong. Default timeout is 60s."
4src/ws/client.ts:10-355.70.84Client-side WebSocket wrapper -- does not implement pong response handler
5nginx.conf:22-289.80.71Nginx proxy config: proxy_read_timeout 60s for WebSocket upstream
6CHANGELOG.md:44-503.20.55"v2.1: Fixed WebSocket reconnection logic" -- no timeout details
7src/ws/server.ts:100-1204.50.76Rate limiting middleware for WebSocket messages
8package.json:15-202.10.45"ws": "^8.14.0" dependency entry

After Cross-Encoder Reranking:

Rank#Reranker ScoreReason
110.96Directly shows the 60s timeout configuration
250.93Nginx proxy timeout -- a second cause of 60s drops
340.89Client missing pong handler -- explains why pings fail
420.85Cleanup handler confirms timeout behavior
530.78Documentation corroborates the 60s default
670.42Rate limiting -- marginally related
760.30Changelog -- no useful detail
880.15Package.json -- irrelevant

After MMR Diversity Selection (top-5, lambda=0.6):

  1. src/ws/server.ts:40-65 (score 0.96) -- Server-side 60s timeout config
  2. nginx.conf:22-28 (score 0.93) -- Nginx proxy 60s read timeout (different source of the problem)
  3. src/ws/client.ts:10-35 (score 0.89) -- Client missing pong handler (client-side root cause)
  4. src/ws/server.ts:80-95 (score 0.85) -- Cleanup handler confirms the timeout behavior
  5. docs/websocket.md:15-30 (score 0.78) -- Documentation confirming 60s default

The ranked list covers three distinct causes (server config, nginx proxy, client pong handler) plus confirmation from the cleanup handler and docs.

Show full SKILL.md (519 more words)Show less
Example 2: Ranking Documentation Chunks for a Q&A Task

Query: "How do I configure SSO with SAML for my organization?"

Candidate Chunks (top-6 from vector search):

#SourceCosineContent Summary
1docs/sso/saml-setup.md0.91Step-by-step SAML configuration: metadata URL, certificate upload, attribute mapping
2docs/sso/overview.md0.85Overview of SSO options: SAML, OIDC, LDAP. High-level comparison.
3docs/sso/saml-setup.md0.83Troubleshooting SAML errors: invalid signature, clock skew, missing NameID
4docs/sso/oidc-setup.md0.80OIDC configuration guide -- not SAML
5docs/admin/org-settings.md0.77Organization settings page: where to find the SSO configuration panel
6blog/sso-announcement.md0.72Blog post announcing SSO feature launch -- marketing copy, no setup details

After Cross-Encoder Reranking and MMR (top-4, lambda=0.7):

  1. docs/sso/saml-setup.md (setup guide, score 0.95) -- Direct answer: step-by-step SAML configuration
  2. docs/admin/org-settings.md (score 0.82) -- Where to access the SSO settings (different doc, complements #1)
  3. docs/sso/saml-setup.md (troubleshooting, score 0.79) -- Anticipates common errors the user may encounter
  4. docs/sso/overview.md (score 0.71) -- Provides broader context on SSO options

Chunk 4 (OIDC guide) was filtered as irrelevant to SAML. Chunk 6 (blog post) was filtered for low information density.

Best Practices

  • Always rerank -- never rely solely on embedding cosine similarity or BM25 for final ranking. A cross-encoder reranker on the top 15-25 results consistently improves precision by 15-30% in benchmarks.
  • Use hybrid first-stage scoring -- combining BM25 and cosine similarity via RRF outperforms either alone, especially on queries that mix specific terms with general intent.
  • Apply MMR for multi-faceted queries -- queries like "What causes X and how do I fix it?" have two sub-intents. Without diversity selection, the top results may all address causes and none address fixes.
  • Tune the MMR lambda parameter -- start with lambda = 0.6 (slightly favoring relevance over diversity) and adjust based on your use case. Factoid Q&A benefits from higher lambda (0.7-0.8), while exploratory research benefits from lower lambda (0.4-0.5).
  • Cache reranker results -- cross-encoder inference is expensive. If the same query-chunk pairs recur (common in multi-turn conversations), cache the reranker scores to avoid redundant computation.
  • Evaluate with NDCG and MRR -- use Normalized Discounted Cumulative Gain and Mean Reciprocal Rank on a labeled test set to measure ranking quality. These metrics are more informative than simple Recall@k for ranking evaluation.

Edge Cases

  • Tie scores: When multiple chunks receive identical or near-identical reranker scores, break ties by preferring chunks from more authoritative sources, more recent documents, or chunks with higher information density.
  • Single-result queries: Some queries have exactly one relevant chunk in the corpus. The ranking pipeline should still work correctly -- the reranker should score that chunk highly and MMR should not penalize it for lack of diversity.
  • Adversarial or noisy chunks: Web-scraped or user-generated content may contain SEO spam or irrelevant keyword stuffing that inflates BM25 scores. The cross-encoder reranker typically handles this well, but consider adding a quality filter as a pre-processing step.
  • Cross-lingual queries: When the query language differs from the corpus language, ensure the embedding model and reranker support cross-lingual matching, or add a translation step before ranking.
  • Very large candidate sets (100+): If the initial retrieval returns hundreds of candidates, add an intermediate filtering step (e.g., score threshold cutoff) before the cross-encoder to keep reranking latency manageable.

© seb1n, MIT. Rendered from Markdown: HTML in the file is shown as text, images as links, and headings moved down two levels. Raw file

Files

Just SKILL.md in context-engineering/context-ranking of seb1n/awesome-ai-agent-skills.

Open the folder on GitHubat commit 75865a5

Compare with similar skills

Context Ranking next to the 5 skills that share the most tags, products or categories with it. Stars are the repository's; “used in” counts other GitHub owners with a copy.

Context Ranking compared with similar skills
SkillStarsUsed inTokensAuto-checkLicenceRepo updated
Context Ranking this skillseb1n/awesome-ai-agent-skills206—~2.9kAutomated safety check: PassMIT
Memori Long-Term MemoryMemoriLabs/Memori17k—~2kAutomated safety check: PassApache-2.0
Project Developmentguanyang/open-agent-hub9752 repos~4.7kAutomated safety check: PassMIT
Context DoctorjzOcb/context-doctor119—~642Automated safety check: PassMIT
Caveman Learn Token FixesJuliusBrussee/caveman110k—~2.8kAutomated safety check: PassApache-2.0
Cognee Session Memory and Improvetopoteretes/cognee32k—~3.2kAutomated safety check: PassApache-2.0

Similar skills

  • Memori Long-Term Memory

    MemoriLabs/Memori

    Adds structured long-term memory to OpenClaw agents, built automatically from sessions, with tools the agent calls to recall facts, summaries and decisions.

    17k GitHub stars~2k tokensUpdated 5 days ago
    Agent WorkflowsAuto-check passed
  • Project Development

    guanyang/open-agent-hub

    This skill should be used for project-level decisions about LLM-powered systems: whether an LLM is the right primitive for the task at hand, the shape of a multi-stage batch or agent pipeline, token…

    975 GitHub starsUsed in 2 repos~4.7k tokens
    Agent WorkflowsAuto-check passed
  • Context Doctor

    jzOcb/context-doctor

    Visualize and diagnose OpenClaw context window usage. An agent skill from jzOcb/context-doctor.

    119 GitHub stars~642 tokensUpdated 6 mo ago
    Agent WorkflowsAuto-check passed
  • Caveman Learn Token Fixes

    JuliusBrussee/caveman

    Acts on a Caveman learn report: reviews ranked token sinks, applies cost-lowering edits one at a time with your consent, and reports what each fix returned.

    110k GitHub stars~2.8k tokensUpdated today
    Agent WorkflowsAuto-check passed
  • Explains how cognee stores session memory by session_id and bridges it into the permanent graph with improve(), including the stages, results and settings.

    32k GitHub stars~3.2k tokensUpdated yesterday
    Agent WorkflowsAuto-check passed
  • Claudish Usage

    MadAppGang/claudish

    CRITICAL - Guide for using Claudish CLI ONLY through sub-agents to run Claude Code with any AI model (OpenRouter, Gemini, OpenAI, local models).

    1k GitHub stars~9k tokensUpdated yesterday
    Agent WorkflowsAuto-check passed

More from seb1n/awesome-ai-agent-skills

All 91 skills in this repo
  • Agent Red Teaming

    seb1n/awesome-ai-agent-skills

    Plan, execute, document, and retest authorized security assessments of AI agents and multi-agent workflows using safe adversarial cases, synthetic identities, canaries, and evidence-based findings.

    206 GitHub stars~2.8k tokensUpdated 2 mo ago
    Auto-check passed
  • Eu AI Act Readiness

    seb1n/awesome-ai-agent-skills

    Build a preliminary, evidence-based EU AI Act readiness assessment across AI-system inventory, territorial scope, operator roles, prohibited-practice screening, risk classification, transparency…

    206 GitHub stars~3.3k tokensUpdated 2 mo ago
    Auto-check passed
  • Human In The Loop

    seb1n/awesome-ai-agent-skills

    Design and verify auditable human oversight, approval gates, escalation paths, and safe state transitions for AI agent workflows.

    206 GitHub stars~2.5k tokensUpdated 2 mo ago
    Auto-check passed
  • MCP Server Building

    seb1n/awesome-ai-agent-skills

    Design, implement, harden, and verify Model Context Protocol (MCP) servers with precise tool contracts, least-privilege authorization, safe transports, structured errors, and interoperability tests.

    206 GitHub stars~2.5k tokensUpdated 2 mo ago
    Auto-check passed
  • Skill Supply Chain Audit

    seb1n/awesome-ai-agent-skills

    Audit agent skills, plugins, prompts, manifests, scripts, dependencies, and bundled assets for provenance, prompt-injection, permission, execution, exfiltration, persistence, and update risk.

    206 GitHub stars~2.4k tokensUpdated 2 mo ago
    Auto-check passed
  • Spreadsheet Analysis

    seb1n/awesome-ai-agent-skills

    Inspect, profile, clean, reconcile, analyze, visualize, and verify spreadsheet data while preserving formulas, formatting, types, and source files.

    206 GitHub stars~2.5k tokensUpdated 2 mo ago
    Auto-check passed

Questions about Context Ranking

What does Context Ranking do?

Rank an existing set of context chunks by relevance, diversity, freshness, and utility. Context Ranking is an agent skill from seb1n/awesome-ai-agent-skills. Rank an existing set of context chunks by relevance, diversity, freshness, and utility.

When should I use Context Ranking?

Context Ranking fits situations like: retrieval has already produced candidates that must be scored; use context-retrieval when the source corpus still needs to be searched.

How do I install Context Ranking in Claude Code?

Run `npx skills add seb1n/awesome-ai-agent-skills --skill context-ranking -a claude-code`. Or copy the skill folder (context-engineering/context-ranking in seb1n/awesome-ai-agent-skills) into .claude/skills/context-ranking in your project. Claude Code loads it when a task matches its description.

How do I install Context Ranking in Codex?

Run `npx skills add seb1n/awesome-ai-agent-skills --skill context-ranking -a codex`. Or copy the skill folder (context-engineering/context-ranking in seb1n/awesome-ai-agent-skills) into .agents/skills/context-ranking in your project. Codex loads it when a task matches its description.

Can I use Context Ranking in Cursor, Gemini CLI or GitHub Copilot?

Cursor, Gemini CLI, GitHub Copilot and OpenCode also load SKILL.md folders. With the skills CLI, run `npx skills add seb1n/awesome-ai-agent-skills --skill context-ranking -a cursor` (or -a gemini-cli, github-copilot or opencode for the others). To copy it by hand, put the folder in .cursor/skills/context-ranking, .gemini/skills/context-ranking, .github/skills/context-ranking and .opencode/skills/context-ranking in your project.

What does Context Ranking need to run?

SKILL.md names no scripts, command-line tools or credentials: Context Ranking is instructions for the agent only.

Does Context Ranking access the network?

SKILL.md contains no URLs. Any network use would come from the scripts or tools the agent runs. This is read from the text; nothing was executed.

Is Context Ranking safe to install?

Our automated static check of SKILL.md found no risky patterns, such as piping downloads into a shell, reading credential files or hidden Unicode. It is not a guarantee. Review the folder before installing.

What licence does Context Ranking use?

Context Ranking is published under the MIT licence (declared in SKILL.md). It allows redistribution, so the full SKILL.md is shown on this page.

How many tokens does Context Ranking use?

About 2.9k tokens (SKILL.md is roughly 12k characters). Agents keep only the skill's name and description in context until a task matches; then they load SKILL.md in full.

What are the alternatives to Context Ranking?

Skills that share tags, products or a category with Context Ranking: Memori Long-Term Memory (MemoriLabs/Memori, 17k stars), Project Development (guanyang/open-agent-hub, 975 stars), Context Doctor (jzOcb/context-doctor, 119 stars) and Caveman Learn Token Fixes (JuliusBrussee/caveman, 110k stars). The comparison table on this page puts their stars, adoption, token cost, safety result and licence side by side.

Who maintains Context Ranking?

seb1n (a GitHub user) maintains it in seb1n/awesome-ai-agent-skills, which has 206 GitHub stars. The repository holds 91 skills in this directory. The repository was last updated on August 9, 2026.

Source: seb1n/awesome-ai-agent-skills on GitHub. Facts on this page come from the repository at the commit we read; the author's words are quoted as theirs.