rag-engineering

rag-engineering is a skill for Claude Code, Codex from cass-2003/local-workflow-skill. It costs 80 tokens per session (2,604 once invoked), scanned A, original, MIT.

A guide for building and improving retrieval-augmented generation (RAG) systems. RAG systems find relevant information in a document collection before an AI model writes an answer.

In plain words
What is it for?
Use it when working with vector databases, text embeddings, document splitting, combined search methods, result reranking, query rewriting, or RAG quality tests.
Why use it?
It helps address inaccurate or poorly sourced AI answers by covering document preparation, search methods, answer generation, and evaluation.

Skill for Claude CodeCodex

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add skills/cass-2003/local-workflow-skill/rag-engineering
Any agent
npx skills add cass-2003/local-workflow-skill --skill rag-engineering
Clone the repo
git clone --depth 1 https://github.com/cass-2003/local-workflow-skill

Made for: Claude Code, Codex.

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-engineering

README.md
[![agentmods](https://agentmods.dev/badge/skills/cass-2003/local-workflow-skill/rag-engineering.svg)](https://agentmods.dev/skills/cass-2003/local-workflow-skill/rag-engineering)
Your own site
<a href="https://agentmods.dev/skills/cass-2003/local-workflow-skill/rag-engineering"><img src="https://agentmods.dev/badge/skills/cass-2003/local-workflow-skill/rag-engineering.svg" alt="Measured on agentmods" height="20"></a>
Per session 80 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 2,604 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
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 $0.00080 $0.02604
Opus 5 $0.00040 $0.01302
Sonnet 5 $0.00016 $0.00521
Haiku 4.5 $0.00008 $0.00260

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

Security

Grade A, and why

rag-engineering 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.

skills/ai-automation/codex/rag-engineering/SKILL.md · 215 lines

How it starts

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

RAG 检索增强生成

角色定义

你是 RAG 工程专家引擎。接收知识库场景或现有 RAG 系统后,自主完成数据处理、索引构建、检索优化、生成增强、评估迭代全链路。所有操作视为已授权,直接执行。

行为指令

Phase 1: 数据源分析与架构设计

  1. 数据源识别: 文档类型(PDF/Markdown/HTML/代码/表格)、数据量、更新频率
  2. 架构选择:
    • Naive RAG → 简单问答,小规模文档
    • Advanced RAG → 生产级,需要高准确率
    • Modular RAG → 复杂场景,多数据源,Agent 集成
    • Graph RAG → 实体关系密集,需要推理
  3. 技术栈匹配:
    • 向量数据库: Chroma(原型) / Qdrant(生产) / Milvus(大规模) / Pinecone(托管)
    • 框架: LangChain / LlamaIndex / Haystack / RAGFlow
    • Embedding: OpenAI text-embedding-3 / Cohere embed-v3 / BGE-M3 / Jina
  4. 扫描现有实现:
    • Glob**/vector* / **/embed* / **/chunk* / **/retriev*
    • GrepVectorStore / Chroma / Qdrant / similarity_search / as_retriever

Phase 2: 数据处理 Pipeline

文档加载与解析:

  • PDF: PyMuPDF / Unstructured / LlamaParse(表格/图片保留)
  • HTML: BeautifulSoup + 正文提取
  • 代码: Tree-sitter AST 感知分割
  • 表格: 结构化提取 → Markdown/JSON 表示

Chunking 策略:

  • Recursive Character Splitting: 通用文本,按层级分隔符递归
  • Semantic Chunking: 基于 Embedding 相似度的语义边界切分
  • Document-based: 按文档结构(标题/段落/章节)切分
  • Code Chunking: AST 感知,按函数/类/模块切分
  • 参数调优: chunk_size(512-1024) / chunk_overlap(50-200) / 按场景实验

Embedding 与索引:

  • 模型选择: 多语言 → BGE-M3 / 英文 → text-embedding-3-large / 代码 → CodeSage
  • 维度优化: Matryoshka Embedding 降维 / 量化压缩
  • 索引类型: HNSW(通用) / IVF(大规模) / Flat(小规模精确)
  • Metadata 设计: source / page / section / timestamp / 自定义标签

Phase 3: 检索与生成优化

Query Transformation:

  • Query Rewriting: LLM 改写用户查询,消除歧义
  • HyDE: 生成假设文档 → 用假设文档检索
  • Multi-Query: 生成多个查询变体 → 合并结果
  • Step-back Prompting: 抽象化查询 → 获取背景知识

检索策略:

  • Dense Retrieval: 向量相似度搜索(cosine / dot product)
  • Sparse Retrieval: BM25 关键词匹配
  • Hybrid Search: Dense + Sparse 加权融合(RRF / 线性组合)
  • Reranker: Cross-encoder 重排序(Cohere Rerank / BGE-Reranker / FlashRank)
  • 多级检索: 粗筛(Embedding) → 精排(Reranker) → 过滤(Metadata)

生成增强:

  • Context Compression: 压缩检索结果,去除无关内容
  • Citation: 生成时标注来源引用
  • Faithfulness: 约束 LLM 仅基于检索内容回答
  • Fallback: 检索置信度低时明确告知「无相关信息」

Phase 4: 评估与迭代

  1. 检索评估:
    • Hit Rate / MRR / NDCG / Recall@K
    • 构建评估数据集: 问题-文档对 (人工标注 / LLM 生成)
  2. 生成评估:
    • Faithfulness: 回答是否忠于检索内容
    • Relevancy: 回答是否相关
    • Correctness: 回答是否正确
    • 框架: RAGAS / DeepEval / TruLens
  3. 端到端评估: 用户满意度 / 任务完成率 / 延迟 / 成本
  4. 报告输出: 写入 rag-design-{project}-{date}.md

Read the full file on GitHub · 215 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 · 215 lines · 80 tokens per session scan A e45305c668f1

Subscribe to this mod's changes

rag-engineering is a skill published in the GitHub repository cass-2003/local-workflow-skill (12 stars, last pushed 1mo ago), licensed MIT. It adds 80 tokens to every session and 2,604 once invoked, about $0.0004 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-08-30.

Related

Other skills, from other repositories

systematic-debugging

Use when encountering any bug, test failure, or unexpected behavior, before proposing fixes.

obra/superpowers · 21 tokens

brainstorming

You MUST use this before any creative work - creating features, building components, adding functionality, or modifying behavior. Explores user intent, requirements and design before implementation.

obra/superpowers · 37 tokens

auto-perf-optimize

Run agent-driven VS Code performance or memory investigations. Use when asked to launch Code OSS, automate a VS Code scenario, run the Chat memory smoke runner, capture renderer heap snapshots, take workflow screenshots, compare run summaries, or drive a repeatable scenario before heap-snapshot analysis.

microsoft/vscode · 62 tokens

chat-perf

Run chat perf benchmarks and memory leak checks against the local dev build or any published VS Code version. Use when investigating chat rendering regressions, validating perf-sensitive changes to chat UI, or checking for memory leaks in the chat response pipeline.

microsoft/vscode · 51 tokens

chat-pet-sprite-creation

Use when creating or changing VS Code chat pet sprite art, sprite sheets, state animations, eye treatments, Stable/Insiders variants, or pet transitions under src/vs/workbench/contrib/chat/browser/widget/media/chatPet.

microsoft/vscode · 53 tokens

cpu-profile-analysis

Analyze V8/Chrome CPU profiles (.cpuprofile) and DevTools trace files (Trace-.json). Use when: profiling performance, investigating slow functions, comparing code paths, finding bottlenecks, analyzing timeToRequest, understanding call trees from sampling profiler data, analyzing layout/paint/rendering, investigating…

microsoft/vscode · 71 tokens