rag-patterns

rag-patterns is a skill for Claude Code from softspark/ai-toolkit. It costs 57 tokens per session (1,768 once invoked), scanned A, original, Apache-2.0.

A guide to retrieval-augmented generation, or RAG: using document search to give an AI system relevant information before it answers.

In plain words
What is it for?
Use it when designing embeddings, document chunking, hybrid search, reranking, corrective retrieval, or multi-step searches with vector databases.
Why use it?
It helps improve searches that rely on both exact words and meaning, including difficult questions that need several retrieval steps.

Skill for Claude Code

Written for Claude Code: allowed-tools in frontmatter.

Needs its repository: it runs a file that does not travel with it, so clone the repository first. The line is python scripts/evaluate_rag.py.

Part of the ai-toolkit plugin — 113 skills, 44 agents, 14 hooks shipped together

Good fit Use it when designing embeddings, document chunking, hybrid search, reranking, corrective retrieval…

Compare 6 skills from other repositories ↓
Install

Getting it into your agent

It runs from inside its repository, so the clone comes first — what it calls does not travel with the file alone.

Clone the repo
git clone --depth 1 https://github.com/softspark/ai-toolkit
agentmods
npx agentmods add skills/softspark/ai-toolkit/rag-patterns

Made for: Claude Code.

Or install ai-toolkit, the plugin that ships this one along with the rest of its 113 skills, 44 agents, 14 hooks.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for rag-patterns

README.md
[![agentmods](https://agentmods.dev/badge/skills/softspark/ai-toolkit/rag-patterns.svg)](https://agentmods.dev/skills/softspark/ai-toolkit/rag-patterns)
Your own site
<a href="https://agentmods.dev/skills/softspark/ai-toolkit/rag-patterns"><img src="https://agentmods.dev/badge/skills/softspark/ai-toolkit/rag-patterns.svg" alt="Measured on agentmods" height="20"></a>
Per session 57 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 1,768 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. A grade says what 26 rules found in the file — not that it is safe.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.00057 $0.01768
Opus 5 $0.00028 $0.00884
Sonnet 5 $0.00011 $0.00354
Haiku 4.5 $0.00006 $0.00177

Measured 3d ago against content hash f082b8361665, method: parsed. Prices are Anthropic first-party input rates as of 2026-09-06, from the pricing page.

Security

Grade A, and why

rag-patterns scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 3d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

app/skills/rag-patterns/SKILL.md · 231 lines

How it starts

The opening of the file, as written. The whole thing — 231 lines — stays where its author put it; the contents beside it link to each section on GitHub.

RAG Patterns Skill

Core Patterns

1. Hybrid Search

Combine dense (vector) and sparse (BM25) retrieval with RRF fusion:

# RAG-MCP hybrid search
result = await hybrid_search_kb(
    query="rate limiting configuration",
    service="nginx",
    limit=10
)

2. Corrective RAG (CRAG)

Self-correcting retrieval with relevance validation:

result = await crag_search(
    query="fuzzy query",
    relevance_threshold=0.4,
    max_retries=2
)

# Or via smart_query
result = await smart_query(query="...", use_crag=True)

3. HyDE (Hypothetical Document Embeddings)

Generate hypothetical answers for better retrieval on conceptual queries:

result = await smart_query(
    query="conceptual question about design patterns",
    use_hyde=True
)

4. Multi-hop Retrieval

Complex queries requiring multiple retrieval steps:

result = await multi_hop_search(
    query="Compare nginx with varnish for Magento cache",
    max_hops=3
)

# Or via smart_query
result = await smart_query(query="compare A vs B", use_multi_hop=True)

Indexing Best Practices

Aspect Recommendation
Chunk size 512-1024 tokens
Overlap 10-20% of chunk
Structure Preserve headers, sections
Metadata Include title, path, date, category, tags
Frontmatter YAML with standardized fields

Frontmatter Template

---
title: "Document Title"
service: {project-name}
category: reference|howto|procedures|troubleshooting|decisions|best-practices
tags: [tag1, tag2, tag3]
last_updated: "YYYY-MM-DD"
---

MCP Tools Reference (v5.5.0)

Tool Use Case Speed
smart_query Default for 90% of queries 2-4s
hybrid_search_kb Raw vector + text search <1s
get_document Full document content <1s
crag_search Vague/fuzzy queries 1-3s
multi_hop_search Complex reasoning 20-30s

Tool Selection Guide

# Default - auto-routing
smart_query("specific technical question")

# Vague query - self-correcting
crag_search("jak to skonfigurować")

# Complex comparison
multi_hop_search("nginx vs varnish performance comparison")

# Known document
get_document(path="kb/reference/architecture.md")

Read the full file on GitHub · 231 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 3d ago First seen · 231 lines · 57 tokens per session scan A f082b8361665

Subscribe to this mod's changes

rag-patterns is a skill published in the GitHub repository softspark/ai-toolkit (170 stars, last pushed 2d ago), licensed Apache-2.0. It adds 57 tokens to every session and 1,768 once invoked, about $0.0003 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-09-03.