/craftsman:ragfrom craftsman
Designs RAG (Retrieval-Augmented Generation) pipelines with explicit chunking, embedding, and retrieval decisions. Covers ingestion, retrieval, and generation stages for knowledge bases, document Q&A, or semantic search.
Ships in craftsman. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
Design production-ready RAG pipelines following best practices.
┌─────────────────────────────────────────────────────────────────┐
│ RAG PIPELINE │
├─────────────────────────────────────────────────────────────────┤
│ │
│ ┌──────────────┐ ┌──────────────┐ ┌──────────────┐ │
│ │ INGESTION │───▶│ RETRIEVAL │───▶│ GENERATION │ │
│ └──────────────┘ └──────────────┘ └──────────────┘ │
│ │
│ Documents → Chunks Query → Vectors Context → LLM → Answer │
│ → Embeddings → → Similar Chunks → Response │
│ Vector Store │
│ │
└─────────────────────────────────────────────────────────────────┘
from langchain.text_splitter import RecursiveCharacterTextSplitter
from langchain.embeddings import OpenAIEmbeddings
from langchain.vectorstores import PGVector
# Chunking Strategy
text_splitter = RecursiveCharacterTextSplitter(
chunk_size=1000, # Characters per chunk
chunk_overlap=200, # Overlap for context
separators=["\n\n", "\n", ". ", " ", ""],
)
# Embedding Model
embeddings = OpenAIEmbeddings(
model="text-embedding-3-small", # Cost-effective
# model="text-embedding-3-large", # Higher quality
)
# Vector Store
vectorstore = PGVector.from_documents(
documents=chunks,
embedding=embeddings,
collection_name="knowledge_base",
connection_string=DATABASE_URL,
)
from langchain.retrievers import ContextualCompressionRetriever
from langchain.retrievers.document_compressors import LLMChainExtractor
# Base Retriever
retriever = vectorstore.as_retriever(
search_type="similarity", # or "mmr" for diversity
search_kwargs={"k": 5}, # Top K results
)
# Optional: Contextual Compression
compressor = LLMChainExtractor.from_llm(llm)
compression_retriever = ContextualCompressionRetriever(
base_compressor=compressor,
base_retriever=retriever,
)
from langchain.chains import RetrievalQA
from langchain.chat_models import ChatOpenAI
llm = ChatOpenAI(
model="gpt-4-turbo-preview",
temperature=0, # Deterministic for factual answers
)
qa_chain = RetrievalQA.from_chain_type(
llm=llm,
chain_type="stuff", # or "map_reduce" for long contexts
retriever=retriever,
return_source_documents=True,
)
| Strategy | Use Case | Chunk Size |
|---|---|---|
| Fixed | General text | 500-1000 chars |
| Sentence | Precise retrieval | 1-3 sentences |
| Paragraph | Structured docs | Natural breaks |
| Semantic | Technical docs | Topic boundaries |
| Recursive | Mixed content | Adaptive |
| Database | Pros | Cons | Best For |
|---|---|---|---|
| pgvector | PostgreSQL native, ACID | Scale limits | Small-medium, existing PG |
| Pinecone | Managed, fast | Cost, vendor lock | Production, scale |
| Weaviate | Hybrid search | Complexity | Complex queries |
| Chroma | Simple, local | Not for prod | Development, prototypes |
| Qdrant | Fast, filtering | Self-host | Performance critical |
## RAG Design: [Project Name]
### 1. Data Source Analysis
- [ ] Document types: [PDF, Markdown, HTML, etc.]
- [ ] Total volume: [X documents, Y MB]
- [ ] Update frequency: [Real-time, Daily, Weekly]
- [ ] Quality: [Clean, Needs preprocessing]
### 2. Chunking Strategy
- [ ] Strategy: [Recursive, Semantic, etc.]
- [ ] Chunk size: [X characters]
- [ ] Overlap: [Y characters]
- [ ] Metadata: [Title, Source, Date, etc.]
### 3. Embedding Choice
- [ ] Model: [text-embedding-3-small, etc.]
- [ ] Dimensions: [1536, 3072, etc.]
- [ ] Cost estimate: [$X per 1M tokens]
### 4. Vector Store
- [ ] Database: [pgvector, Pinecone, etc.]
- [ ] Index type: [HNSW, IVF, etc.]
- [ ] Hosting: [Self-hosted, Managed]
### 5. Retrieval Strategy
- [ ] Search type: [Similarity, MMR, Hybrid]
- [ ] Top K: [3-10]
- [ ] Reranking: [Yes/No]
- [ ] Filtering: [Metadata filters]
### 6. Generation
- [ ] Model: [GPT-4, Claude, etc.]
- [ ] Temperature: [0 for factual, 0.7 for creative]
- [ ] Context window: [Token limit]
- [ ] Fallback: [When no relevant docs found]
| Pitfall | Solution |
|---|---|
| Chunks too small | Increase size, lose context |
| Chunks too large | Decrease, add overlap |
| Wrong embedding model | Match to domain (code, medical, etc.) |
| No metadata | Add source, date, section |
| No evaluation | Implement retrieval metrics |
# Retrieval Quality
- Recall@K: % of relevant docs in top K
- Precision@K: % of top K that are relevant
- MRR: Mean Reciprocal Rank
# Generation Quality
- Faithfulness: Does answer match sources?
- Relevance: Does answer address query?
- Groundedness: Is answer supported by context?
What SKILL.md sets; muted values are Claude Code's defaults
opusxhighnpx claudepluginhub buldee/ai-craftsman-superpowers --plugin craftsman23 skills in this plugin
/agent-designDesign AI agents using the 3P pattern (Perceive/Plan/Perform). Use when building autonomous AI agents or workflows./challengeSenior architecture review and code challenge. Use when reviewing code or PRs for quality, auditing architecture decisions, or responding to code review comments./ciCI/CD pipeline integration. Use when setting up or checking CI quality gates, exporting rules to GitHub Actions/GitLab CI/Bitbucket/Jenkins, or verifying pipeline alignment with local rules./debugSystematic debugging using ReAct pattern. Use when encountering bugs, errors, unexpected behavior, test failures, or performance issues. Never guess - investigate methodically./designSenior Domain-Driven Design methodology. Use for creating entities, value objects, aggregates, or designing domain models. Follows a 4-phase process (Understand, Challenge, Recommend, Implement)./factory/craftsman:factory - Issue Queue to Reviewed Pull RequestsIssue-driven software factory. Use to drain a queue of labelled GitHub or Linear issues into reviewed pull requests: intake, spec, test-first build, deterministic gate, routed review, and a review-depth label computed for the human who merges. Never merges.Other plugins' skills for the same job