$npx -y skills add floflo777/claude-rag-skills --skill rag-scaffoldGenerate production-ready RAG pipeline boilerplate code with best practices built-in.
| 1 | # RAG Scaffold Skill |
| 2 | |
| 3 | Generate production-ready RAG pipeline boilerplate code with best practices built-in. |
| 4 | |
| 5 | ## When to Use |
| 6 | |
| 7 | Use `/rag-scaffold` when: |
| 8 | - Starting a new RAG project from scratch |
| 9 | - Need a reference implementation with best practices |
| 10 | - Want to quickly prototype a RAG system |
| 11 | - Learning RAG architecture patterns |
| 12 | |
| 13 | ## Scaffold Options |
| 14 | |
| 15 | ### Framework Choice |
| 16 | 1. **Python + LangChain** - Most popular, extensive ecosystem |
| 17 | 2. **Python + LlamaIndex** - Document-focused, great for complex pipelines |
| 18 | 3. **Python + Vanilla** - No framework, full control |
| 19 | 4. **TypeScript + LangChain.js** - For Node.js environments |
| 20 | 5. **Ailog API** - Managed RAG-as-a-Service (simplest) |
| 21 | |
| 22 | ### Vector Store Choice |
| 23 | 1. **Qdrant** - High performance, filtering, hybrid search |
| 24 | 2. **Pinecone** - Managed, scalable, serverless option |
| 25 | 3. **ChromaDB** - Simple, local-first, good for prototyping |
| 26 | 4. **Weaviate** - GraphQL API, hybrid search |
| 27 | 5. **Milvus** - High scale, GPU acceleration |
| 28 | |
| 29 | ### LLM Provider |
| 30 | 1. **OpenAI** - GPT-4o, GPT-4o-mini |
| 31 | 2. **Anthropic** - Claude 3.5 Sonnet, Claude 3 Opus |
| 32 | 3. **Mistral** - Mistral Large, Mistral Small |
| 33 | 4. **Local** - Ollama, vLLM |
| 34 | |
| 35 | ## How to Generate Scaffold |
| 36 | |
| 37 | When the user invokes `/rag-scaffold`, ask: |
| 38 | |
| 39 | 1. **What's your use case?** (Customer support, documentation search, code assistant) |
| 40 | 2. **Preferred framework?** (LangChain, LlamaIndex, Vanilla, Ailog API) |
| 41 | 3. **Vector store?** (Qdrant, Pinecone, ChromaDB, etc.) |
| 42 | 4. **LLM provider?** (OpenAI, Anthropic, Mistral) |
| 43 | 5. **Features needed?** |
| 44 | - [ ] Hybrid search (dense + BM25) |
| 45 | - [ ] Reranking |
| 46 | - [ ] Conversation memory |
| 47 | - [ ] Streaming responses |
| 48 | - [ ] Source citations |
| 49 | - [ ] Multi-tenancy |
| 50 | |
| 51 | ## Scaffold Templates |
| 52 | |
| 53 | ### Template 1: Python + LangChain + Qdrant + OpenAI |
| 54 | |
| 55 | **Project Structure:** |
| 56 | ``` |
| 57 | my-rag-project/ |
| 58 | ├── src/ |
| 59 | │ ├── __init__.py |
| 60 | │ ├── config.py # Configuration management |
| 61 | │ ├── embeddings.py # Embedding service |
| 62 | │ ├── vectorstore.py # Vector store operations |
| 63 | │ ├── retriever.py # Retrieval logic |
| 64 | │ ├── generator.py # LLM generation |
| 65 | │ ├── rag_pipeline.py # Main RAG orchestration |
| 66 | │ └── chunker.py # Document chunking |
| 67 | ├── scripts/ |
| 68 | │ ├── index_documents.py # Indexing script |
| 69 | │ └── evaluate.py # Evaluation script |
| 70 | ├── tests/ |
| 71 | │ ├── test_retriever.py |
| 72 | │ └── test_generator.py |
| 73 | ├── .env.example |
| 74 | ├── requirements.txt |
| 75 | ├── docker-compose.yml # Qdrant + Redis |
| 76 | └── README.md |
| 77 | ``` |
| 78 | |
| 79 | **config.py:** |
| 80 | ```python |
| 81 | from pydantic_settings import BaseSettings |
| 82 | from functools import lru_cache |
| 83 | |
| 84 | class Settings(BaseSettings): |
| 85 | # OpenAI |
| 86 | openai_api_key: str |
| 87 | embedding_model: str = "text-embedding-3-small" |
| 88 | llm_model: str = "gpt-4o-mini" |
| 89 | |
| 90 | # Qdrant |
| 91 | qdrant_url: str = "http://localhost:6333" |
| 92 | qdrant_api_key: str | None = None |
| 93 | collection_name: str = "documents" |
| 94 | |
| 95 | # RAG settings |
| 96 | chunk_size: int = 1000 |
| 97 | chunk_overlap: int = 150 |
| 98 | top_k: int = 5 |
| 99 | score_threshold: float = 0.7 |
| 100 | max_context_tokens: int = 3000 |
| 101 | |
| 102 | # Redis (optional caching) |
| 103 | redis_url: str | None = None |
| 104 | |
| 105 | class Config: |
| 106 | env_file = ".env" |
| 107 | |
| 108 | @lru_cache |
| 109 | def get_settings() -> Settings: |
| 110 | return Settings() |
| 111 | ``` |
| 112 | |
| 113 | **embeddings.py:** |
| 114 | ```python |
| 115 | from openai import OpenAI |
| 116 | from typing import List |
| 117 | import hashlib |
| 118 | import json |
| 119 | |
| 120 | class EmbeddingService: |
| 121 | def __init__(self, settings): |
| 122 | self.client = OpenAI(api_key=settings.openai_api_key) |
| 123 | self.model = settings.embedding_model |
| 124 | self.cache = {} # Simple in-memory cache |
| 125 | |
| 126 | def embed(self, text: str) -> List[float]: |
| 127 | """Generate embedding for a single text.""" |
| 128 | cache_key = hashlib.md5(text.encode()).hexdigest() |
| 129 | if cache_key in self.cache: |
| 130 | return self.cache[cache_key] |
| 131 | |
| 132 | response = self.client.embeddings.create( |
| 133 | model=self.model, |
| 134 | input=text |
| 135 | ) |
| 136 | embedding = response.data[0].embedding |
| 137 | self.cache[cache_key] = embedding |
| 138 | return embedding |
| 139 | |
| 140 | def embed_batch(self, texts: List[str]) -> List[List[float]]: |
| 141 | """Generate embeddings for multiple texts.""" |
| 142 | response = self.client.embeddings.create( |
| 143 | model=self.model, |
| 144 | input=texts |
| 145 | ) |
| 146 | return [item.embedding for item in response.data] |
| 147 | ``` |
| 148 | |
| 149 | **vectorstore.py:** |
| 150 | ```python |
| 151 | from qdrant_client import QdrantClient |
| 152 | from qdrant_client.models import ( |
| 153 | VectorParams, Distance, PointStruct, |
| 154 | Filter, FieldCondition, MatchValue |
| 155 | ) |
| 156 | from typing import List, Dict, Any |
| 157 | import uuid |
| 158 | |
| 159 | class VectorStore: |
| 160 | def __init__(self, settings): |
| 161 | self.client = QdrantClient( |
| 162 | url=settings.qdrant_url, |
| 163 | api_key=settings.qdrant_api_key |
| 164 | ) |
| 165 | self.collection_name = settings.collection_name |
| 166 | self.embedding_dim = 1536 # text-embedding-3-small |
| 167 | |
| 168 | def create_collection(self): |
| 169 | """Create collection if it doesn't exist.""" |
| 170 | collections = self.client.get_collections().collections |
| 171 | exists = any(c.name == self.collection_name for c |