Agent skill · AI & Agents

contextual-retrieval

Anthropic's Contextual Retrieval technique for improved RAG. Use when chunks lose context during retrieval, implementing hybrid BM25+vector search, or reducing retrieval failures.

majiayu000github.com/majiayu000GitHub ↗
claude-codeMIT
Install
npx skills add majiayu000/claude-skill-registry --skill contextual-retrieval --agent claude-code

Same command for any agent — swap --agent for codex, cursor, copilot.

Facts
Files in the skill folder: 2
SKILL.md size: 11 KB
Bundled scripts: none
Version: 1.0.0
Declared author: SkillForge
Path: skills/ai-llm/contextual-retrieval/SKILL.md
Open the folder on GitHub →
Where it comes from
Stars: 534
Language: HTML

Weekly change comes from our own snapshots, not the repository page — it measures attention, not adoption.

From the SKILL.md

# Contextual Retrieval Prepend situational context to chunks before embedding to preserve document-level meaning. ## The Problem Traditional chunking loses context: ``` Original document: "ACME Q3 2024 Earnings Report..." Chunk: "Revenue increased 15% compared to the previous quarter." Query: "What was ACME's Q3 2024 revenue growth?" Result: Chunk doesn't mention "ACME" or "Q3 2024" - retrieval fails ``` ## The Solution **Contextual Retrieval** prepends a brief context to each chunk: ``` Contextualized chunk: "This chunk is from ACME Corp's Q3 2024 earnings report, specifically the revenue section. Revenue increased 15% compared to the previous quarter." ``` ## Implementation ### Context Generation ```python import anthropic client = anthropic.Anthropic() CONTEXT_PROMPT = """ <document> {document} </document> Here is the chunk we want to situate within the document: <chunk> {chunk} </chunk> Please give a short, succinct context (1-2 sentences) to situate this chunk within the overall document. Focus on information that would help retrieval. Answer only with the context, nothing else. """ def generate_context(document: str, chunk: str) -> str: """Generate context for a single chunk.

What's inside
Steps it walks through
  1. The Problem
  2. The Solution
  3. Implementation
  4. Context Generation
  5. Batch Processing with Caching
  6. Hybrid Search (BM25 + Vector)
  7. Complete Pipeline
  8. Optimization Tips
  9. 1. Cost Reduction with Caching
  10. 2. Parallel Processing
  11. 3. Context Quality
  12. Results (from Anthropic's research)
  13. When to Use
  14. Related Skills
Ships with 1 file
  • metadata.json
More from claude-skill-registry
All skills →
About this skill
What does the contextual-retrieval skill do?

Anthropic's Contextual Retrieval technique for improved RAG. Use when chunks lose context during retrieval, implementing hybrid BM25+vector search, or reducing retrieval failures.

How do I install it?

Run `npx skills add majiayu000/claude-skill-registry --skill contextual-retrieval --agent claude-code` — it drops the skill into your project so the agent can pick it up. Swap the --agent value for codex, cursor or copilot if you use one of those.

Where does this skill come from?

From majiayu000/claude-skill-registry, a repository with 534 stars. We read it straight from the repository tree rather than a submitted listing, so what you see here is what is actually published.

Is a popular skill a good skill?

Not necessarily. Stars measure attention, not adoption — a repository can trend for a week and be abandoned. That is why we show the weekly change from our own snapshots next to the total, instead of a single flattering number.

Keep going